diff --git a/src/lib/store/rooms/rooms.slice.ts b/src/lib/store/rooms/rooms.slice.ts index 0177640..50f5429 100644 --- a/src/lib/store/rooms/rooms.slice.ts +++ b/src/lib/store/rooms/rooms.slice.ts @@ -11,30 +11,32 @@ const roomsSlice = createSlice({ initialState, reducers: { setRoomState(state, action:PayloadAction) { - const type = action.payload.type; + const type = action.payload.type; + const key = type.slice(type.lastIndexOf('/') + 1); - // extract the room key from the type - const matches = type.match('/room/(.*)/status'); + console.log(type, key); - if (!matches) return; - - const key = matches[1]; + if(!key) return; // This method solves the issue of multiple layers of properties // and avoids doing a deep copy of the object const content = action.payload.content as RoomState; + console.log(content); + // Get existing room state const existingState = state[key] ?? {}; // merge new state with existing - const newState = _.merge(existingState, content); + const newState = merge(existingState, content); // overlay the incoming state properties onto the existing item // or create new item state[key] = newState; + console.log(state); + return state; } },