From d755cf67a7249caa544572750d80a65d6d57a02c Mon Sep 17 00:00:00 2001 From: Andrey Melnik Date: Mon, 29 Aug 2016 14:24:37 +0300 Subject: [PATCH] rawChanges tracking --- dist/horizon-collection.html | 25 ++++++++++++++++++++++--- dist/todo-item.html | 2 -- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dist/horizon-collection.html b/dist/horizon-collection.html index 47ff30a..2302d7d 100644 --- a/dist/horizon-collection.html +++ b/dist/horizon-collection.html @@ -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) { diff --git a/dist/todo-item.html b/dist/todo-item.html index 95e4296..4dff465 100644 --- a/dist/todo-item.html +++ b/dist/todo-item.html @@ -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)); @@ -178,7 +177,6 @@ } }, _onCheck: function(){ - console.log("sda sd") this.fire('update-todo', {todo: this.todo}); }, _onDelete: function() {