Skip to main content

Interface: ValueSerializer<T, J>

Handles one kind of value: encodes it as { "$mobxKeystone": tag, "v": payload } and decodes it back. createSerializer composes a list of them into a Serializer.

Type Parameters​

Type ParameterDefault typeDescription
TanyType of the values it handles.
J extends JsonValue | undefinedanyType of the encoded payload (undefined to carry none).

Properties​

tag​

readonly tag: string;

Unique, e.g. "geom/Polygon"; the $mobxKeystone of the encoded value.

Methods​

claimsTarget()?​

optional claimsTarget(value, ctx): boolean;

Only for reference serializers: whether this serializer references value, a node of the tree, when it is a call's target. Unlike is, it ignores options such as when, since the call must run on the node itself. A call's target goes through the first serializer whose claimsTarget accepts it (else as a pathRef), and only serializers with claimsTarget decode it.

Parameters​

ParameterTypeDescription
valueobjectThe call's target.
ctxEncodeContextEncoding context.

Returns​

boolean


decode()​

decode(json, ctx): T;

Decodes a payload back into a value. Use ctx.decode(child) for nested values.

Parameters​

ParameterTypeDescription
jsonJThe payload (v).
ctxDecodeContextDecoding context.

Returns​

T

The decoded value.


encode()​

encode(value, ctx): J;

Encodes a value is accepted. Use ctx.encode(child) for nested values.

Parameters​

ParameterTypeDescription
valueTValue to encode.
ctxEncodeContextEncoding context.

Returns​

J

The payload (v), or undefined to carry none.


is()​

is(value, ctx): value is T;

Whether this serializer encodes value.

Parameters​

ParameterTypeDescription
valueunknownValue to check.
ctxEncodeContextEncoding context; ctx.root is the tree the value is encoded against.

Returns​

value is T