fluxible-redux-dispatcher

1.0.1 • Public • Published

fluxible-redux-dispatcher

Use redux style action creators and thunks with fluxible. Meant for easing the porting from fluxible to redux. Use in conjunction with fluxible-reducer-store

Installation

npm install fluxible-redux-dispatcher

Usage

const { createDispatcher, createHandler } = require('fluxible-redux-dispatcher');
const actionCreator = function (payload) {
    return { type: 'REDUX_ACTION', payload };
};
const thunk = function (payload) {
    // note the getStore instead of the normal `getState`
    return function (dispatch, getStore) {
        dispatch(actionCreator(Object.assign({}, payload, {
            someProp: getStore('StoreName').getState().someProp
        })));
    };
};
 
// within a fluxible action
function someAction(actionContext, payload) {
    const dispatch = createDispatcher(actionContext);
    dispatch(actionCreator(payload));
    dispatch(thunk(payload));
}
 
// within a react component
class SomeComponent extends React.Component {
    constructor(props, context) {
        super(props);
        this.handlerOne = createHandler(context, actionCreator);
        this.handlerTwo = createHandler(context, thunk);
    }
    // ...
}

NOTE:

You cannot create the handlers in Fluxible's connectToStores because the context that gets passed in does not have executeAction defined. I could create a new connect method that would combine the functionality of Redux's connect and Fluxible's connectToStores to reduce the need to keep calling createHandler for each handler a component would have but this package isn't meant to be full-fledged, it's just to help with porting from Fluxible to Redux.

Readme

Keywords

none

Package Sidebar

Install

npm i fluxible-redux-dispatcher

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • petejodo