Last active
October 22, 2016 15:18
-
-
Save bnhansn/6163d15c2b6a5e7d8e7efd28ad86c022 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: [], // 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(), // new line | |
| }; | |
| case 'USER_LEFT_ROOM': | |
| return initialState; | |
| case 'MESSAGE_CREATED': // new case | |
| return { | |
| ...state, | |
| messages: [ | |
| ...state.messages, | |
| action.message, | |
| ], | |
| }; | |
| default: | |
| return state; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment