diff --git a/packages/lib/src/parent/core.ts b/packages/lib/src/parent/core.ts index c91a4397..746f0488 100644 --- a/packages/lib/src/parent/core.ts +++ b/packages/lib/src/parent/core.ts @@ -22,22 +22,26 @@ export function parentPathEquals( return parentPath1.parent === parentPath2.parent && parentPath1.path === parentPath2.path } -function createParentPathAtom(obj: object) { - return getOrCreate(objectParentsAtoms, obj, () => createAtom("parentAtom")) +function createParentPathAtom() { + return createAtom("parentAtom") +} + +function getOrCreateParentPathAtom(obj: object) { + return getOrCreate(objectParentsAtoms, obj, createParentPathAtom) } /** * @internal */ export function reportParentPathObserved(node: object) { - createParentPathAtom(node).reportObserved() + getOrCreateParentPathAtom(node).reportObserved() } /** * @internal */ export function reportParentPathChanged(node: object) { - createParentPathAtom(node).reportChanged() + getOrCreateParentPathAtom(node).reportChanged() } /** diff --git a/packages/lib/src/rootStore/rootStore.ts b/packages/lib/src/rootStore/rootStore.ts index a42068c7..55e2303e 100644 --- a/packages/lib/src/rootStore/rootStore.ts +++ b/packages/lib/src/rootStore/rootStore.ts @@ -7,11 +7,15 @@ import { attachToRootStore, detachFromRootStore } from "./attachDetach" const rootStoreRegistry = new WeakMap() -const getOrCreateRootStoreEntry = (node: object) => - getOrCreate(rootStoreRegistry, node, () => ({ +function createRootStoreEntry() { + return { atom: createAtom("rootStore"), is: false, - })) + } +} + +const getOrCreateRootStoreEntry = (node: object) => + getOrCreate(rootStoreRegistry, node, createRootStoreEntry) /** * Registers a model / tree node object as a root store tree. diff --git a/packages/lib/src/snapshot/internal.ts b/packages/lib/src/snapshot/internal.ts index 4984b411..d11e539d 100644 --- a/packages/lib/src/snapshot/internal.ts +++ b/packages/lib/src/snapshot/internal.ts @@ -78,15 +78,19 @@ export const setNewInternalSnapshot = action( transformFn: SnapshotTransformFn | undefined, markAsFrozen = false ): void => { + const transformed: any = transformFn ? transformFn(untransformed) : untransformed + const sn: SnapshotData = { untransformed, transformFn, - transformed: transformFn ? transformFn(untransformed) : untransformed, + transformed, atom: createAtom("snapshot"), } - frozenState.set(sn.untransformed, markAsFrozen) - if (sn.transformed !== undefined) { - frozenState.set(sn.transformed, markAsFrozen) + + frozenState.set(untransformed, markAsFrozen) + + if (transformed !== undefined && transformed !== untransformed) { + frozenState.set(transformed, markAsFrozen) } snapshots.set(value, sn)