import { Collection, NonFunctionPropNames } from "../../types/HelperTypes.js"; import type { IRef, Ref } from "../../encoder/ChangeTree.js"; import { Decoder } from "../Decoder.js"; import { DataChange } from "../DecodeOperation.js"; import { OPERATION } from "../../encoding/spec.js"; import { Schema } from "../../Schema.js"; import { $refId } from "../../types/symbols.js"; import { MapSchema } from "../../types/custom/MapSchema.js"; import { ArraySchema } from "../../types/custom/ArraySchema.js"; import { type SchemaCallbackProxy } from "./getDecoderStateCallbacks.js"; type PropertyChangeCallback = (currentValue: K, previousValue: K) => void; type KeyValueCallback = (key: K, value: V) => void; type ValueKeyCallback = (value: V, key: K) => void; type InstanceChangeCallback = () => void; type PublicPropNames = Exclude, typeof $refId> & string; type CollectionPropNames = Exclude<{ [K in keyof T]: T[K] extends Collection ? K : never; }[keyof T] & string, typeof $refId>; type CollectionValueType = T[K] extends MapSchema ? V : T[K] extends ArraySchema ? V : T[K] extends Collection ? V : never; type CollectionKeyType = T[K] extends MapSchema ? Key : T[K] extends ArraySchema ? number : T[K] extends Collection ? Key : never; export declare class StateCallbackStrategy { protected decoder: Decoder; protected uniqueRefIds: Set; protected isTriggering: boolean; constructor(decoder: Decoder); protected get callbacks(): { [refId: number]: import("../ReferenceTracker.js").SchemaCallbacks; }; protected get state(): TState; protected addCallback(refId: number, operationOrProperty: OPERATION | string, handler: Function): () => void; protected addCallbackOrWaitCollectionAvailable(instance: TInstance, propertyName: string, operation: OPERATION, handler: Function, immediate?: boolean): () => void; /** * Listen to property changes on the root state. */ listen>(property: K, handler: PropertyChangeCallback, immediate?: boolean): () => void; /** * Listen to property changes on a nested instance. */ listen>(instance: TInstance, property: K, handler: PropertyChangeCallback, immediate?: boolean): () => void; protected listenInstance(instance: TInstance, propertyName: string, handler: PropertyChangeCallback, immediate?: boolean): () => void; /** * Listen to any property change on an instance. */ onChange(instance: TInstance, handler: InstanceChangeCallback): () => void; /** * Listen to item changes in a collection on root state. */ onChange>(property: K, handler: KeyValueCallback, CollectionValueType>): () => void; /** * Listen to item changes in a nested collection. */ onChange>(instance: TInstance, property: K, handler: KeyValueCallback, CollectionValueType>): () => void; /** * Listen to items added to a collection on root state. */ onAdd>(property: K, handler: ValueKeyCallback, CollectionKeyType>, immediate?: boolean): () => void; /** * Listen to items added to a nested collection. */ onAdd>(instance: TInstance, property: K, handler: ValueKeyCallback, CollectionKeyType>, immediate?: boolean): () => void; /** * Listen to items removed from a collection on root state. */ onRemove>(property: K, handler: ValueKeyCallback, CollectionKeyType>): () => void; /** * Listen to items removed from a nested collection. */ onRemove>(instance: TInstance, property: K, handler: ValueKeyCallback, CollectionKeyType>): () => void; /** * Bind properties from a Schema instance to a target object. * Changes will be automatically reflected on the target object. */ bindTo(from: TInstance, to: TTarget, properties?: string[], immediate?: boolean): () => void; protected triggerChanges(allChanges: DataChange[]): void; } /** * Factory class for retrieving the callbacks API. */ export declare const Callbacks: { /** * Get the new callbacks standard API. * * Usage: * ```ts * const callbacks = Callbacks.get(roomOrDecoder); * * // Listen to property changes * callbacks.listen("currentTurn", (currentValue, previousValue) => { ... }); * * // Listen to collection additions * callbacks.onAdd("entities", (entity, sessionId) => { * // Nested property listening * callbacks.listen(entity, "hp", (currentHp, previousHp) => { ... }); * }); * * // Listen to collection removals * callbacks.onRemove("entities", (entity, sessionId) => { ... }); * * // Listen to any property change on an instance * callbacks.onChange(entity, () => { ... }); * * // Bind properties to another object * callbacks.bindTo(player, playerVisual); * ``` * * @param roomOrDecoder - Room or Decoder instance to get the callbacks for. * @returns the new callbacks standard API. */ get(roomOrDecoder: Decoder | { serializer: { decoder: Decoder; }; } | { state: T; serializer: object; }): StateCallbackStrategy; /** * Get the legacy callbacks API. * * We aim to deprecate this API on 1.0, and iterate on improving Callbacks.get() API. * * @param roomOrDecoder - Room or Decoder instance to get the legacy callbacks for. * @returns the legacy callbacks API. */ getLegacy(roomOrDecoder: Decoder | { serializer: { decoder: Decoder; }; } | { state: T; serializer: object; }): SchemaCallbackProxy; getRawChanges(decoder: Decoder, callback: (changes: DataChange[]) => void): void; }; export {};