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

API to properly dispose objects #545

Closed
chancancode opened this issue Sep 20, 2019 · 8 comments
Closed

API to properly dispose objects #545

chancancode opened this issue Sep 20, 2019 · 8 comments

Comments

@chancancode
Copy link
Member

chancancode commented Sep 20, 2019

@ember/object should provide the following APIs:

function isDestroying(obj: object): boolean; // same as isDestroying on Ember.Object
function isDestroyed(obj: object): boolean; // same as isDestroyed on Ember.Object
function onBeforeDestroy<T extends object>(obj: T, callback: (obj: T) => void); // same as willDestroy() on Ember.Object
function destroy(obj: object): void; // same as destroy() on Ember.Object

This is required for objects that doesn't inherit from Ember.Object (e.g. Glimmer Components, other native classes) to participate in the destruction protocol (dispose of the "meta", etc).

@NullVoxPopuli
Copy link
Contributor

Just there be a TS interface that is like C#'s IDisposable?

Copy link
Member

rwjblue commented Sep 20, 2019

Seems good, both ember-lifeline and ember-concurrency could use (and want) this functionality.

@chriskrycho
Copy link
Contributor

@NullVoxPopuli the point here (if I'm reading @chancancode's suggestion correctly) is that you don't have to require the object itself to implement all of that interface. That keeps the API surface of the various classes smaller.

@chancancode
Copy link
Member Author

Right, or rather, we would provided functions that could be used on any objects, rather than making the objects implement anything. Think Ember.get() vs EmberObject.prototype.get().

@rwjblue
Copy link
Member

rwjblue commented Sep 20, 2019

Ya, exactly. This is roughly akin to the registerDisposable in ember-lifeline (and Ember would implement the runDisposable concept.

@rwjblue
Copy link
Member

rwjblue commented Sep 20, 2019

See an earlier proposal of this here emberjs/ember.js#14602.

@sandstrom
Copy link
Contributor

Can we close this?

#580

@NullVoxPopuli
Copy link
Contributor

@locks, I think we can close this issue, because @ember/destroyable has landed

@wagenet wagenet closed this as completed Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants