mcfly-combinereducers

Util to use in a McFly-Store's callback. Turns an object whose values are different reducer functions, into a single reducerFunction

Usage no npm install needed!

<script type="module">
  import mcflyCombinereducers from 'https://cdn.skypack.dev/mcfly-combinereducers';
</script>

README

McFly CombineReducers

Util to use in a McFly-Store's callback.
It turns an object whose values are different reducer functions, into a single reducerFunction.

usage

var Redux 				= require('redux');
,	reducerCollection 	= require('../actions/reducers')
,	McFly 				= require('../my-mcfly')
,	combineReducers 	= require('mcfly-combinereducers')
,	combinedReducers 	= combineReducers(reducerCollection)
,	_state 				= _getState() // however you'll get it
,	MsgStore 			= McFly.createStore({
        getState: function() {
            return this.state;
        }
    }, 	function(action) {
            // switch(action.type) { ... }
            // outsource your reducers and use:
            combinedReducers(_state, action);
            // standard McFly procedure
            MsgStore.emit('change');
            return true;
        }
    )
;
module.exports 	= MsgStore;
// actions/reducers.js
var ReducerCollection 	= {
        'todo': 	function(state, action) {
            switch (action.type) {
                case 'SEND_MSG':
                    _state.todos.push(action.payload);
                default:
                    return _state;
            }
        }
    ,	'counter': 	function(state, action) {
            switch (action.type) {
                case 'INCREMENT':
                    return _state.counter + 1;
                case 'DECREMENT':
                    return _state.counter - 1;
                default:
                    return _state;
            }
        }
    }
;
module.exports 	= ReducerCollection;

API

@param {object} ReducerCollection - your reducer functions
@return {func} combinedReducers - your new reducer function
combineReducers(ReducerCollection)
@param {object} state - your App/Component State
@param {object} action - a flux standard action object
@return {bool} success - true at success
combinedReducers(state, action);