UNPKG

mobx-bonsai

Version:

A fast lightweight alternative to MobX-State-Tree + Y.js two-way binding

16 lines (13 loc) 485 B
import { node } from "./node" import { getSnapshot } from "./snapshot/getSnapshot" import { substituteNodeKeys } from "./substituteNodeKeys" /** * Clones a node. It will generate new node keys deeply using `substituteNodeKeys`. * * @param nodeToClone Node to clone. * @returns The cloned node. */ export function clone<T extends object>(nodeToClone: T): T { const snapshotWithChangedKeys = substituteNodeKeys(getSnapshot(nodeToClone)) return node(snapshotWithChangedKeys) }