Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix beta] cleanup Chains #11536

Merged
merged 1 commit into from
Jun 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions packages/ember-metal/lib/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function isVolatile(obj) {
return !(isObject(obj) && obj.isDescriptor && obj._cacheable);
}

function Chains() {

}

Chains.prototype = Object.create(null);

var pendingQueue = [];

// attempts to add the pendingQueue chains again. If some of them end up
Expand Down Expand Up @@ -46,13 +52,15 @@ function addChainWatcher(obj, keyName, node) {
var nodes = m.chainWatchers;

if (!m.hasOwnProperty('chainWatchers')) { // FIXME?!
nodes = m.chainWatchers = {};
nodes = m.chainWatchers = new Chains();
}

if (!nodes[keyName]) {
nodes[keyName] = [];
nodes[keyName] = [node];
} else {
nodes[keyName].push(node);
}
nodes[keyName].push(node);

watchKey(obj, keyName, m);
}

Expand Down Expand Up @@ -93,6 +101,10 @@ function ChainNode(parent, key, value) {
// the observer on it)
this._watching = (value === undefined);

this._chains = undefined;
this._object = undefined;
this.count = 0;

this._value = value;
this._paths = {};
if (this._watching) {
Expand Down Expand Up @@ -231,19 +243,19 @@ ChainNode.prototype = {
this.unchain(key, path);
},

count: 0,

chain(key, path, src) {
var chains = this._chains;
var node;
if (!chains) {
chains = this._chains = {};
if (chains === undefined) {
chains = this._chains = new Chains();
} else {
node = chains[key];
}

node = chains[key];
if (!node) {
if (node === undefined) {
node = chains[key] = new ChainNode(this, key, src);
}

node.count++; // count chains...

// chain rest of path if there is one
Expand All @@ -268,7 +280,7 @@ ChainNode.prototype = {
// delete node if needed.
node.count--;
if (node.count <= 0) {
delete chains[node._key];
chains[node._key] = undefined;
node.destroy();
}
},
Expand All @@ -277,9 +289,6 @@ ChainNode.prototype = {
var chains = this._chains;
if (chains) {
for (var key in chains) {
if (!chains.hasOwnProperty(key)) {
continue;
}
chains[key].willChange(events);
}
}
Expand Down Expand Up @@ -347,9 +356,6 @@ ChainNode.prototype = {
var chains = this._chains;
if (chains) {
for (var key in chains) {
if (!chains.hasOwnProperty(key)) {
continue;
}
chains[key].didChange(events);
}
}
Expand All @@ -376,10 +382,6 @@ export function finishChains(obj) {
chainWatchers = m.chainWatchers;
if (chainWatchers) {
for (var key in chainWatchers) {
if (!chainWatchers.hasOwnProperty(key)) {
continue;
}

chainNodes = chainWatchers[key];
if (chainNodes) {
for (var i = 0, l = chainNodes.length; i < l; i++) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-metal/lib/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function destroy(obj) {
nodes = node._chains;
if (nodes) {
for (key in nodes) {
if (nodes.hasOwnProperty(key)) {
if (nodes[key] !== undefined) {
NODE_STACK.push(nodes[key]);
}
}
Expand Down