Last active
September 5, 2017 23:11
-
-
Save rohozhnikoff/b98820585cb1580159578e51dbd4e33f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function createLeafReducer(initialState, HANDLERS) { | |
return function leafReducer(state, action) { | |
if (typeof state === 'undefined') return initialState; | |
const HANDLER = HANDLERS[action.type]; | |
if (typeof HANDLER === 'undefined') return state; | |
if (typeof HANDLER !== 'function') return HANDLER; | |
var newState; | |
try { | |
newState = HANDLER.call(HANDLERS, state, action); | |
} catch (err) { | |
console.error('Ошибка в обработке ивента ' + action.type, err); | |
} | |
return typeof newState === 'undefined' ? state : newState; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment