equal
deleted
inserted
replaced
|
1 import Immutable from 'immutable'; |
|
2 import * as types from '../constants/actionTypes'; |
|
3 |
|
4 export const currentSession = (state = null, action) => { |
|
5 switch (action.type) { |
|
6 case types.NEW_SESSION: |
|
7 return action.session; |
|
8 default: |
|
9 return state; |
|
10 } |
|
11 }; |
|
12 |
|
13 export const sessions = (state = Immutable.List([]), action) => { |
|
14 switch (action.type) { |
|
15 case types.NEW_SESSION: |
|
16 return state.push(action.session); |
|
17 case types.UPDATE_SESSION: |
|
18 const sessionToUpdate = state.find(session => session === action.session); |
|
19 const sessionIndex = state.indexOf(action.session); |
|
20 if (sessionIndex === -1) { |
|
21 return state; |
|
22 } |
|
23 const updatedSession = Object.assign({}, sessionToUpdate, action.values); |
|
24 return state.set(sessionIndex, updatedSession); |
|
25 default: |
|
26 return state; |
|
27 } |
|
28 }; |