disposeOwner
Disposes an owner and everything below it: children first, newest first, then each node's cleanups, newest first.
Disposes an owner and everything below it: children first, newest first, then each node's
cleanups, newest first. Use it to end an owner made with createOwner; disposing an owner that is
already disposed does nothing. Exported from @shadow-js/core/extend as disposeOwner.
Cleanups run in an implicit batch (O-3): effects that depend on signals a cleanup wrote are flushed before this returns, unless the disposal happens inside a computation, a batch or a flush, whose own exit flushes.
Import#
ts
import { disposeOwner } from "@shadow-js/core/extend";
Signature#
ts
function disposeTree(root: Owner): void
Parameters#
| Name | Description |
|---|---|
root |
The owner to dispose, with its whole subtree. |
Throws#
- The error of a cleanup that no error handler caught, once the whole tree is disposed (several such errors are thrown together as an
AggregateError); during a running flush, that flush throws them instead. An error of the flush that follows is thrown as is, or combined with the cleanup errors in anAggregateError.
Examples#
ts
import { addCleanup, createOwner, disposeOwner } from "@shadow-js/core/extend";
const owner = createOwner(null);
addCleanup(owner, () => console.log("released"));
disposeOwner(owner); // logs "released"