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

34 lines (33 loc) 1.27 kB
import { RefIdResolver, RefOnResolvedValueChange } from './core'; import { RefConstructor } from './Ref'; /** * Custom reference options. */ export interface RootRefOptions<T extends object> { /** * Must return the ID associated to the given target object, or `undefined` if it has no ID. * If not provided it will try to get the reference id from the model `getRefId()` method. * * @param target Target object. */ getId?: RefIdResolver; /** * What should happen when the resolved value changes. * * @param ref Reference object. * @param newValue New resolved value. * @param oldValue Old resolved value. */ onResolvedValueChange?: RefOnResolvedValueChange<T>; } /** * Creates a root ref to an object, which in its snapshot form has an id. * A root ref will only be able to resolve references as long as both the Ref * and the referenced object share a common root. * * @template T Target object type. * @param modelTypeId Unique model type id. * @param [options] Root reference options. * @returns A function that allows you to construct that type of root reference. */ export declare const rootRef: <T extends object>(modelTypeId: string, options?: RootRefOptions<T>) => RefConstructor<T>;