Skip to content

@computed chains not compatible with native arrays #20386

@runspired

Description

@runspired

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

The current implementation of computed chains ([email protected], 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 [email protected] 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, '[]'));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions