client/src/sagas/index.js
changeset 30 4d93f4ed95bc
parent 29 4cfeabef7d5e
child 40 7f940dbb60a6
--- a/client/src/sagas/index.js	Mon Jun 12 18:12:38 2017 +0200
+++ b/client/src/sagas/index.js	Wed Jun 14 12:28:09 2017 +0200
@@ -40,6 +40,28 @@
 
 // ---
 
+export function* updateSession(action) {
+
+  const { _id } = action.session;
+  let session;
+
+  const response = yield sessionsDB.get(_id).then(function(doc) {
+    session = Object.assign({}, doc, action.values);
+    return sessionsDB.put(session);
+  });
+
+  yield put({
+    type: types.UPDATE_SESSION,
+    session: Object.assign({}, session, { rev: response.rev })
+  })
+}
+
+export function* watchUpdateSession() {
+  yield takeLatest(types.UPDATE_SESSION_ASYNC, updateSession)
+}
+
+// ---
+
 export function* addNote(action) {
   const response = yield notesDB.put(action.note);
   // TODO Error control
@@ -73,5 +95,6 @@
     watchLoadNotesBySession(),
     watchAddNote(),
     watchCreateSession(),
+    watchUpdateSession(),
   ])
 }