Created
April 22, 2016 13:24
-
-
Save tamizhvendan/b75e486c183f75dd12739458494d011e to your computer and use it in GitHub Desktop.
Redux sample implementation
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
| const statusMessagesReducer = (state = [], action) => { | |
| if (action.type === "ADD_STATUS") { | |
| return state.concat(action.statusMessage); | |
| } | |
| return state; | |
| }; | |
| const notificationsReducer = (state = [], action) => { | |
| if (action.type === "ADD_NOTIFICATION") { | |
| return state.concat(action.notification); | |
| } | |
| return state; | |
| }; | |
| const store = Redux.createStore(Redux.combineReducers({ | |
| statusMessages: statusMessagesReducer, | |
| notifications: notificationsReducer, | |
| })); | |
| let addStatusMessage = (statusMessage) => { | |
| return { | |
| type : "ADD_STATUS", | |
| statusMessage : statusMessage | |
| }; | |
| }; | |
| let addNotification = (notification) => { | |
| return { | |
| type : "ADD_NOTIFICATION", | |
| notification : notification | |
| }; | |
| }; | |
| let unsubscribe = store.subscribe(() => | |
| console.log(store.getState()) | |
| ) | |
| store.dispatch(addStatusMessage({ | |
| message : "Redux looks cool", | |
| likesCount: 23, | |
| postedAt: "12/12/2015" | |
| })); | |
| store.dispatch(addNotification({ | |
| message : "Some liked your status" | |
| })); | |
| unsubscribe(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment