-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[FEATURE ember-metal-meta-destructors] #14602
Conversation
Introduces a mechanism to add additional work to be done at object / meta destruction time. Example: ```js // app/utils/run-later.js export default function runLater(object, functionOrName, delay) { let cancelId = run.later(object, functionOrName, delay); Ember.meta(object).addDestructor(() => run.cancel(cancelId)); } ``` ```js // some component export default Component.extend({ stuff() { }, actions: { doStuff() { runLater(this, this._stuff, 1000); } } }) ``` When this component is destroyed, the scheduled task will be canceled. A number of popular addons do similar things by monkey patching the objects `willDestroy` at runtime, but that is less than ideal (due to shape changes and whatnot). This provides a mechanism to easily entangle cleanup tasks for objects from utility functions...
Would love review/feedback from folks I know have been working on and around similar issues to my example above. |
Alternatively, wouldn't it be possible to implement destructors using ember-metal's listener APIs and just broadcast a willDestroy event? Then anyone will be able to do |
I think we should go all in on cancellation tokens as the primitive for these things, and I'm hesitant to grow the API surface area instead of doubling down on building a great async story top to bottom. But otherwise, looks good, seems forward compatible. |
@rwjblue I like the idea of cancelling a scheduled task during the destroy phase. Over the past week I've had to add checks for |
☔ The latest upstream changes (presumably #14360) made this pull request unmergeable. Please resolve the merge conflicts. |
Not applicable anymore. |
For those that might stumble across this old PR, this was RFC'ed in emberjs/rfcs#545 |
Introduces a mechanism to add additional work to be done at object / meta destruction time.
Example:
When this component is destroyed, the scheduled task will be canceled. A number of popular addons do similar things by monkey patching the objects
willDestroy
at runtime, but that is less than ideal (due to shape changes and whatnot).This provides a mechanism to easily entangle cleanup tasks for objects from utility functions...