Created
August 19, 2018 17:47
-
-
Save dduleone/480d50755fbb2e9d200e17d4a82587bf to your computer and use it in GitHub Desktop.
UIE Handlers Prototype.js
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
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