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

DEV: Introduce @dedupeTracked #27084

Merged
merged 2 commits into from
May 20, 2024
Merged

DEV: Introduce @dedupeTracked #27084

merged 2 commits into from
May 20, 2024

Conversation

davidtaylorhq
Copy link
Member

@davidtaylorhq davidtaylorhq commented May 20, 2024

Same as @tracked, but skips notifying consumers if the value is unchanged. This introduces some performance overhead, so should only be used where excessive downstream re-evaluations are a problem.

This is loosely based on @dedupeTracked in the tracked-toolbox package, but without the added complexity of a customizable 'comparator'. Implementing ourselves also avoids the need for pulling in the entire package, which contains some tools which we don't want, or which are now implemented in Ember/Glimmer (e.g. @cached).

Same as `@tracked`, but skips notifying consumers if the value is unchanged. This introduces some performance overhead, so should only be used where excessive downstream re-evaluations are a problem.

This is loosely based on `@dedupeTracked` in the `tracked-toolbox` package, but without the added complexity of a customizable 'comparator'. Implementing ourselves also avoids the need for pulling in the entire package, which contains some tools which we don't want, or which are now implemented in Ember/Glimmer (e.g. `@cached`).
Comment on lines 27 to 31
await render(<template>
<span id="initials">{{pet.initials}}</span>
</template>);

assert.dom("#initials").hasText("SD", "Initials are correct");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is rendering a template necessary to this test? 😃

Suggested change
await render(<template>
<span id="initials">{{pet.initials}}</span>
</template>);
assert.dom("#initials").hasText("SD", "Initials are correct");
assert.strictEqual(pet.initials, "SD", "Initials are correct");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... we need some way to know whether downstream autotracking is being notified of a change. Rendering is one way to do that. But perhaps we get the same effect by using @cached on the getter. Lemme try 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that's much cleaner with @cached. Thanks @CvX!

@davidtaylorhq davidtaylorhq merged commit 23b02a3 into main May 20, 2024
15 of 16 checks passed
@davidtaylorhq davidtaylorhq deleted the dedupe-tracked branch May 20, 2024 14:59
CvX pushed a commit that referenced this pull request May 21, 2024
Same as `@tracked`, but skips notifying consumers if the value is unchanged. This introduces some performance overhead, so should only be used where excessive downstream re-evaluations are a problem.

This is loosely based on `@dedupeTracked` in the `tracked-toolbox` package, but without the added complexity of a customizable 'comparator'. Implementing ourselves also avoids the need for pulling in the entire package, which contains some tools which we don't want, or which are now implemented in Ember/Glimmer (e.g. `@cached`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants