Skip to content

Commit

Permalink
Merge pull request #18073 from emberjs/bugfix/tracked/fix-alias-chain…
Browse files Browse the repository at this point in the history
…-tagging

[BUGFIX] Fixes alias chaining when tracked is enabled
  • Loading branch information
rwjblue authored Jun 5, 2019
2 parents 25fd482 + 149f11c commit 0e33c7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/chain-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function getChainTagsForKey(obj: any, key: string) {
if (typeof descriptor.altKey === 'string') {
// it's an alias, so just get the altkey without tracking
track(() => {
current = get(obj, descriptor.altKey);
current = get(current, descriptor.altKey);
});
} else {
current = peekCacheFor(current).get(segment);
Expand Down
34 changes: 34 additions & 0 deletions packages/@ember/-internals/metal/tests/alias_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
alias,
computed,
defineProperty,
get,
set,
Expand Down Expand Up @@ -253,5 +254,38 @@ moduleFor(
assert.equal(get(obj, 'bar'), 'FOO');
});
}

['@test nested aliases update their chained dependencies properly'](assert) {
let count = 0;

class Inner {
@alias('pojo') aliased;

pojo = {
value: 123,
};
}

class Outer {
@computed('inner.aliased.value')
get value() {
count++;
return this.inner.aliased.value;
}

inner = new Inner();
}

let outer = new Outer();

assert.equal(outer.value, 123, 'Property works');

outer.value;
assert.equal(count, 1, 'Property was properly cached');

set(outer, 'inner.pojo.value', 456);

assert.equal(outer.value, 456, 'Property was invalidated correctly');
}
}
);

0 comments on commit 0e33c7b

Please sign in to comment.