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

[v2] Use @tracked underneath on Ember 3.16+ #354

Merged
merged 7 commits into from
Sep 4, 2020
Merged

Conversation

maxfierke
Copy link
Collaborator

@maxfierke maxfierke commented Apr 22, 2020

This is a PR to use @tracked for Task and TaskInstance state on Ember 3.16+ to enable use without using @computed when consuming derived state.

In Ember < 3.16, e-c behaves as it currently does requiring @computed to track task-derived state changes.

This PR essentially replaces the state properties on the Ember implementations of Task and TaskInstance with those properties decorated with @tracked (done dynamically, though w/ property descriptors. not redefining them with actual decorator syntax, so there's no dependency on decorator transforms.) This incurs a little bit of a cost, since it's redefining the properties, but practically shouldn't have much effect since it's applied to the Task and TaskInstance prototypes, rather than every instance, so it would only be incurred once.

There's a few outstanding issues/open questions with this:

  • The no-render-breaking tests are triggering re-render assertions (one of them might technically be a "correct" failure.) Fixed
    • Seems that setProperties reads the properties it sets, consuming the tag and leading to the error when setting @tracked properties. I think this can be worked around by using Object.assign instead.
    • performCount needs to be read to be updated. Seems this is fine in some contexts, but not others? (i.e. not in the case in one of the tests) Tracked internally as _performCount and used for reads to ensure write-only to tracked performCount
  • How does this work for add-ons that depend on ember-concurrency and support multiple Ember versions?
    • They'll still need to use @computed if they consume ember-concurrency state and support < 3.16. However, @computed Just Works™ with the tracked state, it seems.

Within applications with both tracked & computed properties, if using a native getter to access task state, and wishing to use it alongside a computed property, @dependantKeyCompat will need to be used on the getter as expected with any other tracked-prop using getter.

I'd expect there are probably other edge-cases with this as well.

Resolves #343

@maxfierke maxfierke changed the title [v2] WIP: Use @tracked underneath on Ember 3.16+ [v2] Use @tracked underneath on Ember 3.16+ Aug 14, 2020
No more `@computed` required to read derived state from
Tasks and TaskInstances.
setProperties will consume the tag on initial reads (to read the initializer value)
which causes the following set to fail, even if the property hasn't _really_ been
read yet (by anything user-side.) Instead, we can avoid altogether and just use
native Object.assign, which won't read & consume the property before setting.
@maxfierke maxfierke marked this pull request as ready for review August 17, 2020 05:09
@maxfierke maxfierke requested a review from machty August 17, 2020 05:09
@maxfierke maxfierke added ember-octane Issues related to use with Ember "Octane" Edition enhancement labels Aug 17, 2020
Case Number 483092 of forgetting about task groups
This'll put it on the microtask queue on modern Ember, which is what we expect
@maxfierke maxfierke merged commit 4529391 into v2 Sep 4, 2020
@maxfierke maxfierke deleted the mf-v2_tracked_interop branch September 29, 2020 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ember-octane Issues related to use with Ember "Octane" Edition enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant