@ebflat9/fp
Advanced tools
Comparing version 1.2.60 to 1.2.61
@@ -602,12 +602,24 @@ /** | ||
interface Observer { | ||
next(value: any): void; | ||
next(value: unknown): void; | ||
error(err: Error): void; | ||
complete(): void; | ||
} | ||
type _GenericFunction2 = (...args: any[]) => any; | ||
type _GenericFunction2 = (...args: unknown[]) => unknown; | ||
interface IEventListener { | ||
(event: CustomEvent | Error): void; | ||
} | ||
type EventListenerMethodType = (eventType: string, listener: IEventListener) => void; | ||
interface IEventEmitter { | ||
emit(event: CustomEvent): void; | ||
addListener?: EventListenerMethodType; | ||
on?: EventListenerMethodType; | ||
addEventListener?: EventListenerMethodType; | ||
removeListener?: EventListenerMethodType; | ||
off?: EventListenerMethodType; | ||
removeEventListener?: EventListenerMethodType; | ||
} | ||
export interface Observable { | ||
fromEvent(emitter: any, event: string, handler: _GenericFunction2): Observable; | ||
fromEvent(emitter: IEventEmitter, event: string, handler: _GenericFunction2): Observable; | ||
fromPromise<X>(promise: Promise<X>): Observable; | ||
fromStream(stream: any): Observable; | ||
listen(eventName: string, element: any): Observable; | ||
listen(eventName: string, element: HTMLElement): Observable; | ||
subject(): Observable; | ||
@@ -704,3 +716,3 @@ wrap(obj: any): Observable; | ||
interface IGenericFunction { | ||
(...args: any[]): any; | ||
(...args: unknown[]): unknown; | ||
} | ||
@@ -707,0 +719,0 @@ interface IBehaviour { |
{ | ||
"name": "@ebflat9/fp", | ||
"version": "1.2.60", | ||
"version": "1.2.61", | ||
"description": "my fp utils", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
@@ -15,3 +15,5 @@ import { IBehaviour } from './Types' | ||
throw new Error( | ||
`Illegal attempt to override ${prop as string}, which already exists.` | ||
`Illegal attempt to override ${ | ||
prop as string | ||
}, which already exists.`, | ||
) | ||
@@ -18,0 +20,0 @@ } |
@@ -10,2 +10,3 @@ import { IBehaviour } from './Types' | ||
const overriddenMethodFunction = clazz.prototype[prop] | ||
Object.defineProperty(clazz.prototype, prop, { | ||
@@ -15,3 +16,3 @@ value(this: any, ...args: any[]) { | ||
this, | ||
overriddenMethodFunction.bind(this, ...args) | ||
overriddenMethodFunction.bind(this, ...args), | ||
) | ||
@@ -21,3 +22,7 @@ }, | ||
}) | ||
} else throw new Error(`Attempt to override non-existant method${prop as string}`) | ||
} else { | ||
throw new Error( | ||
`Attempt to override non-existant method${prop as string}`, | ||
) | ||
} | ||
} | ||
@@ -24,0 +29,0 @@ return clazz |
@@ -21,3 +21,5 @@ import { IBehaviour } from './Types' | ||
} else { | ||
throw new Error(`Attempt to override non-existant method ${prop as string}`) | ||
throw new Error( | ||
`Attempt to override non-existant method ${prop as string}`, | ||
) | ||
} | ||
@@ -24,0 +26,0 @@ } |
/* eslint no-unused-vars: 0 */ | ||
export interface IGenericFunction { | ||
(...args: any[]): any | ||
(...args: unknown[]): unknown | ||
} | ||
@@ -6,0 +6,0 @@ |
@@ -55,3 +55,5 @@ /* eslint no-unused-vars: 0 */ | ||
const headers: any = { 'Content-Type': 'application/json' } | ||
if (token) headers.Authorization = `Bearer ${token}` | ||
const config = { | ||
@@ -66,2 +68,3 @@ signal: controller.signal, | ||
} | ||
return { | ||
@@ -68,0 +71,0 @@ req: fetch(`${apiEndpoint}${endpoint}`, config) |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
/* eslint-disable no-redeclare */ | ||
@@ -41,3 +42,3 @@ /* eslint no-unused-vars: 0, no-magic-numbers: 0 */ | ||
export interface Observer { | ||
next(value: any): void | ||
next(value: unknown): void | ||
error(err: Error): void | ||
@@ -47,10 +48,36 @@ complete(): void | ||
type GenericFunction = (...args: any[]) => any | ||
type GenericFunction = (...args: unknown[]) => unknown | ||
interface IEventListener { | ||
(event: CustomEvent | Error): void | ||
} | ||
type EventListenerMethodType = ( | ||
eventType: string, | ||
listener: IEventListener, | ||
) => void | ||
interface IEventEmitter { | ||
emit(event: CustomEvent): void | ||
addListener?: EventListenerMethodType | ||
on?: EventListenerMethodType | ||
addEventListener?: EventListenerMethodType | ||
removeListener?: EventListenerMethodType | ||
off?: EventListenerMethodType | ||
removeEventListener?: EventListenerMethodType | ||
} | ||
interface IStream { | ||
on(event: string, handler: IEventListener): void | ||
} | ||
export interface Observable { | ||
fromEvent(emitter: any, event: string, handler: GenericFunction): Observable | ||
fromEvent( | ||
emitter: IEventEmitter, | ||
event: string, | ||
handler: GenericFunction, | ||
): Observable | ||
// fromGenerator(generator: GeneratorFunction): Observable | ||
fromPromise<X>(promise: Promise<X>): Observable | ||
fromStream(stream: any): Observable | ||
listen(eventName: string, element: any): Observable | ||
listen(eventName: string, element: HTMLElement): Observable | ||
subject(): Observable | ||
@@ -98,3 +125,3 @@ wrap(obj: any): Observable | ||
fromEvent: placeholder( | ||
(emitter: any, event: string, handler: GenericFunction) => | ||
(emitter: IEventEmitter, event: string, handler: GenericFunction) => | ||
new Observable((observer: Observer) => { | ||
@@ -106,8 +133,22 @@ const group = new Map([ | ||
]) | ||
entries(group as any).forEach(([event, handler]) => | ||
emitter.on(event, handler), | ||
) | ||
const on = | ||
typeof emitter.on === 'function' | ||
? emitter.on.bind(emitter) | ||
: typeof emitter.addListener === 'function' | ||
? emitter.addListener.bind(emitter) | ||
: emitter.addEventListener! | ||
const off = | ||
typeof emitter.off === 'function' | ||
? emitter.off.bind(emitter) | ||
: typeof emitter.removeListener === 'function' | ||
? emitter.removeListener.bind(emitter) | ||
: emitter.removeEventListener! | ||
entries(group as any).forEach(([event, handler]) => on(event, handler)) | ||
return () => | ||
entries(group as any).forEach(([event, handler]) => | ||
emitter.removeListener(event, handler), | ||
off(event, handler), | ||
) | ||
@@ -135,7 +176,7 @@ }), | ||
fromStream: placeholder( | ||
(stream: any) => | ||
(stream: IStream) => | ||
new Observable((observer: Observer) => { | ||
stream.on('data', observer.next.bind(observer)) | ||
stream.on('end', observer.complete.bind(observer)) | ||
stream.on('error', observer.error.bind(observer)) | ||
stream.on('error', observer.error.bind(observer) as IEventListener) | ||
}), | ||
@@ -142,0 +183,0 @@ ), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
914019
13152