Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Last active October 22, 2016 15:18
Show Gist options
  • Save bnhansn/6163d15c2b6a5e7d8e7efd28ad86c022 to your computer and use it in GitHub Desktop.
Save bnhansn/6163d15c2b6a5e7d8e7efd28ad86c022 to your computer and use it in GitHub Desktop.
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