Last active
October 13, 2020 11:21
-
-
Save raphaelmonte/af22ec09a18a147ed61d74c62496ad11 to your computer and use it in GitHub Desktop.
Redux - Example Publish-subscribe pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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