On Fri, Jun 19, 2015 at 2:46 PM, David Rajchenbach-Teller <
dtel...@mozilla.com> wrote:

> Out of curiosity: can these streams be used as a base for reactive
> programming? Or is it an entirely separate notion of streams?
>

I'm not an expert on reactive programming, but I believe its based around
the observables pattern.  Basically a way to signal next object, complete,
and error.  I believe most APIs look something like:

  function handleNext() { ... }
  function handleComplete() { ... }
  function handleError() { ... }

  data.subscribe(handleNext, handleComplete, handleError);

The WhatWG Streams proposal is a superset of observables.  You can achieve
the same sort of behavior by doing something like:

 data.subscribe(new WritableStream({
    write: handleNext,
    close: handleComplete,
    abort: handleError
  }));
// data then uses WritableStream.write(), .close(), and .abort() to
communicate changes

You could also use ReadableStream, but it doesn't look as similar to
observables:

  var reader = data.getStream().getReader();
  reader.read().then(function handleRead(value) {
    handleNext(value);
    return reader.read().then(handleRead);
  }).catch(handleError);

  reader.closed.then(handleComplete);

I think the Streams spec is more comprehensive to just observables because
it offers a pull interface in ReadableStream instead of just a push
interface.  In general pull interfaces handle backpressure better.

Hope that helps.

Ben


>
> Cheers,
>  David
>
> On 19/06/15 20:09, Benjamin Kelly wrote:
> > Also, I have setup a session on streams in the DOM room at Whistler:
> >
> >
> >
> http://juneworkweekwhistler2015.sched.org/event/28ff926a768953ba39a44cd36598d7f7
> >
> > Please stop by if you have questions or just want to talk about it.
> >
> > Thanks!
> >
> > Ben
>
>
> --
> David Rajchenbach-Teller, PhD
>  Performance Team, Mozilla
>
>
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to