Owner (@shadow-js/core/extend)
A node in the ownership tree: it owns the effects, memos and owners created under it, their cleanups and error handlers, and disposes them together. (Owner of @shadow-js/core/extend)
A node in the ownership tree: it owns the effects, memos and owners created under it, their
cleanups and error handlers, and disposes them together. Create one with createOwner and end it
with disposeOwner; the class is exported for instanceof checks and for reading its state.
Computations (ComputationNode) are owners too. Children are a doubly linked list so detaching one
is O(1); disposal walks the tree iteratively because its depth is user controlled (R-CODE-11).
Import#
ts
import { Owner } from "@shadow-js/core/extend";
Signature#
ts
class Owner
Members#
| Name | Type | Description |
|---|---|---|
parent |
parent: Owner | null |
The owner this node was created under, or null for a root. Kept after disposal. |
lastChild |
lastChild: Owner | null |
The newest child that is still alive, or null when there is none. |
prevSibling |
prevSibling: Owner | null |
The next older sibling that is still alive, or null. |
nextSibling |
nextSibling: Owner | null |
The next newer sibling that is still alive, or null. |
cleanups |
cleanups: Cleanup | Cleanup[] | null |
The cleanups registered with addCleanup or onCleanup: null for none, a function for one, an array (oldest first) for several. Emptied when they run. |
context |
context: ContextMap | null |
The context values this node sees: inherited from the parent at creation, null for a root. |
errorHandlers |
errorHandlers: ErrorHandler[] | null |
The handlers registered with onError or catchError, oldest first (they are tried newest first), or null for none. A computation clears them before each run. |
childCount |
childCount |
Number of children ever created; gives each child a stable index for useId(). |
idCount |
idCount |
Number of ids useId() has handed out from this owner. |
index |
index: number |
Position among the parent's children, assigned at creation. |
depth |
depth: number |
Distance from the root: 0 for a root, the parent's depth plus one otherwise. |
idPrefix |
idPrefix: string | undefined |
The hydration-scope prefix of a component's owner, set by the renderer. When present, useId() builds the ids below it from this prefix instead of the owner path. |
disposed |
disposed |
True once the node has been disposed. |
gate |
gate: (() => boolean) | null |
While this returns true, user effects (and onMount) created below this owner wait: they do not run until it returns false for the first time. Suspense sets it so the effects of content that is still loading are held back. The read is tracked. |
pauses |
pauses |
Number of pauses (Activity hidden) that cover this node. Inherited at creation, and changed for a whole subtree by pauseOwner/resumeOwner. Above zero, effects wait and memos keep their value. |
disposeSelf |
disposeSelf(): void |
Disposes this node only (children must already be gone). |
runCleanups |
runCleanups(): void |
Runs own cleanups newest first, untracked, isolating failures. |
Examples#
ts
import { createOwner, disposeOwner, Owner } from "@shadow-js/core/extend";
const owner = createOwner(null);
console.log(owner instanceof Owner, owner.depth); // true 0
disposeOwner(owner);
console.log(owner.disposed); // true