mobx-keystone
Version:
A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more
23 lines (22 loc) • 1.16 kB
TypeScript
/**
* 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.
*
* @param target Function that returns the object whose children should be tracked.
* @param fn Callback called when a child is attached to the target object.
* @param [options]
* @returns
*/
export declare function onChildAttachedTo(target: () => object, fn: (child: object) => (() => void) | void, options?: {
deep?: boolean;
fireForCurrentChildren?: boolean;
}): (runDetachDisposers: boolean) => void;