Function

destroy (destroyable) public

Module: @ember/destroyable
destroyable
Object|Function
the object to destroy

Initiates the destruction of a destroyable object. It runs all associated destructors, and then destroys all children recursively.

let obj = {};

registerDestructor(obj, () => console.log('destroyed!'));

destroy(obj); // this will schedule the destructor to be called

// ...some time later, during scheduled destruction

// destroyed!

Destruction via destroy() follows these steps:

1, Mark the destroyable such that isDestroying(destroyable) returns true 2, Call destroy() on each of the destroyable's associated children 3, Schedule calling the destroyable's destructors 4, Schedule setting destroyable such that isDestroyed(destroyable) returns true

This results in the entire tree of destroyables being first marked as destroying, then having all of their destructors called, and finally all being marked as isDestroyed. There won't be any in between states where some items are marked as isDestroying while destroying, while others are not.

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fdestroyable/destroy