このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

debounceOn, delayOn & throttleOn

Selector-driven time: each value names the stream that decides when it is due — debounce, delay, and throttle without a Duration.

FxEvents<T> FxEvents<T>.debounceOn(Stream<void> Function(T value) selector) // chain (events) FxEvents<T> FxEvents<T>.delayOn(Stream<void> Function(T value) selector) FxEvents<T> FxEvents<T>.throttleOn(Stream<void> Function(T value) selector, {bool leading = true, bool trailing = false})

Lecture

The Duration forms already live on debounce, throttle, and delay — a fixed clock, the same wait for every value. The xOn family hands that clock to a selector: each value produces a stream, and the first event on that stream is the moment the value is due. Wait for a blur instead of 300ms; debounce longer queries longer; release a held value when a button fires rather than when a timer does.

debounceOn(selector) is trailing-edge debounce with that stream as the quiet window. A newer value aborts the previous inner and starts a fresh one; the inner's first next emits the pending value; an inner that completes without a next drops it. A value still pending when the source closes is flushed, matching Duration debounce.

delayOn(selector) holds every value until its own inner fires — nothing is aborted, so two in-flight values can pass each other if their selectors do, matching Rx's delayWhen. The close waits for outstanding inners; errors are forwarded immediately, since only data is worth holding.

throttleOn(selector) emits at most one event per inner window: leading (on by default, like the stream form of throttle) keeps the first of the window; trailing keeps the newest seen when the inner fires, or when the source closes mid-window. fxdart events layer, after Rx's selector forms of debounce, delayWhen, and throttle.

Demo 1 · A burst, released when its selector fires

Demo 2 · Held until a notifier says go

Try it yourself

Exercise: one scroll offset per inner window, leading edge.

Related: debounce — the Duration form, and the callback wrapper · throttle — the Duration form, leading and trailing · delay — shift a whole stream by a fixed clock