Skip to content

Instantly share code, notes, and snippets.

@carlos-wong
Last active November 25, 2016 15:56
Show Gist options
  • Save carlos-wong/39ab861866f9c9287714 to your computer and use it in GitHub Desktop.
Save carlos-wong/39ab861866f9c9287714 to your computer and use it in GitHub Desktop.
let initialState = Immutable.Map({count:1, b:2, c:3});
function counter(state = initialState, action) {
switch (action.type) {
case 'INCREMENT':
return state.set('count',state.get('count')+1);
case 'DECREMENT':
return state.set('count',state.get('count')-1);
default:
return state;
}
}
let store = createStore(counter);
store.subscribe(() =>{
console.log(store.getState());
});
store.subscribe(() =>{
console.log("another subscribe:",store.getState());
});
store.dispatch({ type: 'INCREMENT' });
// 1
store.dispatch({ type: 'INCREMENT' });
// 2
store.dispatch({ type: 'DECREMENT' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment