From 149f11cd3441d608f6bb6a0c7d1b473c92ea9dc1 Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Tue, 4 Jun 2019 17:02:11 -0700 Subject: [PATCH] [BUGFIX] Fixes alias chaining when tracked is enabled --- .../@ember/-internals/metal/lib/chain-tags.ts | 2 +- .../-internals/metal/tests/alias_test.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/metal/lib/chain-tags.ts b/packages/@ember/-internals/metal/lib/chain-tags.ts index b048d817a93..7ec44e1700e 100644 --- a/packages/@ember/-internals/metal/lib/chain-tags.ts +++ b/packages/@ember/-internals/metal/lib/chain-tags.ts @@ -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); diff --git a/packages/@ember/-internals/metal/tests/alias_test.js b/packages/@ember/-internals/metal/tests/alias_test.js index a7d624ad993..5d2eb2cdf94 100644 --- a/packages/@ember/-internals/metal/tests/alias_test.js +++ b/packages/@ember/-internals/metal/tests/alias_test.js @@ -1,5 +1,6 @@ import { alias, + computed, defineProperty, get, set, @@ -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'); + } } );