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

only invoke didChange if a node is still present. #11558

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
11 changes: 9 additions & 2 deletions packages/ember-metal/lib/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,13 @@ ChainNode.prototype = {

willChange(events) {
var chains = this._chains;
var node;
if (chains) {
for (var key in chains) {
chains[key].willChange(events);
node = chains[key];
if (node !== undefined) {
node.willChange(events);
}
}
}

Expand Down Expand Up @@ -389,7 +393,10 @@ export function finishChains(obj) {
chainNodes = chainWatchers[key];
if (chainNodes) {
for (var i = 0, l = chainNodes.length; i < l; i++) {
chainNodes[i].didChange(null);
var node = chainNodes[i];
if (node) {
node.didChange(null);
}
}
}
}
Expand Down
54 changes: 53 additions & 1 deletion packages/ember-metal/tests/chains_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { addObserver } from 'ember-metal/observer';
import { get } from 'ember-metal/property_get';
import { finishChains } from 'ember-metal/chains';

import { defineProperty } from 'ember-metal/properties';
import computed from 'ember-metal/computed';
import { propertyDidChange } from 'ember-metal/property_events';
QUnit.module('Chains');

QUnit.test('finishChains should properly copy chains from prototypes to instances', function() {
Expand All @@ -14,3 +17,52 @@ QUnit.test('finishChains should properly copy chains from prototypes to instance

ok(obj['__ember_meta__'].chains !== childObj['__ember_meta__'].chains, 'The chains object is copied');
});


QUnit.test('observer and CP chains', function() {
var obj = { };

defineProperty(obj, 'foo', computed('qux.[]', function() { }));
defineProperty(obj, 'qux', computed(function() { }));

// create DK chains
get(obj, 'foo');

// create observer chain
addObserver(obj, 'qux.length', function() { });

/*
+-----+
| qux | root CP
+-----+
^
+------+-----+
| |
+--------+ +----+
| length | | [] | chainWatchers
+--------+ +----+
observer CP(foo, 'qux.[]')
*/


// invalidate qux
propertyDidChange(obj, 'qux');

// CP chain is blown away

/*
+-----+
| qux | root CP
+-----+
^
+------+xxxxxx
| x
+--------+ xxxxxx
| length | x [] x chainWatchers
+--------+ xxxxxx
observer CP(foo, 'qux.[]')
*/

get(obj, 'qux'); // CP chain re-recreated
ok(true, 'no crash');
});