mobx-utils
Version:
Utility functions and common patterns for MobX
22 lines (21 loc) • 897 B
TypeScript
import { IDisposer } from "./utils";
/**
* `queueProcessor` takes an observable array, observes it and calls `processor`
* once for each item added to the observable array, optionally debouncing the action
*
* @example
* const pendingNotifications = observable([])
* const stop = queueProcessor(pendingNotifications, msg => {
* // show Desktop notification
* new Notification(msg);
* })
*
* // usage:
* pendingNotifications.push("test!")
*
* @param {T[]} observableArray observable array instance to track
* @param {(item: T) => void} processor action to call per item
* @param {number} [debounce=0] optional debounce time in ms. With debounce 0 the processor will run synchronously
* @returns {IDisposer} stops the processor
*/
export declare function queueProcessor<T>(observableArray: T[], processor: (item: T) => void, debounce?: number): IDisposer;