UNPKG

@dooboostore/dom-render

Version:
79 lines 3.11 kB
import { ConstructorType } from '@dooboostore/core/types'; import { Config } from '../configs/Config'; declare enum CallBackType { FILTER = 0, MAP = 1, SUBSCRIBE = 2 } export type ChannelData = { channel: Channel; data?: (any | undefined); }; export type ChannelMetaData = { channel?: Channel; action?: string; }; export declare class ChannelSubscription { channel: Channel; subscriber: ChannelSubscriber; constructor(channel: Channel, subscriber: ChannelSubscriber); unsubscribe(): void; } export declare class ChannelSubscriber<SD = any> { channel: Channel; parentSubscriber?: ChannelSubscriber; callbacks: ({ type: CallBackType; callback: (data: any, metaData: ChannelMetaData) => any | undefined; })[]; constructor(channel: Channel); exeCallback(data: any, metaData: ChannelMetaData): any; filter<D = SD>(callback: (data: D, meta: ChannelMetaData) => boolean): ChannelSubscriber<SD>; map<D = SD, R = any>(callback: (data: D, meta: ChannelMetaData) => R): ChannelSubscriber<R>; subscribe(callback: (data: SD, metaData: ChannelMetaData) => any | undefined): ChannelSubscription; unsubscribe(): void; deleteSubscriber(): void; } export declare class Channel { private messenger; obj: object; key: string; subscribers: Set<ChannelSubscriber<any>>; constructor(messenger: Messenger, obj: object, key: string); publish(key: string | object | ConstructorType<any>, data: any, action?: string): ChannelData[]; allPublish(data: any, action: string): any[]; filter<D = any>(filterF: (data: D, meta: ChannelMetaData) => boolean): ChannelSubscriber<D>; map<D = any, R = any>(filterF: (data: D, meta: ChannelMetaData) => R): ChannelSubscriber<R>; subscribe<D = any>(subscribeCallback: (data: D, meta: ChannelMetaData) => any | void | undefined): ChannelSubscription; deleteChannel(): void; } type MessengerEventDetail = { key: string | object | ConstructorType<any>; data?: any; action?: string; result?: (c: ChannelData[]) => void; }; type MessengerSubscribeEventDetail = { obj: any; key?: string | object | ConstructorType<any>; init: (channel: Channel, subscription: ChannelSubscription) => void; subscribe: (data: any, meta: ChannelMetaData) => void; }; export declare abstract class Messenger { private config; private channels; static readonly EVENT_PUBLISH_KEY = "domRenderMessenger_publish"; static readonly EVENT_SUBSCRIBE_KEY = "domRenderMessenger_subscribe"; constructor(config: Config); static publish(window: Window, detail: MessengerEventDetail): void; static subscribe(window: Window, detail: MessengerSubscribeEventDetail): void; createChannel(obj: any, key?: any): Channel; deleteChannel(channel: Channel): void; deleteChannelFromObj(obj: any): void; addChannel(channel: Channel): void; getChannels(key: string | object | ConstructorType<any>): Channel[]; getAllChannels(): Channel[]; getAllChannelKeys(): string[]; } export {}; //# sourceMappingURL=Messenger.d.ts.map