From 6fdc5b7c7d82d6e326e5f4634650ff752ceb4416 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 27 Nov 2017 12:07:57 -0500 Subject: [PATCH] add handleActions redux util --- ui/js/util/redux-utils.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ui/js/util/redux-utils.js diff --git a/ui/js/util/redux-utils.js b/ui/js/util/redux-utils.js new file mode 100644 index 000000000..6875ec550 --- /dev/null +++ b/ui/js/util/redux-utils.js @@ -0,0 +1,10 @@ +// util for creating reducers +// based off of redux-actions +// https://redux-actions.js.org/docs/api/handleAction.html#handleactions +export const handleActions = (actionMap, defaultState) => { + return (state = defaultState, action) => { + const handler = actionMap[action.type]; + const newState = handler ? handler(state, action) : {}; + return Object.assign({}, state, newState); + }; +};