client/src/reducers/sessionsReducer.js
changeset 12 48ddaa42b810
child 29 4cfeabef7d5e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/reducers/sessionsReducer.js	Wed May 31 17:51:54 2017 +0200
@@ -0,0 +1,28 @@
+import Immutable from 'immutable';
+import * as types from '../constants/actionTypes';
+
+export const currentSession = (state = null, action) => {
+  switch (action.type) {
+    case types.NEW_SESSION:
+      return action.session;
+    default:
+      return state;
+  }
+};
+
+export const sessions = (state = Immutable.List([]), action) => {
+  switch (action.type) {
+    case types.NEW_SESSION:
+      return state.push(action.session);
+    case types.UPDATE_SESSION:
+      const sessionToUpdate = state.find(session => session === action.session);
+      const sessionIndex = state.indexOf(action.session);
+      if (sessionIndex === -1) {
+        return state;
+      }
+      const updatedSession = Object.assign({}, sessionToUpdate, action.values);
+      return state.set(sessionIndex, updatedSession);
+    default:
+      return state;
+  }
+};