Skip to content

Instantly share code, notes, and snippets.

@anderjs
Created July 20, 2020 20:02
Show Gist options
  • Select an option

  • Save anderjs/f2c07da3f64f007692643b2ee49d74e9 to your computer and use it in GitHub Desktop.

Select an option

Save anderjs/f2c07da3f64f007692643b2ee49d74e9 to your computer and use it in GitHub Desktop.
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