mobx-bonsai
Version:
A fast lightweight alternative to MobX-State-Tree + Y.js two-way binding
27 lines (26 loc) • 1.02 kB
TypeScript
/**
* Mode for the `walkTree` method.
*/
export declare enum WalkTreeMode {
/**
* The walk will be done parent (roots) first, then children.
*/
ParentFirst = "parentFirst",
/**
* The walk will be done children (leafs) first, then parents.
*/
ChildrenFirst = "childrenFirst"
}
/**
* Walks a tree, running the predicate function for each node.
* If the predicate function returns something other than undefined,
* then the walk will be stopped and the function will return the returned value.
*
* @template T Returned node type, defaults to void.
* @param root Subtree root node.
* @param visit Function that will be run for each node of the tree.
* @param mode Mode to walk the tree, as defined in `WalkTreeMode`.
* @returns The value returned by the predicate function that stopped the walk,
* or undefined if the walk was completed.
*/
export declare function walkTree<T = void>(root: object, visit: (node: object) => T | undefined, mode: WalkTreeMode): T | undefined;