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

@computed chains not compatible with native arrays #20386

Open
runspired opened this issue Feb 26, 2023 · 0 comments · Fixed by emberjs/data#8432
Open

@computed chains not compatible with native arrays #20386

runspired opened this issue Feb 26, 2023 · 0 comments · Fixed by emberjs/data#8432

Comments

@runspired
Copy link
Contributor

Priority: high
Affects: emberjs/rfcs#848
Affects: ember-data 4.8+
Affects: all array computed macros (filterBy sortBy mapBy etc.)
Related: emberjs/data#8431
Related: emberjs/data#8411

The current implementation of computed chains (field.@each.key, field.length, field.[]) is not compatible with tracked properties and native arrays when prototype extensions are not present.

This is due to the presumed existence on all arrays of the [] tag. For instance, when building the chain tags for field.@each.key the [] tag is what is entangled for the array, not length.

// Push the tag for the array length itself
chainTags.push(tagForProperty(current, '[]', true, currentTagMeta));

The result is that computed chains will not work when field is a native array without prototype extensions, nor will they work when field is a Proxy to a native array (as all EmberData arrays are).

Note that its not enough to define a '[]' getter on the native array or native array proxy that consumes a tag, as the tag will not be the same tag accessed via tagForProperty(iterable, '[]').

{{#each}}

This design issue also affects the implementation of {{#each}} which targets entanglement with [], although from experience it appears each will recalculate due to access of other tracked properties during iteration whereas computed will not because we specifically untrack computed and add back in only the specific chain tags.

consumeTag(tagForProperty(iterable, '[]'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant