UNPKG

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

19 lines (14 loc) 553 B
import type { IObservableArray } from "mobx" import { isArray } from "../../utils" import { ActionCallArgumentSerializer, cannotSerialize } from "./core" export const arraySerializer: ActionCallArgumentSerializer<any[] | IObservableArray<any>, any[]> = { id: "mobx-keystone/array", serialize(value, serialize) { if (!isArray(value)) return cannotSerialize // this will also transform observable arrays into non-observable ones return value.map(serialize) }, deserialize(arr, deserialize) { return arr.map(deserialize) }, }