UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

113 lines (112 loc) 4.48 kB
/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-11-23 08:06:30 * @modify date 2021-10-19 17:55:35 * @desc [description] */ import { Subject, Subscription } from "rxjs"; import { TSubjectOptions } from "../helpers/getSubject"; import { IEventAdditionalData, IEventCallback, INopeEventEmitter, INopeObserver, INopePartialObserver, INopeSubscriptionOptions, INopeWaitForObservableChangeOptions, IObservableType, IPipe, IWaitForCallback } from "../types/nope/index"; /** * RsJX based Observable. * * Contains additional Functionalities like: * - property with the current value * - function to publish values. (wrapper for next) * - enables performing a subscription with synced call or a immediate call. */ export declare class NopeEventEmitter<T = unknown, S = T, G = T, AD extends IEventAdditionalData = IEventAdditionalData> implements INopeEventEmitter<T, S, G, AD> { protected _options: TSubjectOptions; protected _emitter: Subject<IObservableType<G, AD>>; readonly id: string; options: any; /** * Function to specify a Setter */ setter: ((value: S | null, options?: Partial<AD>) => { data: T | null; valid: boolean; }) | null; /** * Function to specify a Getter */ protected _getter: ((value: T | null) => G | null) | null; get getter(): ((value: T | null) => G | null) | null; set getter(_getter: ((value: T | null) => G | null) | null); emit(value: S | null, options?: Partial<AD>): boolean; /** * Function to set the content of the Observable * @param value * @param sender * @param timeStamp * @param data */ protected _emit(value: S | null, options?: Partial<AD>): boolean; /** * Helper to update the Timestamp and sender * * @author M.Karkowski * @protected * @param {IEventAdditionalData} options * @return {*} {ISetContentOptions} * @memberof NopeObservable */ protected _updateSenderAndTimestamp(options: Partial<AD>): Partial<AD>; /** * A Set containing the Subscriptions */ _subscriptions: Set<() => void>; /** * Flag to Disable Publishing */ disablePublishing: boolean; /** * Function, used to dispose the observable. * Every item will be unsubscribed. */ dispose(): void; protected _lastDataUpdate: number; /** * A Function to subscribe to updates of the Observable. * @param observer The Observer. Could be a Function or a Partial Observer. * @param mode The Mode of the Subscription * @param options Additional Options. */ subscribe(observer: INopePartialObserver<G, AD> | IEventCallback<G, AD>, options?: INopeSubscriptionOptions): INopeObserver; protected _subscribe(observer: INopePartialObserver<G, AD> | IEventCallback<G, AD>, options?: INopeSubscriptionOptions): INopeObserver; /** * Create an enhanced Subscription of the Observable. Use the Pipes, to * Define what should be subscribed. * @param next The Next Function, used to transmit changes * @param options The Options, used to determine the Enhancements. */ enhancedSubscription<K>(next: (data: K) => void, options?: { scope?: { [index: string]: any; }; pipe?: IPipe<T | G, K>; }): Subscription; /** * Creates a Subscription for the value of the Observable. After one Update the Value will be deleted * @param func Function which is called when new Datas are pushed * @param mode Mode of the Subscription * @param options Additional Options */ once(func: IEventCallback<G, AD>, options?: INopeSubscriptionOptions): INopeObserver; /** * Async Function to Wait for an Update * @param mode Mode of the Subscription * @param options Additional Options for the Wait Function. */ waitFor(testCallback?: IWaitForCallback<G, AD>, options?: INopeWaitForObservableChangeOptions): Promise<G>; /** * Async Function to Wait for an Update * @param mode Mode of the Subscription * @param options Additional Options for the Wait Function. */ waitForUpdate(options?: INopeSubscriptionOptions): Promise<G>; get hasSubscriptions(): boolean; get observerLength(): number; constructor(_options?: TSubjectOptions); }