From 11d3cdd5f6994ae197eaf3599f5fcb0cbe2760db Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Tue, 3 Jul 2018 16:10:38 -0700 Subject: [PATCH] Check for can-observation._value instead of .value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit can-observation’s value property is going to be a getter, so now the `._value` property needs to be used. Related to https://github.com/canjs/can-observation/pull/135 --- .jshintrc | 1 + scope-key-data.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.jshintrc b/.jshintrc index f7840d6..3631bc9 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,6 +26,7 @@ "Map": true }, "strict": false, + "validthis": true, "curly": true, "eqeqeq": true, "freeze": true, diff --git a/scope-key-data.js b/scope-key-data.js index a11880f..8e402d5 100644 --- a/scope-key-data.js +++ b/scope-key-data.js @@ -106,6 +106,14 @@ var ScopeKeyData = function(scope, key, options){ valueEventBindings(ScopeKeyData.prototype); +function fastOnBoundSet_Value() { + this._value = this.newVal; +} + +function fastOnBoundSetValue() { + this.value = this.newVal; +} + Object.assign(ScopeKeyData.prototype, { constructor: ScopeKeyData, dispatch: function dispatch(newVal){ @@ -174,9 +182,12 @@ Object.assign(ScopeKeyData.prototype, { return Observation.prototype.dependencyChange.apply(this, arguments); }; - observation.onBound = function(){ - this.value = this.newVal; - }; + + if (observation.hasOwnProperty("_value")) {// can-observation 4.1+ + observation.onBound = fastOnBoundSet_Value; + } else {// can-observation < 4.1 + observation.onBound = fastOnBoundSetValue; + } }, toSlowPath: function(){ this.observation.dependencyChange = Observation.prototype.dependencyChange;