UNPKG

matrix-react-sdk

Version:
77 lines (76 loc) 2.67 kB
import { Action } from "./actions"; import { ActionPayload } from "./payloads"; type DispatchToken = string; /** * A dispatcher for ActionPayloads (the default within the SDK). * Based on the old Flux dispatcher https://github.com/facebook/flux/blob/main/src/Dispatcher.js */ export declare class MatrixDispatcher { private readonly callbacks; private readonly isHandled; private readonly isPending; private pendingPayload?; private lastId; /** * Registers a callback to be invoked with every dispatched payload. Returns * a token that can be used with `waitFor()`. */ register(callback: (payload: ActionPayload) => void): DispatchToken; /** * Removes a callback based on its token. */ unregister(id: DispatchToken): 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: DispatchToken[]): void; /** * Dispatches a payload to all registered callbacks. */ private _dispatch; /** * Is this Dispatcher currently dispatching. */ isDispatching(): boolean; /** * Call the callback stored with the given id. Also do some internal * bookkeeping. * * Must only be called with an id which has a callback and pendingPayload set * @internal */ private invokeCallback; /** * Set up bookkeeping needed when dispatching. * * @internal */ private startDispatching; /** * Clear bookkeeping used for dispatching. * * @internal */ private stopDispatching; /** * Dispatches an event on the dispatcher's event bus. * @param {ActionPayload} payload Required. The payload to dispatch. * @param {boolean=false} sync Optional. Pass true to dispatch * synchronously. This is useful for anything triggering * an operation that the browser requires user interaction * for. Default false (async). */ dispatch<T extends ActionPayload>(payload: T, sync?: boolean): void; /** * Shorthand for dispatch({action: Action.WHATEVER}, sync). No additional * properties can be included with this version. * @param {Action} action The action to dispatch. * @param {boolean=false} sync Whether the dispatch should be sync or not. * @see dispatch(action: ActionPayload, sync: boolean) */ fire(action: Action, sync?: boolean): void; } export declare const defaultDispatcher: MatrixDispatcher; export default defaultDispatcher;