An easy way of consuming an EventEmitter (e.g. socket.io) in redux-saga
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.babelrc
.eslintrc.json
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
package.json

README.md

redux-saga-event-iterator

Build Status Coverage Status

An easy way of consuming an EventEmitter (e.g. socket.io) in redux-saga

Installation

Install using npm:

$ npm install --save redux-saga-event-iterator

Example

import {call} from 'redux-saga/effects';
import eventIterator from 'redux-saga-event-iterator';
import io from 'socket.io-client';

const socketClient = io('localhost:12345');

const listenerSaga = function * (eventName) {
  const {nextEvent, removeListener} = yield call(eventIterator, socketClient, eventName);

  while (true) {
    const payload = yield call(nextEvent);

    // Do something with payload
  }

  // Optionally remove listener, further calls to nextEvent will throw an error
  yield call(removeListener);
};

Testing

To run the tests:

$ npm test

Contributing

Feel free to create a pull request. Make sure to lint and test:

$ npm run lint && npm run test

License

MIT - see LICENSE