Skip to content

Instantly share code, notes, and snippets.

@Adesh
Last active July 13, 2018 01:26
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 Adesh/2eff2b58071041d94d129ada4c1f8d27 to your computer and use it in GitHub Desktop.
Save Adesh/2eff2b58071041d94d129ada4c1f8d27 to your computer and use it in GitHub Desktop.
const redux = reuire('redux');
const createStore = redux.createStore;
const = initialState = {
counter: 0
};
// Reducer
const rootReducer = (state = initialState, action) => {
if(action.type === 'INC_COUNTER') {
return {
...state,
counter: state.counter + 1
};
}
if(action.type === 'ADD_COUNTER') {
return {
...state,
counter: state.counter + action.value
};
}
return state;
};
// Store
const store = createStore(rootReducerl);
console.log(store.getState());
// Actions
store.dispatch({
type: 'INC_COUNTER'
}):
store.dispatch({
type: 'ADD_COUNTER'
}, 10):
console.log(store.getState());
// Subscription
store.subscribe(() => {
console.log('[Subscription]', store.getState());
});
@Adesh
Copy link
Author

Adesh commented Jul 12, 2018

First commit

@Adesh
Copy link
Author

Adesh commented Jul 12, 2018

Add actions

@Adesh
Copy link
Author

Adesh commented Jul 12, 2018

Subscribe

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