Created
October 22, 2016 18:23
-
-
Save bnhansn/56c33d9b8441aaf132de4a74ed0d2881 to your computer and use it in GitHub Desktop.
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 initialState = { | |
| channel: null, | |
| currentRoom: {}, | |
| messages: [], | |
| presentUsers: [], // new line | |
| }; | |
| export default function (state = initialState, action) { | |
| switch (action.type) { | |
| case 'ROOM_CONNECTED_TO_CHANNEL': | |
| return { | |
| ...state, | |
| channel: action.channel, | |
| currentRoom: action.response.room, | |
| messages: action.response.messages.reverse(), | |
| }; | |
| case 'USER_LEFT_ROOM': | |
| return initialState; | |
| case 'MESSAGE_CREATED': | |
| return { | |
| ...state, | |
| messages: [ | |
| ...state.messages, | |
| action.message, | |
| ], | |
| }; | |
| case 'ROOM_PRESENCE_UPDATE': // new case | |
| return { | |
| ...state, | |
| presentUsers: action.presentUsers, | |
| }; | |
| default: | |
| return state; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment