@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
27 lines • 593 B
JavaScript
/**
* Debouncing behavior to queue the leading event.
*
* @group Transformers
* @see {@link debounce:function}
* @example
* ```
* --a-b-c--T20-d--|
*
* debounce(20, new DebounceLeadingBehavior())
*
* --a----------d---
* ```
*/
export class DebounceLeadingBehavior {
preTimer(state, chunk, controller) {
const enqueue = !state.timer && !state.queued;
if (enqueue) {
controller.enqueue(chunk);
return {
...state,
queued: enqueue,
};
}
}
}
//# sourceMappingURL=LeadingBehavior.js.map