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 lts] Ensure aliases are bootstrapped when using @each, #19279 #19280

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
9 changes: 9 additions & 0 deletions packages/@ember/-internals/metal/lib/chain-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ function getChainTags(
);

chainTags.push(tagForProperty(item, segment, true));

currentMeta = peekMeta(item);
descriptor = currentMeta !== null ? currentMeta.peekDescriptors(segment) : undefined;

// If the key is an alias, we need to bootstrap it
if (descriptor !== undefined && typeof descriptor.altKey === 'string') {
// tslint:disable-next-line: no-unused-expression
item[segment];
}
}
}

Expand Down
23 changes: 22 additions & 1 deletion packages/@ember/-internals/metal/tests/alias_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
removeObserver,
tagForProperty,
} from '..';
import { Object as EmberObject } from '@ember/-internals/runtime';
import { Object as EmberObject, A } from '@ember/-internals/runtime';
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
import { destroy } from '@glimmer/runtime';
import { valueForTag, validateTag } from '@glimmer/validator';
Expand Down Expand Up @@ -68,6 +68,27 @@ moduleFor(
assert.equal(count, 1);
}

['@test nested aliases should trigger computed property invalidation [GH#19279]'](assert) {
let AttributeModel = EmberObject.extend({
countAdditives: alias('additives.length'),
additives: A(),
});

let RootModel = EmberObject.extend({
allAdditives: computed('metaAttributes.@each.countAdditives', function () {
return this.metaAttributes.reduce((acc, el) => {
return acc.concat(el.additives);
}, []);
}),
metaAttributes: A([AttributeModel.create()]),
});

let model = RootModel.create();
assert.equal(model.allAdditives.length, 0);
model.metaAttributes[0].additives.pushObject('foo');
assert.equal(model.allAdditives.length, 1);
}

async [`@test inheriting an observer of the alias from the prototype then
redefining the alias on the instance to another property dependent on same key
does not call the observer twice`](assert) {
Expand Down