frontend/.pnpm-store/v3/files/e8/d53d1f945a1eb2eaef28390de7e9722de6a6be17d46f165b14bc776b9876f1c251ee5665a22dcb1965a585f80ed6cea9d8f570f9db81ebff6fab81bc67b161

62 lines
1.5 KiB
Plaintext

/**
* This class is mostly based on Flux's Dispatcher by Facebook
* https://github.com/facebook/flux/blob/master/src/Dispatcher.js
*/
export default class Dispatcher<TPayload> {
_callbacks: {
[key: string]: (payload: TPayload) => void;
};
_isDispatching: boolean;
_isHandled: {
[key: string]: boolean;
};
_isPending: {
[key: string]: boolean;
};
_lastID: number;
_pendingPayload: TPayload;
constructor();
/**
* Registers a callback to be invoked with every dispatched payload. Returns
* a token that can be used with `waitFor()`.
*/
register(callback: (payload: TPayload) => void): string;
/**
* Removes a callback based on its token.
*/
unregister(id: string): void;
/**
* Waits for the callbacks specified to be invoked before continuing execution
* of the current callback. This method should only be used by a callback in
* response to a dispatched payload.
*/
waitFor(ids: Array<string>): void;
/**
* Dispatches a payload to all registered callbacks.
*/
dispatch(payload: TPayload): void;
/**
* Is this Dispatcher currently dispatching.
*/
isDispatching(): boolean;
/**
* Call the callback stored with the given id. Also do some internal
* bookkeeping.
*
* @internal
*/
private _invokeCallback;
/**
* Set up bookkeeping needed when dispatching.
*
* @internal
*/
private _startDispatching;
/**
* Clear bookkeeping used for dispatching.
*
* @internal
*/
private _stopDispatching;
}