mobx-keystone
Version:
A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more
85 lines (84 loc) • 3.49 kB
TypeScript
import { ActionCall } from '../../action/applyAction';
import { JSONPrimitiveValue } from '../../utils/types';
import { ActionCallArgumentSerializer } from './core';
/**
* Registers a new action call argument serializers.
* Serializers are called in the inverse order they are registered, meaning the
* latest one registered will be called first.
*
* @param serializer Serializer to register.
* @returns A disposer to unregister the serializer.
*/
export declare function registerActionCallArgumentSerializer(serializer: ActionCallArgumentSerializer<any, any>): () => void;
/**
* Serialized action call argument.
*/
export interface SerializedActionCallArgument {
/**
* Serializer id.
*/
readonly $mobxKeystoneSerializer: string;
/**
* Serialized value.
*/
readonly value: any;
}
/**
* A serialized action call.
*/
export interface SerializedActionCall extends Omit<ActionCall, "serialized"> {
/**
* Serialized action arguments.
*/
readonly args: ReadonlyArray<SerializedActionCallArgument | JSONPrimitiveValue>;
/**
* Marks this action call as serialized.
*/
serialized: true;
}
/**
* Transforms an action call argument by returning a `SerializedActionCallArgument`.
* The following are supported out of the box:
* - Primitives.
* - Nodes that are under the same root node as the target root (when provided) will be serialized
* as a path.
* - Nodes that are not under the same root node as the target root will be serialized as their snapshot.
* - Arrays (observable or not).
* - Dates.
* - Maps (observable or not).
* - Sets (observable or not).
* - Plain objects (observable or not).
*
* If the value cannot be serialized it will throw an exception.
*
* @param argValue Argument value to be transformed into its serializable form.
* @param [targetRoot] Target root node of the model where this action is being performed.
* @returns The serializable form of the passed value.
*/
export declare function serializeActionCallArgument(argValue: any, targetRoot?: object): SerializedActionCallArgument | JSONPrimitiveValue;
/**
* Ensures that an action call is serializable by mapping the action arguments into its
* serializable version by using `serializeActionCallArgument`.
*
* @param actionCall Action call to convert.
* @param [targetRoot] Target root node of the model where this action is being performed.
* @returns The serializable action call.
*/
export declare function serializeActionCall(actionCall: ActionCall, targetRoot?: object): SerializedActionCall;
/**
* Transforms an action call argument by returning its deserialized equivalent.
*
* @param argValue Argument value to be transformed into its deserialized form.
* @param [targetRoot] Target root node of the model where this action is being performed.
* @returns The deserialized form of the passed value.
*/
export declare function deserializeActionCallArgument(argValue: SerializedActionCallArgument | JSONPrimitiveValue, targetRoot?: object): any;
/**
* Ensures that an action call is deserialized by mapping the action arguments into its
* deserialized version by using `deserializeActionCallArgument`.
*
* @param actionCall Action call to convert.
* @param [targetRoot] Target root node of the model where this action is being performed.
* @returns The deserialized action call.
*/
export declare function deserializeActionCall(actionCall: SerializedActionCall, targetRoot?: object): ActionCall;