Wrap handlers to use pull-stream in a choo plugin.
This is intended to go beyond basic choo usage, and tread into the domain of
managing asynchronous complexity using streams / FRP.
While streams code takes longer to write up front, resulting code is generally
stateless, pretty damn fast and surprisingly reusable. pull-streams are a
minimal version of streams that weigh 200 bytes and handle backpressure
phenomenally.
Now each handler in a model expects a valid through pull-stream to be
returned synchronously. Initial data will be passed as the source, errors
handling and done() calls are appended in the sink:
Like all other API methods, so too does the send() method become a
pull-stream. More specifically it becomes a through stream that takes the
action name as the sole arugment, and pushes any results into any a
connecting through or sink stream:
Create an object of hooks that can be passed to app.use(). Internally ties
into the following hooks:
wrapSubscriptions: changes the API of subscriptions to be (Send$)
wrapEffects: changes the API of effects to be (state, Send$)
The following options can be passed:
opts.subscriptions: default: true. Determine if subscriptions should
be wrapped
opts.effects: default: true. Determine if effects should be wrapped
Incrementally enabling options can be useful when incrementally upgrading from
a CSP-style codebase to a reactive / streaming one.
pull.subscription(subscription)
Wrap a single subscription. Useful to incrementally upgrade a CSP-style
codebase to a reactive / streaming one.
pull.effect(effect)
Wrap a single effect. Useful to incrementally upgrade a CSP-style
codebase to a reactive / streaming one.
FAQ
Why aren't reducers wrapped in pull-streams?
In choo@3 the internal workings demand that data always be returned
synchronously. Because pull-stream returns data in a callback, reducers
cannot be wrapped. Perhaps at some point we'll allow for a hybrid API, but at
this point it's frankly not possible.