DOM EventStreams (take two on Streams): Request for feedback

Tab Atkins Jr. jackalmage at gmail.com
Tue Apr 16 16:38:50 PDT 2013


Condensing my suggestions for additional variants into one small post:

* EventStream is an abstraction to represent streams of events as a
first-class value.  It's lossy, and forgets about its history.
(Though we probably want a switch allowing it to at least remember its
history before the first listener is attached.)  It's multi-listener.
This will be used for event-like interfaces that don't need the
complexity of DOM Events (because they're not tree-based).  I think we
should also allow a way to extract an EventStream from *any*
element/event pair - the stream is updated whenever an event
successfully reaches the element without being cancelled by an
ancestor.

* UpdateStream is an EventStream specifically focused on watching
updates of some given value.  When you add a new listener, the stream
replays its most recent update to the new listener.  It adds a
.value() function, which is identical to .next() but also gets the
most recent update replayed first.  It's multi-listener, and probably
also wants the remember-initial-history switch.)  This is intended for
something like my proposal for "UpdateStream.watch(object, property)",
which turns *any* JS property into an event stream of value changes.
(This can be built on top of Object.observe, so there's nothing
fundamentally new there.)

* ValueStream is a single-listener non-lossy stream.  Only one
.listen() callback can be active at a time; trying to call .listen()
again before the first is unlistened throws an error.  If there's no
listener, .next() can be used to pull values out of the stream in
succession without loss. Successive calls to .next() return successive
values from the stream.  (This is unlike EventStream, where multiple
.next() calls in the same tick will return equivalent futures for
whatever the very next value is.)  This is intended for a lot of
general use-cases, like pulling tokens out of a token stream.

Have I missed any major use-cases?

~TJ


More information about the es-discuss mailing list