Skip to content

Instantly share code, notes, and snippets.

@dduleone
Created August 19, 2018 17:47
Show Gist options
  • Save dduleone/480d50755fbb2e9d200e17d4a82587bf to your computer and use it in GitHub Desktop.
Save dduleone/480d50755fbb2e9d200e17d4a82587bf to your computer and use it in GitHub Desktop.
UIE Handlers Prototype.js
const createUIEHandler = (type, onFunction, handleFunction) => {
return {
type,
onFunction: (payload) => {
return {
type,
payload: onFunction(payload)
};
},
handleFunction
};
}
export const UIEHandlers = {
"CLICK_BACK_BUTTON": createUIEHandler("CLICK_BACK_BUTTON",
() => {},
(state, action) => {
return state;
}
),
// ...
// ...
// ... etc ...
"RENDER_BUILD_DETAILS": createUIEHandler("RENDER_BUILD_DETAILS",
(singleBuild) => {
singleBuild
},
(state, {payload}) => {
// Change the store to represent that a specific PartyStrat is on display.
// The BuildDetails component will use this value to know which build to display and interact with.
const {singleBuild} = payload;
return {
...state,
isVisible: true,
activeBuild: singleBuild
};
}
)
};
export const reducer = (state = defaultState, action) => {
const {type} = action;
if (UIEHandlers.hasOwnProperty(type)) {
const {handleFunction} = UIEHandlers[type];
return handleFunction(state, action);
}
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment