Skip to content

Instantly share code, notes, and snippets.

@davinctor
Created July 19, 2018 15:02
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 davinctor/d90a09ef8cfa00a89b1db6f4a0a4934f to your computer and use it in GitHub Desktop.
Save davinctor/d90a09ef8cfa00a89b1db6f4a0a4934f to your computer and use it in GitHub Desktop.
Redux using sample
// Easily run on `https://stephengrider.github.io/JSPlaygrounds/`
const reducer = (state = [], action) => {
switch (action.type) {
case 'split_string':
return action.payload.split('');
case 'add_character':
return [ ...state, action.payload ];
default:
return state;
}
};
const store = Redux.createStore(reducer);
store.getState();
const action = {
type: 'split_string',
payload: 'asdf'
};
store.dispatch(action);
store.getState();
const action2 = {
type: 'add_character',
payload: 'a'
};
store.dispatch(action2);
store.getState();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment