import { State } from "../state.js"; //#region src/field/ref.d.ts declare namespace ref { type Map = (this: T, key: State.Field & string, state: T) => R; type Callback = (argument: T) => ((next: T | null) => void) | Promise | void | boolean; /** Callable ref that also exposes ref-object properties. */ interface Object { /** Set the current value of this reference. */ (value: T | null): void; /** Current value held by this reference. */ current: T; /** State instance this reference belongs to. */ is: State; /** Key of property on state this reference belongs to. */ key: string; /** * Subscribe to changes of this reference. * * @param callback - Callback to invoke with the current value when it changes. * @returns Unsubscribe function to stop listening to changes. */ get(callback: (value: T) => void): () => void; /** Retrieve current value. */ get(): T | null; } /** Object with references to all managed values of `T`. */ type Proxy = { [P in State.Field]-?: Object } & { get(): T; }; type CustomProxy = { [P in State.Field]-?: R } & { get(): T; }; } /** * Creates an object with references to all managed values. * Each property is a function to set value in state when invoked. * * *Properties are simultaneously a ref-function and ref-object, use as needed.* * * Non-enumerable; excluded from snapshots and `ref(this)`. * * @param state - Source state from which to reference values. */ declare function ref(state: T): ref.Proxy; /** * Creates an object with values based on managed values. * Each property will invoke map function on first access supply * the its return value going forward. * * Non-enumerable; excluded from snapshots and `ref(this)`. * * @param state - Source state from which to reference values. * @param map - Function producing the placeholder value for any given property. */ declare function ref(state: T, map: ref.Map): ref.CustomProxy; /** * Creates a ref-compatible property. * Callable to set the value, with ref-object properties for reading and subscribing. * * Non-enumerable; excluded from snapshots and `ref(this)`. * * @param callback - Optional callback to synchronously fire when reference is first set or does update. */ declare function ref(callback?: ref.Callback): ref.Object; /** * Creates a ref-compatible property. * Callable to set the value, with ref-object properties for reading and subscribing. * * Non-enumerable; excluded from snapshots and `ref(this)`. * * @param callback - Optional callback to synchronously fire when reference is first set or does update. * @param ignoreNull - Default `true`. If `false`, will still callback with `null`. */ declare function ref(callback: ref.Callback, ignoreNull: boolean): ref.Object; //#endregion export { ref }; //# sourceMappingURL=ref.d.ts.map