Skip to content

Instantly share code, notes, and snippets.

@dominictobias
Last active January 29, 2020 15:35
Show Gist options
  • Save dominictobias/70074f2ab0146b288e3801258c6cdc41 to your computer and use it in GitHub Desktop.
Save dominictobias/70074f2ab0146b288e3801258c6cdc41 to your computer and use it in GitHub Desktop.
appState
const darkTheme = {
name: 'dark',
background: 'black',
text: 'white',
}
const lightTheme = {
name: 'light',
background: 'white',
text: 'black',
}
function reducer(state, actionName, payload) {
switch (actionName) {
case 'toggleTheme':
return {
...state,
theme: state.theme.name === 'light' ? darkTheme : lightTheme,
};
default:
throw new Error(`Action does not exist: ${actionName}`);
}
}
const appState = new GlobalState(reducer, { theme: lightTheme });
export default appState;
@dominictobias
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment