bootstack.streams.Stream#
- class bootstack.streams.Stream(owner, *, _source=None, _scheduler=None)#
Bases:
Generic[T]A composable push-stream for widget events.
Created by
widget.on(event)(no handler). Chain operators to transform or filter events, then call.listen(handler)to attach a handler and activate the upstream event binding.Usage:
# Simple — bind immediately, return Subscription sub = widget.on("change", handler) # Composed — lazy bind, activated by .listen() sub = ( widget.on("change") .debounce(300) .filter(lambda e: len(e.value or "") > 1) .listen(on_search) ) sub.cancel() # detach handler and remove the event binding
All operator methods return a new
Stream— they do not consume the original..listen()is the only terminal; it activates the binding and returns a cancellable handle.- Parameters:
owner (tk.Misc) – Widget used for timer scheduling (debounce/throttle delays).
_source (Optional[Callable[[Callable[[T], Any]], AnySubscription]]) – Internal — callable that, given a downstream handler, installs the upstream binding and returns a handle.
- debounce(ms)#
Emit after
msmilliseconds of silence — resets on each new value.Useful for search-as-you-type: only fires after the user stops typing.
- delay(ms)#
Re-emit each value after a fixed
msmillisecond delay.
- filter(pred)#
Emit only values for which
pred(value)isTrue.
- listen(handler)#
Attach
handlerand activate the upstream event binding.This is the only terminal operator. Returns a cancellable handle — call
.cancel()to detach the handler and clean up all resources (event binding, pending timers) in the operator chain.
- map(fn)#
Transform each event value through
fn.
- tap(fn)#
Call
fnfor side-effects on each value; forward value unchanged.