client/src/reducers/sessionsReducer.js
changeset 62 b2514a9bcd49
parent 59 1eb52770eefa
child 93 469da13402e2
equal deleted inserted replaced
61:7586b4a11c32 62:b2514a9bcd49
     1 import Immutable from 'immutable';
     1 import Immutable from 'immutable';
     2 import * as types from '../constants/actionTypes';
     2 import * as types from '../constants/actionTypes';
       
     3 import SessionRecord from '../store/sessionRecord';
     3 
     4 
     4 export const currentSession = (state = null, action) => {
     5 // export const currentSession = (state = null, action) => {
     5   switch (action.type) {
     6 //   switch (action.type) {
     6     case types.CREATE_SESSION:
     7 //     case types.CREATE_SESSION:
     7       return action.session;
     8 //       return action.session;
     8     default:
     9 //     default:
     9       return state;
    10 //       return state;
    10   }
    11 //   }
    11 };
    12 // };
    12 
    13 
    13 export const sessions = (state = Immutable.List([]), action) => {
    14 export const sessions = (state = Immutable.List([]), action) => {
    14   switch (action.type) {
    15   switch (action.type) {
    15     case types.CREATE_SESSION:
    16     case types.CREATE_SESSION:
    16       return state.push(action.session);
    17       return state.push(new SessionRecord(action.session));
    17     case types.UPDATE_SESSION:
    18     case types.UPDATE_SESSION:
    18       const sessionToUpdate = state.find(session => session === action.session);
    19       const sessionToUpdate = state.find(session => session === action.session);
    19       const sessionIndex = state.indexOf(action.session);
    20       const sessionIndex = state.indexOf(action.session);
    20       if (sessionIndex === -1) {
    21       if (sessionIndex === -1) {
    21         return state;
    22         return state;
    22       }
    23       }
    23       const updatedSession = Object.assign({}, sessionToUpdate, action.values);
    24       const updatedSession = sessionToUpdate.merge(action.values);
    24       return state.set(sessionIndex, updatedSession);
    25       return state.set(sessionIndex, updatedSession);
    25     case types.LOAD_SESSIONS:
    26     case types.LOAD_SESSIONS:
    26       return action.sessions;
    27       return action.sessions;
    27     default:
    28     default:
    28       return state;
    29       return state;