Skip to content

Instantly share code, notes, and snippets.

@rohozhnikoff
Last active September 5, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohozhnikoff/b98820585cb1580159578e51dbd4e33f to your computer and use it in GitHub Desktop.
Save rohozhnikoff/b98820585cb1580159578e51dbd4e33f to your computer and use it in GitHub Desktop.
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