Skip to content

Commit

Permalink
rawChanges tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
dru committed Aug 29, 2016
1 parent 9bfef84 commit d755cf6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 22 additions & 3 deletions dist/horizon-collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,29 @@
ready: function() {
var that = this

horizon(this.name).watch().subscribe(function(messages){
that.set("data", messages);
horizon(this.name).watch({rawChanges: true}).subscribe({
next: function(change) {
switch(change.type) {
case "initial":
case "add":
that.push('data', change.new_val)
break;
case "remove":
var index = that.data.findIndex(function(a){ return a.id == change.old_val.id});
if (index != -1) {
that.splice('data', index, 1);
}
break;
case "change":
var index = that.data.findIndex(function(a){ return a.id == change.old_val.id});
if (index != -1) {
that.set(`data.${index}`, change.new_val)
}
}
},
error: function(err) { console.error(`Error: ${err}`) }
});

},

insert: function(data) {
Expand Down
2 changes: 0 additions & 2 deletions dist/todo-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
},

detached: function() {
this.playAnimation('exit');
this.removeEventListener('focus', this._activate.bind(this), true);
this.removeEventListener('blur', this._deactivate.bind(this), true);
this.removeEventListener('mouseenter', this._activate.bind(this));
Expand Down Expand Up @@ -178,7 +177,6 @@
}
},
_onCheck: function(){
console.log("sda sd")
this.fire('update-todo', {todo: this.todo});
},
_onDelete: function() {
Expand Down

0 comments on commit d755cf6

Please sign in to comment.