Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 22, 2016 18:23
Show Gist options
  • Save bnhansn/56c33d9b8441aaf132de4a74ed0d2881 to your computer and use it in GitHub Desktop.
Save bnhansn/56c33d9b8441aaf132de4a74ed0d2881 to your computer and use it in GitHub Desktop.
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