From 770971c8a1ff99bd1df012beef72e9cbb3e4856f Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Fri, 2 Jan 2015 13:30:30 -0500 Subject: [PATCH 1/2] Adds gulp-nodemon and gulp-notify to package.json --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f5a172..4494f81 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,9 @@ "sort-stream": "^1.0.0", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.0.0", - "watchify": "^2.1.1" + "watchify": "^2.1.1", + "gulp-nodemon": "^1.0.4", + "gulp-notify": "^1.0.2" }, "dependencies": { "di": "^2.0.0-pre-12", From f8a7910711e39fcb58f243f895cd375d221be740 Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Fri, 2 Jan 2015 13:31:43 -0500 Subject: [PATCH 2/2] Adds asynchrony to TodoStore saves and TodoList. --- src/app/stores/TodoStore.js | 37 ++++++++++++++++++++++++++++++++----- src/app/views/TodoList.jsx | 3 ++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/app/stores/TodoStore.js b/src/app/stores/TodoStore.js index 720811a..d3acdb9 100644 --- a/src/app/stores/TodoStore.js +++ b/src/app/stores/TodoStore.js @@ -19,12 +19,39 @@ class TodoStore { console.log("OPERATION") return operation(todoList); }) - - // each updated note array is stored in local storage - this.todoList.subscribe((update) => { - console.log('SAVE', update) - LocalStorage.save(key, update) + .flatMapLatest((todoList) => { + console.log('SAVE', todoList); + + // "wrap" the local storage call in an Observable. this Observable + // will be subscribed to, synchronously execute the save, and + // synchronously complete. + // + // Run this in parallel with the Observable that does the async + // network request. ForkJoin waits for them both to complete, + // then onNext's an Array of each of their final values, then + // completes. + // + // Map the result back into the original todoList value for future + // subscribers. + return Rx.Observable.forkJoin([ + Rx.Observable.defer(() => { + // each updated note array is stored in local storage + LocalStorage.save(key, todoList); + return Rx.Observable.return(todoList); + }), + // replace this with your preferred async service call. + Rx.Observable.timer(500) + ]) + .map(() => todoList); }) + // publish here so that multiple people can subscribe to the + // `todoList` Observable, but only one async network request + // will be go out. Replay the most recent event to future + // subscribers so they don't miss out on + .replay(null, 1); + + // Connect publish's subject to the replay'd flatMapLatest. + this.todoList.connect(); } } diff --git a/src/app/views/TodoList.jsx b/src/app/views/TodoList.jsx index e223967..c1d2d03 100644 --- a/src/app/views/TodoList.jsx +++ b/src/app/views/TodoList.jsx @@ -19,7 +19,8 @@ var TodoList = function(TodoItem, TodoActions, EventHandler) { this.handlers = { toggleAllChange: toggleAllChange - } + }; + this.props.todoList = []; }, render: function() {