Function
destroy (destroyable) public
Defined in packages/@ember/destroyable/index.ts:103
import { destroy } from '@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.
1 2 3 4 5 6 7 8 9 |
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.