diff --git a/packages/ember-metal/lib/chains.js b/packages/ember-metal/lib/chains.js index a72be5f1abe..693de378a56 100644 --- a/packages/ember-metal/lib/chains.js +++ b/packages/ember-metal/lib/chains.js @@ -21,24 +21,27 @@ function Chains() { } Chains.prototype = Object.create(null); -// a map of nodes that reference a key -function ChainWatchers(src) { - this.src = src; - this.nodes = Object.create(null); +function ChainWatchers(obj) { + // this obj would be the referencing chain node's parent node's value + this.obj = obj; + // chain nodes that reference a key in this obj by key + // we only create ChainWatchers when we are going to add them + // so create this upfront + this.chains = new Chains(); } ChainWatchers.prototype = { add(key, node) { - let nodes = this.nodes[key]; + let nodes = this.chains[key]; if (nodes === undefined) { - this.nodes[key] = [node]; + this.chains[key] = [node]; } else { nodes.push(node); } }, remove(key, node) { - let nodes = this.nodes[key]; + let nodes = this.chains[key]; if (nodes) { for (var i = 0, l = nodes.length; i < l; i++) { if (nodes[i] === node) { @@ -50,7 +53,7 @@ ChainWatchers.prototype = { }, has(key, node) { - let nodes = this.nodes[key]; + let nodes = this.chains[key]; if (nodes) { for (var i = 0, l = nodes.length; i < l; i++) { if (nodes[i] === node) { @@ -62,7 +65,7 @@ ChainWatchers.prototype = { }, revalidateAll() { - for (let key in this.nodes) { + for (let key in this.chains) { this.notify(key, true, undefined); } }, @@ -77,7 +80,7 @@ ChainWatchers.prototype = { // will be/are invalidated by this key change depending on the // whether the revalidate flag is passed notify(key, revalidate, callback) { - let nodes = this.nodes[key]; + let nodes = this.chains[key]; if (nodes === undefined || nodes.length === 0) { return; } @@ -135,7 +138,7 @@ function addChainWatcher(obj, keyName, node) { let m = metaFor(obj); - if (m.chainWatchers === undefined || m.chainWatchers.src !== obj) { + if (m.chainWatchers === undefined || m.chainWatchers.obj !== obj) { m.chainWatchers = new ChainWatchers(obj); } @@ -152,7 +155,7 @@ function removeChainWatcher(obj, keyName, node) { let m = obj.__ember_meta__; if (!m || - m.chainWatchers === undefined || m.chainWatchers.src !== obj) { + m.chainWatchers === undefined || m.chainWatchers.obj !== obj) { return; } diff --git a/packages/ember-metal/lib/property_events.js b/packages/ember-metal/lib/property_events.js index 14768ef51a0..f46505f4f50 100644 --- a/packages/ember-metal/lib/property_events.js +++ b/packages/ember-metal/lib/property_events.js @@ -191,7 +191,7 @@ function iterDeps(method, obj, deps, depKey, seen, meta) { } function chainsWillChange(obj, keyName, m) { - if (m.chainWatchers === undefined || m.chainWatchers.src !== obj) { + if (m.chainWatchers === undefined || m.chainWatchers.obj !== obj) { return; } @@ -199,7 +199,7 @@ function chainsWillChange(obj, keyName, m) { } function chainsDidChange(obj, keyName, m) { - if (m.chainWatchers === undefined || m.chainWatchers.src !== obj) { + if (m.chainWatchers === undefined || m.chainWatchers.obj !== obj) { return; } @@ -207,7 +207,7 @@ function chainsDidChange(obj, keyName, m) { } function overrideChains(obj, keyName, m) { - if (m.chainWatchers === undefined || m.chainWatchers.src !== obj) { + if (m.chainWatchers === undefined || m.chainWatchers.obj !== obj) { return; } m.chainWatchers.revalidate(keyName);