Last active
August 29, 2015 14:18
-
-
Save janv/fd6fdd72394139df48b6 to your computer and use it in GitHub Desktop.
Revisions
-
janv revised this gist
Apr 4, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,12 +8,12 @@ function Watcher(expression, handler, deep) { Watcher.prototype = { digest: function(){ var _new = this.expression(); var changed = !this.equals(this._old, _new); if (changed) this._handler(_new, _old); this._old = _new; }, equals: function(a, b) { return this._deep ? _.isEqual(a, b) : a === b; } } -
janv created this gist
Apr 4, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ function Watcher(expression, handler, deep) { this._expression = expression; this._handler = handler; this._deep = deep; this._old = undefined; } Watcher.prototype = { digest: function(){ var _new = this.expression(); var changed = this.compare(this._old, _new); if (changed) this._handler(_new, _old); this._old = _new; }, compare: function(a, b) { return this._deep ? _.isEqual(a, b) : a ===b; } }