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] Fixes alias chaining when tracked is enabled #18073

Merged
merged 1 commit into from
Jun 5, 2019
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
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');
}
}
);