A Cycle driver for Socket.IO clients
JavaScript
Latest commit b4eb091 Sep 16, 2016 @cgeorg committed on GitHub Merge pull request #11 from Alex0007/master
fix of #10
Permalink
Failed to load latest commit information.
src remove console.error Sep 12, 2016
.gitignore Use prepublish to build dist Jul 13, 2016
README.md Fix eventListener multiple args Jul 18, 2016
package.json Bumped to 3.0 for xstream Aug 20, 2016

README.md

Cycle-Socket.IO

A Cycle driver for applications using Socket.IO

Usage

import io from 'socket.io-client';
import {run} from '@cycle/xstream-run';
import {makeDOMDriver} from '@cycle/dom';
import {makeSocketIODriver} from 'cycle-socket.io';

function main({socketIO, dom}) {
    const vtree$ = render(dom);

    const incomingMessages$ = socketIO.get('messageType');
    const outgoingMessages$ = stream$.map(eventData => ({
      messageType: 'someEvent',
      message: eventData,
    }));

    return {dom: vtree$, socketIO: outgoingMessages$}
};

var socketIODriver = makeSocketIODriver(io(window.location.origin));
var domDriver = makeDOMDriver(document.body);
run(main, {
    dom: domDriver,
    socketIO: socketIODriver
});

API

makeSocketIODriver(socket)

Creates a socket.io driver which uses the provided socket to listen to and emit events.

sources.get(eventName, { multiArgs = false })

Returns a stream of eventName from the given socket. If the event expects multiple arguments from the Socket.IO server, pass in multiArgs = true, and the stream will emit an array with the arguments.