UNPKG

876 BTypeScriptView Raw
1import { IDisposer } from "./utils";
2/**
3 * `queueProcessor` takes an observable array, observes it and calls `processor`
4 * once for each item added to the observable array, optionally debouncing the action
5 *
6 * @example
7 * const pendingNotifications = observable([])
8 * const stop = queueProcessor(pendingNotifications, msg => {
9 * // show Desktop notification
10 * new Notification(msg);
11 * })
12 *
13 * // usage:
14 * pendingNotifications.push("test!")
15 *
16 * @param {T[]} observableArray observable array instance to track
17 * @param {(item: T) => void} processor action to call per item
18 * @param {number} [debounce=0] optional debounce time in ms. With debounce 0 the processor will run synchronously
19 * @returns {IDisposer} stops the processor
20 */
21export declare function queueProcessor<T>(observableArray: T[], processor: (item: T) => void, debounce?: number): IDisposer;