Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 32 additions & 5 deletions src/app/stores/TodoStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here is an issue I was having, this deals with the entire list. It seems like I'd persist remotely individual todo items, vs the entire array.

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();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/views/TodoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var TodoList = function(TodoItem, TodoActions, EventHandler) {

this.handlers = {
toggleAllChange: toggleAllChange
}
};
this.props.todoList = [];
},

render: function() {
Expand Down