Skip to main content

Function: onChildAttachedTo()

function onChildAttachedTo(
target,
fn,
options?
): (runDetachDisposers) => void;

Runs a callback everytime a new object is attached to a given node. The callback can optionally return a disposer which will be run when the child is detached.

The optional options parameter accepts an object with the following options:

  • deep: boolean (default: false) - true if the callback should be run for all children deeply or false if it it should only run for shallow children.
  • fireForCurrentChildren: boolean (default: true) - true if the callback should be immediately called for currently attached children, false if only for future attachments.

Returns a disposer, which has a boolean parameter which should be true if pending detachment callbacks should be run or false otherwise.

Parameters​

ParameterTypeDescription
target() => objectFunction that returns the object whose children should be tracked.
fn(child) => void | (() => void)Callback called when a child is attached to the target object.
options?{ deep?: boolean; fireForCurrentChildren?: boolean; }-
options.deep?boolean-
options.fireForCurrentChildren?boolean-

Returns​

(runDetachDisposers) => void