Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Create Redux actions from arbitraty sources out of middlewares

License

Notifications You must be signed in to change notification settings

michaelcontento/redux-middleware-oneshot

Repository files navigation

license npm version npm downloads Code Climate build

Create Redux actions from arbitraty sources out of middlewares.

Deprecated - No longer maintained

My focus has left the node / react ecosystem and this module is no longer maintained.

Thank you for your patience and using this module in the first place!

Installation

npm install --save redux-middleware-oneshot

Usage

// In this example, we want to create someAction in redux for every
// change-event emitted by someEventEmitter
import someEventEmitter from './someEventEmitter';
import someAction from './someAction';

// And for this we simply create a new oneShot middleware
import createOneShot from 'redux-middleware-oneshot';
const myMiddleware = createOneShot((dispatch) => {
    // This function is called exactly once as soon as the first action
    // runs through redux. Perfect moment to glue things together!
    someEventEmitter.addEventListener('change', (event) => {
        dispatch(someAction(event.value));
    });
});

// Everything else is straight forward Redux ...
import { createStore, applyMiddleware, combineReducers } from 'redux';
const createStoreWithMiddleware = applyMiddleware(myMiddleware)(createStore);
const store = createStoreWithMiddleware(/* reducer */);

Todo

  • Write tests for everything!

About

Create Redux actions from arbitraty sources out of middlewares

Resources

License

Stars

Watchers

Forks

Packages

No packages published