From 85d8a3a7276a00c4e6a584bc05826a98540f1492 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Mon, 27 Jul 2015 23:00:48 -0700 Subject: [PATCH] Denote keys with # to disambiguate from index. Fixes #2007. --- src/lib/collection.html | 20 ++++++++-- src/standard/notify-path.html | 18 +++++++-- test/unit/notify-path-elements.html | 2 + test/unit/notify-path.html | 62 ++++++++++++++++++++++------- 4 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/lib/collection.html b/src/lib/collection.html index 0e68e38b39..e89fc1d2ad 100644 --- a/src/lib/collection.html +++ b/src/lib/collection.html @@ -46,10 +46,11 @@ } else { this.pmap[item] = key; } - return key; + return '#' + key; }, removeKey: function(key) { + key = this._parseKey(key); this._removeFromMap(this.store[key]); delete this.store[key]; }, @@ -70,17 +71,27 @@ getKey: function(item) { if (item && typeof item == 'object') { - return this.omap.get(item); + return '#' + this.omap.get(item); } else { - return this.pmap[item]; + return '#' + this.pmap[item]; } }, getKeys: function() { - return Object.keys(this.store); + return Object.keys(this.store).map(function(key) { + return '#' + key; + }); + }, + + _parseKey: function(key) { + if (key[0] == '#') { + return key.slice(1); + } + throw new Error('unexpected key ' + key); }, setItem: function(key, item) { + key = this._parseKey(key); var old = this.store[key]; if (old) { this._removeFromMap(old); @@ -94,6 +105,7 @@ }, getItem: function(key) { + key = this._parseKey(key); return this.store[key]; }, diff --git a/src/standard/notify-path.html b/src/standard/notify-path.html index 3c804acdd0..af58b91d5e 100644 --- a/src/standard/notify-path.html +++ b/src/standard/notify-path.html @@ -195,14 +195,20 @@ get: function(path, root) { var prop = root || this; var parts = this._getPathParts(path); - var last = parts.pop(); - while (parts.length) { - prop = prop[parts.shift()]; + var array; + for (var i=0; i