Created
July 20, 2020 20:02
-
-
Save anderjs/f2c07da3f64f007692643b2ee49d74e9 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
| import produce from 'immer' | |
| import * as CR from '../actions/classroom' | |
| /** | |
| * @typedef {Object} ClassRoomState | |
| * @property {Array<User>} users | |
| * @property {import ('twilio-video').Room | null} room | |
| * @property {import ('twilio-video').VideoTrack} track | |
| */ | |
| /** | |
| * @type {ClassRoomState} | |
| */ | |
| export const initialState = { | |
| users: [], | |
| track: [], | |
| room: null | |
| } | |
| /** | |
| * | |
| * @param {ClassRoomState} state | |
| * @param {import ('redux').Action} | |
| */ | |
| const classRoomReducer = (state = initialState, { type, payload }) => { | |
| switch (type) { | |
| case CR.CONNECT_USER_TO_ROOM: | |
| state.users = state.users.concat({ ...payload }) | |
| return | |
| case CR.DISCONNECT_USER_TO_ROOM: | |
| state.users = state.users.filter(user => user !== payload) | |
| return | |
| case CR.SET_ROOM_NETWORK: | |
| state.room = payload | |
| return | |
| case CR.SET_VIDEO_TRACK: | |
| state.track = payload | |
| return | |
| default: | |
| return state | |
| } | |
| } | |
| export default produce(classRoomReducer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment