UNPKG

mobx-keystone

Version:

A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more

42 lines (41 loc) 1.64 kB
import { Path } from './pathTypes'; /** * Iterates through all the parents (from the nearest until the root) * until one of them matches the given predicate. * If the predicate is matched it will return the found node. * If none is found it will return undefined. * * @template T Parent object type. * @param child Target object. * @param predicate Function that will be run for every parent of the target object, from immediate parent to the root. * @param maxDepth Max depth, or 0 for infinite. * @returns */ export declare function findParent<T extends object = any>(child: object, predicate: (parentNode: object) => boolean, maxDepth?: number): T | undefined; /** * Result of `findParentPath`. */ export interface FoundParentPath<T extends object> { /** * Found parent object. */ readonly parent: T; /** * Path from the found parent to the child. */ readonly path: Path; } /** * Iterates through all the parents (from the nearest until the root) * until one of them matches the given predicate. * If the predicate is matched it will return the found node plus the * path to get from the parent to the child. * If none is found it will return undefined. * * @template T Parent object type. * @param child Target object. * @param predicate Function that will be run for every parent of the target object, from immediate parent to the root. * @param maxDepth Max depth, or 0 for infinite. * @returns */ export declare function findParentPath<T extends object = any>(child: object, predicate: (parentNode: object) => boolean, maxDepth?: number): FoundParentPath<T> | undefined;