UNPKG

@civet/events

Version:
17 lines (16 loc) 1.64 kB
import { Notifier, Constructor, GenericDataProvider, ResourceContextValue } from '@civet/core'; export default abstract class EventReceiver<Event, Resource extends ResourceContextValue<GenericDataProvider>, Options> { readonly _inferEvent: Event; readonly _inferResource: Resource; readonly _inferOptions: Options; subscribe<EventI extends Event = Event, ResourceI extends Resource = Resource, OptionsI extends Options = Options>(resource: ResourceI | Notifier<[ResourceI | undefined]> | undefined, options: OptionsI | undefined, handler: (events: EventI[]) => void): () => void; abstract handleSubscribe(resourceNotifier: Notifier<[Resource | undefined]>, options: Options | undefined, handler: (events: Event[]) => void): () => void; } export declare const isEventReceiver: (eventReceiver: unknown) => boolean; export type EventReceiverImplementation<EventReceiverI extends GenericEventReceiver, ConstructorArgs extends any[]> = Constructor<ConstructorArgs, EventReceiverI & { handleSubscribe(resourceNotifier: Notifier<[InferResource<EventReceiverI> | undefined]>, options: InferOptions<EventReceiverI> | undefined, handler: (events: InferEvent<EventReceiverI>[]) => void): () => void; }>; export type GenericEventReceiver = EventReceiver<unknown, ResourceContextValue<GenericDataProvider>, unknown>; export type InferEvent<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferEvent']; export type InferResource<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferResource']; export type InferOptions<EventReceiverI extends GenericEventReceiver> = EventReceiverI['_inferOptions'];