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 Parameter | Default type | Description |
|---|---|---|
T | any | Type of the values it handles. |
J extends JsonValue | undefined | any | Type 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
| Parameter | Type | Description |
|---|---|---|
value | object | The call's target. |
ctx | EncodeContext | Encoding context. |
Returns
boolean
decode()
decode(json, ctx): T;
Decodes a payload back into a value. Use ctx.decode(child) for nested values.
Parameters
| Parameter | Type | Description |
|---|---|---|
json | J | The payload (v). |
ctx | DecodeContext | Decoding context. |
Returns
T
The decoded value.
encode()
encode(value, ctx): J;
Encodes a value is accepted. Use ctx.encode(child) for nested values.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | T | Value to encode. |
ctx | EncodeContext | Encoding context. |
Returns
J
The payload (v), or undefined to carry none.
is()
is(value, ctx): value is T;
Whether this serializer encodes value.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | Value to check. |
ctx | EncodeContext | Encoding context; ctx.root is the tree the value is encoded against. |
Returns
value is T