Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Generic track by annotation for any component bindings #15647

@Aaron-Pool

Description

@Aaron-Pool

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

In component bindings, $onChanges is only triggered if an object reference changes. You can also use $doCheck, but it is, in my opinion, more complex than necessary for the average non-object-reference dirty-check for a component binding. It would also be nice to be able to specify in the parent template what you consider to make a binding "dirty" as opposed to only once in the component definition.

What is the expected behavior?

<my-component
    // normal binding, watches object reference for dirty check
    binding1="model1"
    // But here I have a value field on the model object, and instead of comparing the object reference of my model here, I want you to check this expression value when checking for dirtiness
    binding2="model2 track by model2.value"
></my-component>

What is the motivation / use case for changing the behavior?

Again, I think that $doCheck is overkill for a lot of the times I want to have an identifier field on a binding, but I'm also pretty tired of doing a shallow clone to change an object reference, because, while efficient, it isn't intuitive to people reading code. People are familiar with the track by method, do to ng-repeat, so it seems like this would be an intuitive change. It would also add a GREAT deal of readability to code, in my opinion. This could also, obviously, be accomplished with $scope.$watch, but that encourages the poor habit of regularly injecting and using $scope

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions