4.0.1 • Published 7 years ago

cycle-socket.io v4.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

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.

4.0.1

7 years ago

4.0.0

7 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

9 years ago