Awesome
cycle-sse-driver
cycle-sse-driver is a Cycle.js driver for Server-Sent Events (SSE), a browser feature also known as EventSource. Server-Sent Events allow the server to continuously update the page with new events, without resorting to hacks like long-polling.
Example
The driver function should be called with an SSE URL. In the following code,
assume reasonably-defined view()
and model()
functions:
var makeSSEDriver = require('cycle-sse-driver');
function intent(responses) {
return {
input$: responses.DOM.select('input').events('input'),
eventOne$: responses.SSE('one'),
eventTwo$: responses.SSE('two'),
genericMessage$: responses.SSE()
}
}
Cycle.run(function(responses) {
var vtree$ = view(model(intent(responses)));
return { DOM: vtree$ };
}, {
DOM: makeDOMDriver('#myId'),
SSE: makeSSEDriver('/sse-url')
});
As demonstrated above, the response function may be called with an event type,
in which case only events of that type will be streamed. If the response
function is called with no arguments, generic messages (i.e. messages sent
without an event
field) will be streamed. Since cycle-sse-driver is a
source driver, the "main" function passed to Cycle.run()
need not return an
object with an SSE
member.
Like other Cycle.js drivers, the best way to use cycle-sse-driver is with browserify.
Thanks!
cycle-sse-driver is by Jess Austin and is distributed under the terms of the MIT License. Any and all potential contributions of issues and pull requests are welcome!