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

21 lines (18 loc) 869 B
import { Frozen, frozen, isFrozenSnapshot } from "../frozen/Frozen" import { registerReconciler } from "./reconcileSnapshot" import type { SnapshotInOfFrozen } from "./SnapshotOf" import { SnapshotterAndReconcilerPriority } from "./SnapshotterAndReconcilerPriority" function reconcileFrozenSnapshot(value: any, sn: SnapshotInOfFrozen<Frozen<any>>): Frozen<any> { // reconciliation is only possible if the target is a Frozen instance with the same data (by ref) // in theory we could compare the JSON representation of both datas or do a deep comparison, but that'd be too slow if (value instanceof Frozen && value.data === sn.data) { return value } return frozen(sn.data) } registerReconciler(SnapshotterAndReconcilerPriority.Frozen, (value, sn) => { if (isFrozenSnapshot(sn)) { return reconcileFrozenSnapshot(value, sn) } return undefined })