Skip to content

Commit

Permalink
fix test, fix typo in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisselden committed Dec 6, 2016
1 parent 5d64229 commit f3d0a85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
37 changes: 20 additions & 17 deletions packages/ember-metal/lib/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,36 @@ AliasedProperty.prototype = Object.create(Descriptor.prototype);

AliasedProperty.prototype.setup = function(obj, keyName) {
assert(`Setting alias '${keyName}' on self`, this.altKey !== keyName);
let meta = metaFor(obj);
if (meta.peekWatching(keyName)) {
addDependentKeys(this, obj, keyName, meta);
let m = metaFor(obj);
if (m.peekWatching(keyName)) {
addDependentKeys(this, obj, keyName, m);
}
};

AliasedProperty.prototype._addDependentKeyIfMissing = function(obj, keyName) {
let meta = metaFor(obj);
if (!meta.peekDeps(this.altKey, keyName)) {
addDependentKeys(this, obj, keyName, meta);
AliasedProperty.prototype.teardown = function(obj, keyName) {
let m = metaFor(obj);
if (m.peekWatching(keyName)) {
removeDependentKeys(this, obj, keyName, m);
}
};

AliasedProperty.prototype._removeDependentKeyIfAdded = function(obj, keyName) {
let meta = metaFor(obj);
if (meta.peekDeps(this.altKey, keyName)) {
removeDependentKeys(this, obj, keyName, meta);
}
AliasedProperty.prototype.willWatch = function(obj, keyName) {
addDependentKeys(this, obj, keyName, metaFor(obj));
};

AliasedProperty.prototype.willWatch = AliasedProperty.prototype._addDependentKeyIfMissing;
AliasedProperty.prototype.didUnwatch = AliasedProperty.prototype._removeDependentKeyIfAdded;
AliasedProperty.prototype.teardown = AliasedProperty.prototype._removeDependentKeyIfAdded;
AliasedProperty.prototype.didUnwatch = function(obj, keyName) {
removeDependentKeys(this, obj, keyName, metaFor(obj));
};

AliasedProperty.prototype.get = function AliasedProperty_get(obj, keyName) {
this._addDependentKeyIfMissing(obj, keyName);
const CONSUMED = {};

AliasedProperty.prototype.get = function AliasedProperty_get(obj, keyName) {
let meta = metaFor(obj);
let cache = meta.writableCache();
if (cache[keyName] !== CONSUMED) {
cache[keyName] = CONSUMED;
addDependentKeys(this, obj, keyName, meta);
}
return get(obj, this.altKey);
};

Expand Down
3 changes: 1 addition & 2 deletions packages/ember-metal/tests/watching/watch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,12 @@ testBoth('PROPERTY_DID_CHANGE + alias + cp', function(get, set) {
}
}));


ok(!isWatching(obj, 'child.cost'), 'precond alias target `child.cost` is not watched');
equal(get(obj, 'cost'), undefined);
// this is how PROPERTY_DID_CHANGE will get notified
ok(isWatching(obj, 'child.cost'), 'alias target `child.cost` is watched after consumption');

ok(!isWatching(obj, 'child.tax'), 'precond alias target `child.cost` is not watched');
ok(!isWatching(obj, 'child.tax'), 'precond alias target `child.tax` is not watched');
equal(get(obj, 'tax'), undefined);
// this is how PROPERTY_DID_CHANGE will get notified
ok(isWatching(obj, 'child.tax'), 'alias target `child.cost` is watched after consumption');
Expand Down

0 comments on commit f3d0a85

Please sign in to comment.