machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
691 stars 157 forks source link

v2: Ensure encapsulated task state can be accessed on the TaskInstance #381

Closed maxfierke closed 3 years ago

maxfierke commented 3 years ago

During the re-implementation of encapsulated tasks for v2, I made a few errors:

This addresses both by moving the encapsulated task state instantiation to the same time as when the TaskInstance is created and performed, and allows us to wrap that same TaskInstance and forward non-existing property gets to the encapsulated task state. This is slightly different than v1, which used the EmberObject mixin system to mixin the encapsulated task into a new class definition. Mixins aren't functionality available to us with native classes, but instead the Proxy provides a safer way to do it by not allowing overriding of Task or TaskInstance internals.

Caveats: this does use Proxy and WeakMap for supporting reads of the encapsulated task state via the TaskInstance. However, Proxy and WeakMap are both at ~95% support on caniuse, so it seems pretty safe. Should work fine w/ the existing polyfills out there too, if needed.