mobx-keystone-mindreframer
Version:
A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more
20 lines (15 loc) • 609 B
text/typescript
import { fromSnapshot } from "../../snapshot/fromSnapshot"
import { getSnapshot } from "../../snapshot/getSnapshot"
import { isTweakedObject } from "../../tweaker/core"
import { ActionCallArgumentSerializer, cannotSerialize } from "./core"
export const objectSnapshotSerializer: ActionCallArgumentSerializer<object, object> = {
id: "mobx-keystone/objectSnapshot",
serialize(value) {
if (typeof value !== "object" || value === null || !isTweakedObject(value, false))
return cannotSerialize
return getSnapshot(value)
},
deserialize(snapshot) {
return fromSnapshot(snapshot)
},
}