Skip to content

Instantly share code, notes, and snippets.

@raphaelmonte
Last active October 13, 2020 11:21
Show Gist options
  • Save raphaelmonte/af22ec09a18a147ed61d74c62496ad11 to your computer and use it in GitHub Desktop.
Save raphaelmonte/af22ec09a18a147ed61d74c62496ad11 to your computer and use it in GitHub Desktop.
Redux - Example Publish-subscribe pattern
function firstReducer(state, action) {
if (action.type === 'LOGIN_PENDING') console.log('firstReducer log');
return state;
}
function secondReducer(state, action) {
if (action.type === 'LOGIN_PENDING') console.log('secondReducer log');
return state;
}
const reducer = combineReducers({ firstReducer, secondReducer })
const store = createStore(reducer);
// all subscribers listened to the triggered event
store.dispatch({ type: 'LOGIN_PENDING' });
// firstReducer log
// secondReducer log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment