From 0eed04e7f99418a5966c679ccb0f70764582ceac Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Mon, 11 Jun 2018 11:29:26 -0500 Subject: [PATCH 1/2] Revert "unremoving scope.getPathsforKey in production" This reverts commit 59aaf05e6555cde219a7cbeede061eec25aa4e34. --- can-view-scope.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/can-view-scope.js b/can-view-scope.js index eb67e9f..beed814 100644 --- a/can-view-scope.js +++ b/can-view-scope.js @@ -427,7 +427,9 @@ assign(Scope.prototype, { // ## Scope.prototype.getPathsForKey // Finds all paths that will return a value for a specific key + // NOTE: this is for development purposes only and is removed in production getPathsForKey: function getPathsForKey(key) { + //!steal-remove-start var paths = {}; var getKeyDefinition = function(obj, key) { @@ -493,6 +495,7 @@ assign(Scope.prototype, { }); return paths; + //!steal-remove-end }, // ## Scope.prototype.hasKey From 6b6ac0bbb479e32beb811aa3c8caed8b6186438c Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Mon, 11 Jun 2018 11:24:02 -0500 Subject: [PATCH 2/2] refactoring Scope.prototype.hasKey to avoid using getPathsForKey --- can-view-scope.js | 48 +++++++++-------------------------------------- package.json | 2 +- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/can-view-scope.js b/can-view-scope.js index beed814..4487680 100644 --- a/can-view-scope.js +++ b/can-view-scope.js @@ -501,48 +501,18 @@ assign(Scope.prototype, { // ## Scope.prototype.hasKey // returns whether or not this scope has the key hasKey: function hasKey(key) { - // jshint maxdepth:5 - var context = this._context; - var keyReads = observeReader.reads(key); - var propDefined = false; - - if(typeof context === "object") { - if(!keyReads) { - propDefined = canReflect.hasKey(context, key); - } else { - var reads = keyReads, i = 0, readsLength = reads.length; - var read; - do { - read = reads[i]; - if(canReflect.hasKey(context, read.key)) { - propDefined = true; - - // Get the next context and continue to see if the key is defined. - context = canReflect.getKeyValue(context, read.key); - - if(context) { - propDefined = false; - i++; - continue; - } else { - break; - } - } - break; - } while(i < readsLength); - } - } + var reads = observeReader.reads(key); + var readValue; - // if the prop isn't defined on the context, check if it is a supported "special" key - // like scope.top. or scope.vm. - if (!propDefined) { - var paths = this.getPathsForKey(key); - if (paths[key]) { - propDefined = true; - } + if (reads[0].key === "scope") { + // read properties like `scope.vm.foo` directly from the scope + readValue = observeReader.read(this, reads.slice(1), key); + } else { + // read normal properties from the scope's context + readValue = observeReader.read(this._context, reads, key); } - return propDefined; + return readValue.foundLastParent && readValue.parentHasKey; }, // ## Scope.prototype.getDataForScopeSet diff --git a/package.json b/package.json index 10a2893..90b8223 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "can-simple-map": "^4.0.0", "can-single-reference": "^1.0.0", "can-stache-helpers": "^1.0.0", - "can-stache-key": "^1.2.0", + "can-stache-key": "^1.3.0", "can-symbol": "^1.0.0" }, "devDependencies": {