UNPKG

mobx-keystone-mindreframer

Version:

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

47 lines (46 loc) 2.1 kB
import { ObservableSet } from "mobx"; import { Ref, RefConstructor } from "./Ref"; /** * Reference resolver type. */ export declare type RefResolver<T extends object> = (ref: Ref<T>) => T | undefined; /** * Reference ID resolver type. */ export declare type RefIdResolver = (target: object) => string | undefined; /** * Type for the callback called when a reference resolved value changes. */ export declare type RefOnResolvedValueChange<T extends object> = (ref: Ref<T>, newValue: T | undefined, oldValue: T | undefined) => void; /** * Uses a model `getRefId()` method whenever possible to get a reference ID. * If the model does not have an implementation of that method it returns `undefined`. * If the model has an implementation, but that implementation returns anything other than * a `string` it will throw. * * @param target Target object to get the ID from. * @returns The string ID or `undefined`. */ export declare function getModelRefId(target: object): string | undefined; /** * Resolves a node given its ID. * * @typeparam T Target object type. * @param root Node where to start the search. The search will be done on it and all its children. * @param id ID to search for. * @param getId Function that will be used to get the ID from an object (`getModelRefId` by default). * @returns The node found or `undefined` if none. */ export declare function resolveId<T extends object>(root: object, id: string, getId?: RefIdResolver): T | undefined; /** * Gets all references that resolve to a given object. * * @typeparam T Referenced object type. * @param target Node the references point to. * @param refType Pass it to filter by only references of a given type, or omit / pass `undefined` to get references of any type. * @param options Options. * @returns An observable set with all reference objects that point to the given object. */ export declare function getRefsResolvingTo<T extends object>(target: T, refType?: RefConstructor<T>, options?: { updateAllRefsIfNeeded?: boolean; }): ObservableSet<Ref<T>>;