@jbrowse/mobx-state-tree 5.7.1 → 5.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -10
- package/dist/index.d.ts +2135 -2
- package/dist/mobx-state-tree.cjs +6894 -0
- package/dist/mobx-state-tree.cjs.map +1 -0
- package/dist/mobx-state-tree.mjs +6814 -0
- package/dist/mobx-state-tree.mjs.map +1 -0
- package/package.json +30 -26
- package/dist/core/action.d.ts +0 -87
- package/dist/core/action.js +0 -228
- package/dist/core/action.js.map +0 -1
- package/dist/core/actionContext.d.ts +0 -27
- package/dist/core/actionContext.js +0 -42
- package/dist/core/actionContext.js.map +0 -1
- package/dist/core/flow.d.ts +0 -69
- package/dist/core/flow.js +0 -180
- package/dist/core/flow.js.map +0 -1
- package/dist/core/json-patch.d.ts +0 -46
- package/dist/core/json-patch.js +0 -133
- package/dist/core/json-patch.js.map +0 -1
- package/dist/core/mst-operations.d.ts +0 -459
- package/dist/core/mst-operations.js +0 -885
- package/dist/core/mst-operations.js.map +0 -1
- package/dist/core/node/BaseNode.d.ts +0 -62
- package/dist/core/node/BaseNode.js +0 -152
- package/dist/core/node/BaseNode.js.map +0 -1
- package/dist/core/node/Hook.d.ts +0 -17
- package/dist/core/node/Hook.js +0 -15
- package/dist/core/node/Hook.js.map +0 -1
- package/dist/core/node/create-node.d.ts +0 -16
- package/dist/core/node/create-node.js +0 -41
- package/dist/core/node/create-node.js.map +0 -1
- package/dist/core/node/identifier-cache.d.ts +0 -19
- package/dist/core/node/identifier-cache.js +0 -115
- package/dist/core/node/identifier-cache.js.map +0 -1
- package/dist/core/node/livelinessChecking.d.ts +0 -37
- package/dist/core/node/livelinessChecking.js +0 -38
- package/dist/core/node/livelinessChecking.js.map +0 -1
- package/dist/core/node/node-utils.d.ts +0 -83
- package/dist/core/node/node-utils.js +0 -165
- package/dist/core/node/node-utils.js.map +0 -1
- package/dist/core/node/object-node.d.ts +0 -101
- package/dist/core/node/object-node.js +0 -546
- package/dist/core/node/object-node.js.map +0 -1
- package/dist/core/node/scalar-node.d.ts +0 -21
- package/dist/core/node/scalar-node.js +0 -90
- package/dist/core/node/scalar-node.js.map +0 -1
- package/dist/core/process.d.ts +0 -50
- package/dist/core/process.js +0 -39
- package/dist/core/process.js.map +0 -1
- package/dist/core/type/type-checker.d.ts +0 -69
- package/dist/core/type/type-checker.js +0 -154
- package/dist/core/type/type-checker.js.map +0 -1
- package/dist/core/type/type.d.ts +0 -317
- package/dist/core/type/type.js +0 -251
- package/dist/core/type/type.js.map +0 -1
- package/dist/index.js +0 -85
- package/dist/index.js.map +0 -1
- package/dist/internal.d.ts +0 -39
- package/dist/internal.js +0 -60
- package/dist/internal.js.map +0 -1
- package/dist/middlewares/create-action-tracking-middleware.d.ts +0 -24
- package/dist/middlewares/create-action-tracking-middleware.js +0 -81
- package/dist/middlewares/create-action-tracking-middleware.js.map +0 -1
- package/dist/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
- package/dist/middlewares/createActionTrackingMiddleware2.js +0 -133
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +0 -1
- package/dist/middlewares/on-action.d.ts +0 -87
- package/dist/middlewares/on-action.js +0 -215
- package/dist/middlewares/on-action.js.map +0 -1
- package/dist/package.json +0 -1
- package/dist/types/complex-types/array.d.ts +0 -81
- package/dist/types/complex-types/array.js +0 -353
- package/dist/types/complex-types/array.js.map +0 -1
- package/dist/types/complex-types/map.d.ts +0 -111
- package/dist/types/complex-types/map.js +0 -362
- package/dist/types/complex-types/map.js.map +0 -1
- package/dist/types/complex-types/model.d.ts +0 -193
- package/dist/types/complex-types/model.js +0 -478
- package/dist/types/complex-types/model.js.map +0 -1
- package/dist/types/index.d.ts +0 -33
- package/dist/types/index.js +0 -38
- package/dist/types/index.js.map +0 -1
- package/dist/types/primitives.d.ts +0 -125
- package/dist/types/primitives.js +0 -183
- package/dist/types/primitives.js.map +0 -1
- package/dist/types/utility-types/custom.d.ts +0 -75
- package/dist/types/utility-types/custom.js +0 -111
- package/dist/types/utility-types/custom.js.map +0 -1
- package/dist/types/utility-types/enumeration.d.ts +0 -5
- package/dist/types/utility-types/enumeration.js +0 -34
- package/dist/types/utility-types/enumeration.js.map +0 -1
- package/dist/types/utility-types/frozen.d.ts +0 -24
- package/dist/types/utility-types/frozen.js +0 -98
- package/dist/types/utility-types/frozen.js.map +0 -1
- package/dist/types/utility-types/identifier.d.ts +0 -87
- package/dist/types/utility-types/identifier.js +0 -130
- package/dist/types/utility-types/identifier.js.map +0 -1
- package/dist/types/utility-types/late.d.ts +0 -10
- package/dist/types/utility-types/late.js +0 -110
- package/dist/types/utility-types/late.js.map +0 -1
- package/dist/types/utility-types/lazy.d.ts +0 -23
- package/dist/types/utility-types/lazy.js +0 -77
- package/dist/types/utility-types/lazy.js.map +0 -1
- package/dist/types/utility-types/literal.d.ts +0 -38
- package/dist/types/utility-types/literal.js +0 -64
- package/dist/types/utility-types/literal.js.map +0 -1
- package/dist/types/utility-types/maybe.d.ts +0 -26
- package/dist/types/utility-types/maybe.js +0 -30
- package/dist/types/utility-types/maybe.js.map +0 -1
- package/dist/types/utility-types/optional.d.ts +0 -42
- package/dist/types/utility-types/optional.js +0 -141
- package/dist/types/utility-types/optional.js.map +0 -1
- package/dist/types/utility-types/reference.d.ts +0 -90
- package/dist/types/utility-types/reference.js +0 -393
- package/dist/types/utility-types/reference.js.map +0 -1
- package/dist/types/utility-types/refinement.d.ts +0 -10
- package/dist/types/utility-types/refinement.js +0 -86
- package/dist/types/utility-types/refinement.js.map +0 -1
- package/dist/types/utility-types/resilient.d.ts +0 -18
- package/dist/types/utility-types/resilient.js +0 -121
- package/dist/types/utility-types/resilient.js.map +0 -1
- package/dist/types/utility-types/snapshotProcessor.d.ts +0 -63
- package/dist/types/utility-types/snapshotProcessor.js +0 -162
- package/dist/types/utility-types/snapshotProcessor.js.map +0 -1
- package/dist/types/utility-types/union.d.ts +0 -78
- package/dist/types/utility-types/union.js +0 -246
- package/dist/types/utility-types/union.js.map +0 -1
- package/dist/utils.d.ts +0 -230
- package/dist/utils.js +0 -483
- package/dist/utils.js.map +0 -1
- package/esm/core/action.d.ts +0 -87
- package/esm/core/action.js +0 -219
- package/esm/core/action.js.map +0 -1
- package/esm/core/actionContext.d.ts +0 -27
- package/esm/core/actionContext.js +0 -37
- package/esm/core/actionContext.js.map +0 -1
- package/esm/core/flow.d.ts +0 -69
- package/esm/core/flow.js +0 -173
- package/esm/core/flow.js.map +0 -1
- package/esm/core/json-patch.d.ts +0 -46
- package/esm/core/json-patch.js +0 -125
- package/esm/core/json-patch.js.map +0 -1
- package/esm/core/mst-operations.d.ts +0 -459
- package/esm/core/mst-operations.js +0 -844
- package/esm/core/mst-operations.js.map +0 -1
- package/esm/core/node/BaseNode.d.ts +0 -62
- package/esm/core/node/BaseNode.js +0 -148
- package/esm/core/node/BaseNode.js.map +0 -1
- package/esm/core/node/Hook.d.ts +0 -17
- package/esm/core/node/Hook.js +0 -12
- package/esm/core/node/Hook.js.map +0 -1
- package/esm/core/node/create-node.d.ts +0 -16
- package/esm/core/node/create-node.js +0 -36
- package/esm/core/node/create-node.js.map +0 -1
- package/esm/core/node/identifier-cache.d.ts +0 -19
- package/esm/core/node/identifier-cache.js +0 -111
- package/esm/core/node/identifier-cache.js.map +0 -1
- package/esm/core/node/livelinessChecking.d.ts +0 -37
- package/esm/core/node/livelinessChecking.js +0 -33
- package/esm/core/node/livelinessChecking.js.map +0 -1
- package/esm/core/node/node-utils.d.ts +0 -83
- package/esm/core/node/node-utils.js +0 -153
- package/esm/core/node/node-utils.js.map +0 -1
- package/esm/core/node/object-node.d.ts +0 -101
- package/esm/core/node/object-node.js +0 -542
- package/esm/core/node/object-node.js.map +0 -1
- package/esm/core/node/scalar-node.d.ts +0 -21
- package/esm/core/node/scalar-node.js +0 -86
- package/esm/core/node/scalar-node.js.map +0 -1
- package/esm/core/process.d.ts +0 -50
- package/esm/core/process.js +0 -35
- package/esm/core/process.js.map +0 -1
- package/esm/core/type/type-checker.d.ts +0 -69
- package/esm/core/type/type-checker.js +0 -144
- package/esm/core/type/type-checker.js.map +0 -1
- package/esm/core/type/type.d.ts +0 -317
- package/esm/core/type/type.js +0 -243
- package/esm/core/type/type.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -2
- package/esm/index.js.map +0 -1
- package/esm/internal.d.ts +0 -39
- package/esm/internal.js +0 -44
- package/esm/internal.js.map +0 -1
- package/esm/middlewares/create-action-tracking-middleware.d.ts +0 -24
- package/esm/middlewares/create-action-tracking-middleware.js +0 -78
- package/esm/middlewares/create-action-tracking-middleware.js.map +0 -1
- package/esm/middlewares/createActionTrackingMiddleware2.d.ts +0 -34
- package/esm/middlewares/createActionTrackingMiddleware2.js +0 -130
- package/esm/middlewares/createActionTrackingMiddleware2.js.map +0 -1
- package/esm/middlewares/on-action.d.ts +0 -87
- package/esm/middlewares/on-action.js +0 -210
- package/esm/middlewares/on-action.js.map +0 -1
- package/esm/types/complex-types/array.d.ts +0 -81
- package/esm/types/complex-types/array.js +0 -347
- package/esm/types/complex-types/array.js.map +0 -1
- package/esm/types/complex-types/map.d.ts +0 -111
- package/esm/types/complex-types/map.js +0 -356
- package/esm/types/complex-types/map.js.map +0 -1
- package/esm/types/complex-types/model.d.ts +0 -193
- package/esm/types/complex-types/model.js +0 -471
- package/esm/types/complex-types/model.js.map +0 -1
- package/esm/types/index.d.ts +0 -33
- package/esm/types/index.js +0 -35
- package/esm/types/index.js.map +0 -1
- package/esm/types/primitives.d.ts +0 -125
- package/esm/types/primitives.js +0 -177
- package/esm/types/primitives.js.map +0 -1
- package/esm/types/utility-types/custom.d.ts +0 -75
- package/esm/types/utility-types/custom.js +0 -106
- package/esm/types/utility-types/custom.js.map +0 -1
- package/esm/types/utility-types/enumeration.d.ts +0 -5
- package/esm/types/utility-types/enumeration.js +0 -31
- package/esm/types/utility-types/enumeration.js.map +0 -1
- package/esm/types/utility-types/frozen.d.ts +0 -24
- package/esm/types/utility-types/frozen.js +0 -92
- package/esm/types/utility-types/frozen.js.map +0 -1
- package/esm/types/utility-types/identifier.d.ts +0 -87
- package/esm/types/utility-types/identifier.js +0 -121
- package/esm/types/utility-types/identifier.js.map +0 -1
- package/esm/types/utility-types/late.d.ts +0 -10
- package/esm/types/utility-types/late.js +0 -106
- package/esm/types/utility-types/late.js.map +0 -1
- package/esm/types/utility-types/lazy.d.ts +0 -23
- package/esm/types/utility-types/lazy.js +0 -72
- package/esm/types/utility-types/lazy.js.map +0 -1
- package/esm/types/utility-types/literal.d.ts +0 -38
- package/esm/types/utility-types/literal.js +0 -58
- package/esm/types/utility-types/literal.js.map +0 -1
- package/esm/types/utility-types/maybe.d.ts +0 -26
- package/esm/types/utility-types/maybe.js +0 -26
- package/esm/types/utility-types/maybe.js.map +0 -1
- package/esm/types/utility-types/optional.d.ts +0 -42
- package/esm/types/utility-types/optional.js +0 -135
- package/esm/types/utility-types/optional.js.map +0 -1
- package/esm/types/utility-types/reference.d.ts +0 -90
- package/esm/types/utility-types/reference.js +0 -383
- package/esm/types/utility-types/reference.js.map +0 -1
- package/esm/types/utility-types/refinement.d.ts +0 -10
- package/esm/types/utility-types/refinement.js +0 -82
- package/esm/types/utility-types/refinement.js.map +0 -1
- package/esm/types/utility-types/resilient.d.ts +0 -18
- package/esm/types/utility-types/resilient.js +0 -118
- package/esm/types/utility-types/resilient.js.map +0 -1
- package/esm/types/utility-types/snapshotProcessor.d.ts +0 -63
- package/esm/types/utility-types/snapshotProcessor.js +0 -159
- package/esm/types/utility-types/snapshotProcessor.js.map +0 -1
- package/esm/types/utility-types/union.d.ts +0 -78
- package/esm/types/utility-types/union.js +0 -240
- package/esm/types/utility-types/union.js.map +0 -1
- package/esm/utils.d.ts +0 -230
- package/esm/utils.js +0 -449
- package/esm/utils.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mst-operations.js","sourceRoot":"","sources":["../../src/core/mst-operations.ts"],"names":[],"mappings":"A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AAC,CAAC,CAAA;IAEhC,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAA;AACxC,CAAC","sourcesContent":["import { isComputedProp, isObservableProp } from \"mobx\"\n\nimport {\n EMPTY_OBJECT,\n InvalidReferenceError,\n asArray,\n assertArg,\n assertIsFunction,\n assertIsNumber,\n assertIsStateTreeNode,\n assertIsString,\n assertIsType,\n assertIsValidIdentifier,\n fail,\n freeze,\n getRelativePathBetweenNodes,\n getRunningActionContext,\n getStateTreeNode,\n isModelType,\n isStateTreeNode,\n normalizeIdentifier,\n resolveNodeByPath,\n splitJsonPath\n} from \"../internal.ts\"\n\nimport type {\n AnyObjectNode,\n IActionContext,\n IAnyComplexType,\n IAnyModelType,\n IAnyStateTreeNode,\n IAnyType,\n IDisposer,\n IJsonPatch,\n IStateTreeNode,\n IType,\n ReferenceIdentifier,\n TypeOfValue\n} from \"../internal.ts\"\n\n/** @hidden */\nexport type TypeOrStateTreeNodeToStateTreeNode<\n T extends IAnyType | IAnyStateTreeNode\n> = T extends IType<any, any, infer TT> ? TT & IStateTreeNode<T> : T\n\n/**\n * Returns the _actual_ type of the given tree node. (Or throws)\n *\n * @param object\n * @returns\n */\nexport function getType(object: IAnyStateTreeNode): IAnyComplexType {\n assertIsStateTreeNode(object, 1)\n\n return getStateTreeNode(object).type\n}\n\n/**\n * Returns the _declared_ type of the given sub property of an object, array or map.\n * In the case of arrays and maps the property name is optional and will be ignored.\n *\n * Example:\n * ```ts\n * const Box = types.model({ x: 0, y: 0 })\n * const box = Box.create()\n *\n * console.log(getChildType(box, \"x\").name) // 'number'\n * ```\n *\n * @param object\n * @param propertyName\n * @returns\n */\nexport function getChildType(\n object: IAnyStateTreeNode,\n propertyName?: string\n): IAnyType {\n assertIsStateTreeNode(object, 1)\n\n return getStateTreeNode(object).getChildType(propertyName)\n}\n\n/**\n * Registers a function that will be invoked for each mutation that is applied to the provided model instance, or to any of its children.\n * See [patches](https://github.com/mobxjs/mobx-state-tree#patches) for more details. onPatch events are emitted immediately and will not await the end of a transaction.\n * Patches can be used to deeply observe a model tree.\n *\n * @param target the model instance from which to receive patches\n * @param callback the callback that is invoked for each patch. The reversePatch is a patch that would actually undo the emitted patch\n * @returns function to remove the listener\n */\nexport function onPatch(\n target: IAnyStateTreeNode,\n callback: (patch: IJsonPatch, reversePatch: IJsonPatch) => void\n): IDisposer {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsFunction(callback, 2)\n\n return getStateTreeNode(target).onPatch(callback)\n}\n\n/**\n * Registers a function that is invoked whenever a new snapshot for the given model instance is available.\n * The listener will only be fire at the end of the current MobX (trans)action.\n * See [snapshots](https://github.com/mobxjs/mobx-state-tree#snapshots) for more details.\n *\n * @param target\n * @param callback\n * @returns\n */\nexport function onSnapshot<S>(\n target: IStateTreeNode<IType<any, S, any>>,\n callback: (snapshot: S) => void\n): IDisposer {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsFunction(callback, 2)\n\n return getStateTreeNode(target).onSnapshot(callback)\n}\n\n/**\n * Applies a JSON-patch to the given model instance or bails out if the patch couldn't be applied\n * See [patches](https://github.com/mobxjs/mobx-state-tree#patches) for more details.\n *\n * Can apply a single past, or an array of patches.\n *\n * @param target\n * @param patch\n * @returns\n */\nexport function applyPatch(\n target: IAnyStateTreeNode,\n patch: IJsonPatch | ReadonlyArray<IJsonPatch>\n): void {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertArg(patch, p => typeof p === \"object\", \"object or array\", 2)\n\n getStateTreeNode(target).applyPatches(asArray(patch))\n}\n\nexport interface IPatchRecorder {\n patches: ReadonlyArray<IJsonPatch>\n inversePatches: ReadonlyArray<IJsonPatch>\n reversedInversePatches: ReadonlyArray<IJsonPatch>\n readonly recording: boolean\n stop(): void\n resume(): void\n replay(target?: IAnyStateTreeNode): void\n undo(target?: IAnyStateTreeNode): void\n}\n\n/**\n * Small abstraction around `onPatch` and `applyPatch`, attaches a patch listener to a tree and records all the patches.\n * Returns a recorder object with the following signature:\n *\n * Example:\n * ```ts\n * export interface IPatchRecorder {\n * // the recorded patches\n * patches: IJsonPatch[]\n * // the inverse of the recorded patches\n * inversePatches: IJsonPatch[]\n * // true if currently recording\n * recording: boolean\n * // stop recording patches\n * stop(): void\n * // resume recording patches\n * resume(): void\n * // apply all the recorded patches on the given target (the original subject if omitted)\n * replay(target?: IAnyStateTreeNode): void\n * // reverse apply the recorded patches on the given target (the original subject if omitted)\n * // stops the recorder if not already stopped\n * undo(): void\n * }\n * ```\n *\n * The optional filter function allows to skip recording certain patches.\n *\n * @param subject\n * @param filter\n * @returns\n */\nexport function recordPatches(\n subject: IAnyStateTreeNode,\n filter?: (\n patch: IJsonPatch,\n inversePatch: IJsonPatch,\n actionContext: IActionContext | undefined\n ) => boolean\n): IPatchRecorder {\n // check all arguments\n assertIsStateTreeNode(subject, 1)\n\n interface IPatches {\n patches: IJsonPatch[]\n reversedInversePatches: IJsonPatch[]\n inversePatches: IJsonPatch[]\n }\n\n const data: Pick<IPatches, \"patches\" | \"inversePatches\"> = {\n patches: [],\n inversePatches: []\n }\n\n // we will generate the immutable copy of patches on demand for public consumption\n const publicData: Partial<IPatches> = {}\n\n let disposer: IDisposer | undefined\n\n const recorder: IPatchRecorder = {\n get recording() {\n return !!disposer\n },\n get patches() {\n if (!publicData.patches) {\n publicData.patches = data.patches.slice()\n }\n return publicData.patches\n },\n get reversedInversePatches() {\n if (!publicData.reversedInversePatches) {\n publicData.reversedInversePatches = data.inversePatches\n .slice()\n .reverse()\n }\n return publicData.reversedInversePatches\n },\n get inversePatches() {\n if (!publicData.inversePatches) {\n publicData.inversePatches = data.inversePatches.slice()\n }\n return publicData.inversePatches\n },\n stop() {\n if (disposer) {\n disposer()\n disposer = undefined\n }\n },\n resume() {\n if (disposer) {\n return\n }\n disposer = onPatch(subject, (patch, inversePatch) => {\n // skip patches that are asked to be filtered if there's a filter in place\n if (filter && !filter(patch, inversePatch, getRunningActionContext())) {\n return\n }\n data.patches.push(patch)\n data.inversePatches.push(inversePatch)\n\n // mark immutable public patches as dirty\n publicData.patches = undefined\n publicData.inversePatches = undefined\n publicData.reversedInversePatches = undefined\n })\n },\n replay(target?: IAnyStateTreeNode) {\n applyPatch(target || subject, data.patches)\n },\n undo(target?: IAnyStateTreeNode) {\n applyPatch(target || subject, data.inversePatches.slice().reverse())\n }\n }\n\n recorder.resume()\n return recorder\n}\n\n/**\n * The inverse of `unprotect`.\n *\n * @param target\n */\nexport function protect(target: IAnyStateTreeNode): void {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n const node = getStateTreeNode(target)\n if (!node.isRoot) {\n throw fail(\"`protect` can only be invoked on root nodes\")\n }\n node.isProtectionEnabled = true\n}\n\n/**\n * By default it is not allowed to directly modify a model. Models can only be modified through actions.\n * However, in some cases you don't care about the advantages (like replayability, traceability, etc) this yields.\n * For example because you are building a PoC or don't have any middleware attached to your tree.\n *\n * In that case you can disable this protection by calling `unprotect` on the root of your tree.\n *\n * Example:\n * ```ts\n * const Todo = types.model({\n * done: false\n * }).actions(self => ({\n * toggle() {\n * self.done = !self.done\n * }\n * }))\n *\n * const todo = Todo.create()\n * todo.done = true // throws!\n * todo.toggle() // OK\n * unprotect(todo)\n * todo.done = false // OK\n * ```\n */\nexport function unprotect(target: IAnyStateTreeNode): void {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n const node = getStateTreeNode(target)\n if (!node.isRoot) {\n throw fail(\"`unprotect` can only be invoked on root nodes\")\n }\n node.isProtectionEnabled = false\n}\n\n/**\n * Returns true if the object is in protected mode, @see protect\n */\nexport function isProtected(target: IAnyStateTreeNode): boolean {\n return getStateTreeNode(target).isProtected\n}\n\n/**\n * Applies a snapshot to a given model instances. Patch and snapshot listeners will be invoked as usual.\n *\n * @param target\n * @param snapshot\n * @returns\n */\nexport function applySnapshot<C>(\n target: IStateTreeNode<IType<C, any, any>>,\n snapshot: C\n) {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).applySnapshot(snapshot)\n}\n\n/**\n * Calculates a snapshot from the given model instance. The snapshot will always reflect the latest state but use\n * structural sharing where possible. Doesn't require MobX transactions to be completed.\n *\n * @param target\n * @param applyPostProcess If true (the default) then postProcessSnapshot gets applied.\n * @returns\n */\nexport function getSnapshot<S>(\n target: IStateTreeNode<IType<any, S, any>>,\n applyPostProcess = true\n): S {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n const node = getStateTreeNode(target)\n if (applyPostProcess) {\n return node.snapshot\n }\n\n return freeze(node.type.getSnapshot(node, false))\n}\n\n/**\n * Given a model instance, returns `true` if the object has a parent, that is, is part of another object, map or array.\n *\n * @param target\n * @param depth How far should we look upward? 1 by default.\n * @returns\n */\nexport function hasParent(\n target: IAnyStateTreeNode,\n depth: number = 1\n): boolean {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsNumber(depth, 2, 0)\n\n let parent: AnyObjectNode | null = getStateTreeNode(target).parent\n while (parent) {\n if (--depth === 0) {\n return true\n }\n parent = parent.parent\n }\n return false\n}\n\n/**\n * Returns the immediate parent of this object, or throws.\n *\n * Note that the immediate parent can be either an object, map or array, and\n * doesn't necessarily refer to the parent model.\n *\n * Please note that in child nodes access to the root is only possible\n * once the `afterAttach` hook has fired.\n *\n * @param target\n * @param depth How far should we look upward? 1 by default.\n * @returns\n */\nexport function getParent<IT extends IAnyStateTreeNode | IAnyComplexType>(\n target: IAnyStateTreeNode,\n depth = 1\n): TypeOrStateTreeNodeToStateTreeNode<IT> {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsNumber(depth, 2, 0)\n\n let d = depth\n let parent: AnyObjectNode | null = getStateTreeNode(target).parent\n while (parent) {\n if (--d === 0) {\n return parent.storedValue as any\n }\n parent = parent.parent\n }\n throw fail(\n `Failed to find the parent of ${getStateTreeNode(target)} at depth ${depth}`\n )\n}\n\n/**\n * Given a model instance, returns `true` if the object has a parent of given type, that is, is part of another object, map or array\n *\n * @param target\n * @param type\n * @returns\n */\nexport function hasParentOfType(\n target: IAnyStateTreeNode,\n type: IAnyComplexType\n): boolean {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsType(type, 2)\n\n let parent: AnyObjectNode | null = getStateTreeNode(target).parent\n while (parent) {\n if (type.is(parent.storedValue)) {\n return true\n }\n parent = parent.parent\n }\n return false\n}\n\n/**\n * Returns the target's parent of a given type, or throws.\n *\n * @param target\n * @param type\n * @returns\n */\nexport function getParentOfType<IT extends IAnyComplexType>(\n target: IAnyStateTreeNode,\n type: IT\n): IT[\"Type\"] {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsType(type, 2)\n\n let parent: AnyObjectNode | null = getStateTreeNode(target).parent\n while (parent) {\n if (type.is(parent.storedValue)) {\n return parent.storedValue\n }\n parent = parent.parent\n }\n throw fail(\n `Failed to find the parent of ${getStateTreeNode(target)} of a given type`\n )\n}\n\n/**\n * Given an object in a model tree, returns the root object of that tree.\n *\n * Please note that in child nodes access to the root is only possible\n * once the `afterAttach` hook has fired.\n *\n * @param target\n * @returns\n */\nexport function getRoot<IT extends IAnyComplexType | IAnyStateTreeNode>(\n target: IAnyStateTreeNode\n): TypeOrStateTreeNodeToStateTreeNode<IT> {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).root.storedValue\n}\n\n/**\n * Returns the path of the given object in the model tree\n *\n * @param target\n * @returns\n */\nexport function getPath(target: IAnyStateTreeNode): string {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).path\n}\n\n/**\n * Returns the path of the given object as unescaped string array.\n *\n * @param target\n * @returns\n */\nexport function getPathParts(target: IAnyStateTreeNode): string[] {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return splitJsonPath(getStateTreeNode(target).path)\n}\n\n/**\n * Returns true if the given object is the root of a model tree.\n *\n * @param target\n * @returns\n */\nexport function isRoot(target: IAnyStateTreeNode): boolean {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).isRoot\n}\n\n/**\n * Resolves a path relatively to a given object.\n * Returns undefined if no value can be found.\n *\n * @param target\n * @param path escaped json path\n * @returns\n */\nexport function resolvePath(target: IAnyStateTreeNode, path: string): any {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsString(path, 2)\n\n const node = resolveNodeByPath(getStateTreeNode(target), path)\n return node ? node.value : undefined\n}\n\n/**\n * Resolves a model instance given a root target, the type and the identifier you are searching for.\n * Returns undefined if no value can be found.\n *\n * @param type\n * @param target\n * @param identifier\n * @returns\n */\nexport function resolveIdentifier<IT extends IAnyModelType>(\n type: IT,\n target: IAnyStateTreeNode,\n identifier: ReferenceIdentifier\n): IT[\"Type\"] | undefined {\n // check all arguments\n assertIsType(type, 1)\n assertIsStateTreeNode(target, 2)\n assertIsValidIdentifier(identifier, 3)\n\n const node = getStateTreeNode(target).root.identifierCache!.resolve(\n type,\n normalizeIdentifier(identifier)\n )\n return node?.value\n}\n\n/**\n * Returns the identifier of the target node.\n * This is the *string normalized* identifier, which might not match the type of the identifier attribute\n *\n * @param target\n * @returns\n */\nexport function getIdentifier(target: IAnyStateTreeNode): string | null {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).identifier\n}\n\n/**\n * Tests if a reference is valid (pointing to an existing node and optionally if alive) and returns such reference if the check passes,\n * else it returns undefined.\n *\n * @param getter Function to access the reference.\n * @param checkIfAlive true to also make sure the referenced node is alive (default), false to skip this check.\n * @returns\n */\nexport function tryReference<N extends IAnyStateTreeNode>(\n getter: () => N | null | undefined,\n checkIfAlive = true\n): N | undefined {\n try {\n const node = getter()\n if (node === undefined || node === null) {\n return undefined\n } else if (isStateTreeNode(node)) {\n if (!checkIfAlive) {\n return node\n } else {\n return isAlive(node) ? node : undefined\n }\n } else {\n throw fail(\n \"The reference to be checked is not one of node, null or undefined\"\n )\n }\n } catch (e) {\n if (e instanceof InvalidReferenceError) {\n return undefined\n }\n throw e\n }\n}\n\n/**\n * Tests if a reference is valid (pointing to an existing node and optionally if alive) and returns if the check passes or not.\n *\n * @param getter Function to access the reference.\n * @param checkIfAlive true to also make sure the referenced node is alive (default), false to skip this check.\n * @returns\n */\nexport function isValidReference<N extends IAnyStateTreeNode>(\n getter: () => N | null | undefined,\n checkIfAlive = true\n): boolean {\n try {\n const node = getter()\n if (node === undefined || node === null) {\n return false\n } else if (isStateTreeNode(node)) {\n return checkIfAlive ? isAlive(node) : true\n } else {\n throw fail(\n \"The reference to be checked is not one of node, null or undefined\"\n )\n }\n } catch (e) {\n if (e instanceof InvalidReferenceError) {\n return false\n }\n throw e\n }\n}\n\n/**\n * Try to resolve a given path relative to a given node.\n *\n * @param target\n * @param path\n * @returns\n */\nexport function tryResolve(target: IAnyStateTreeNode, path: string): any {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsString(path, 2)\n\n const node = resolveNodeByPath(getStateTreeNode(target), path, false)\n if (node === undefined) {\n return undefined\n }\n try {\n return node.value\n } catch (_e) {\n // For what ever reason not resolvable (e.g. totally not existing path, or value that cannot be fetched)\n // see test / issue: 'try resolve doesn't work #686'\n return undefined\n }\n}\n\n/**\n * Given two state tree nodes that are part of the same tree,\n * returns the shortest jsonpath needed to navigate from the one to the other\n *\n * @param base\n * @param target\n * @returns\n */\nexport function getRelativePath(\n base: IAnyStateTreeNode,\n target: IAnyStateTreeNode\n): string {\n // check all arguments\n assertIsStateTreeNode(base, 1)\n assertIsStateTreeNode(target, 2)\n\n return getRelativePathBetweenNodes(\n getStateTreeNode(base),\n getStateTreeNode(target)\n )\n}\n\n/**\n * Returns a deep copy of the given state tree node as new tree.\n * Shorthand for `snapshot(x) = getType(x).create(getSnapshot(x))`\n *\n * _Tip: clone will create a literal copy, including the same identifiers. To modify identifiers etc. during cloning, don't use clone but take a snapshot of the tree, modify it, and create new instance_\n *\n * @param source\n * @param keepEnvironment indicates whether the clone should inherit the same environment (`true`, the default), or not have an environment (`false`). If an object is passed in as second argument, that will act as the environment for the cloned tree.\n * @returns\n */\nexport function clone<T extends IAnyStateTreeNode>(\n source: T,\n keepEnvironment: boolean | any = true\n): T {\n // check all arguments\n assertIsStateTreeNode(source, 1)\n\n const node = getStateTreeNode(source)\n return node.type.create(\n node.snapshot,\n keepEnvironment === true\n ? node.root.environment\n : keepEnvironment === false\n ? undefined\n : keepEnvironment\n ) // it's an object or something else\n}\n\n/**\n * Removes a model element from the state tree, and let it live on as a new state tree\n */\nexport function detach<T extends IAnyStateTreeNode>(target: T): T {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n getStateTreeNode(target).detach()\n return target\n}\n\n/**\n * Removes a model element from the state tree, and mark it as end-of-life; the element should not be used anymore\n */\nexport function destroy(target: IAnyStateTreeNode): void {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n const node = getStateTreeNode(target)\n if (node.isRoot) {\n node.die()\n } else {\n node.parent!.removeChild(node.subpath)\n }\n}\n\n/**\n * Returns true if the given state tree node is not killed yet.\n * This means that the node is still a part of a tree, and that `destroy`\n * has not been called. If a node is not alive anymore, the only thing one can do with it\n * is requesting it's last path and snapshot\n *\n * @param target\n * @returns\n */\nexport function isAlive(target: IAnyStateTreeNode): boolean {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).observableIsAlive\n}\n\n/**\n * Use this utility to register a function that should be called whenever the\n * targeted state tree node is destroyed. This is a useful alternative to managing\n * cleanup methods yourself using the `beforeDestroy` hook.\n *\n * This methods returns the same disposer that was passed as argument.\n *\n * Example:\n * ```ts\n * const Todo = types.model({\n * title: types.string\n * }).actions(self => ({\n * afterCreate() {\n * const autoSaveDisposer = reaction(\n * () => getSnapshot(self),\n * snapshot => sendSnapshotToServerSomehow(snapshot)\n * )\n * // stop sending updates to server if this\n * // instance is destroyed\n * addDisposer(self, autoSaveDisposer)\n * }\n * }))\n * ```\n *\n * @param target\n * @param disposer\n * @returns The same disposer that was passed as argument\n */\nexport function addDisposer(\n target: IAnyStateTreeNode,\n disposer: IDisposer\n): IDisposer {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsFunction(disposer, 2)\n\n const node = getStateTreeNode(target)\n node.addDisposer(disposer)\n return disposer\n}\n\n/**\n * Returns the environment of the current state tree. For more info on environments,\n * see [Dependency injection](https://github.com/mobxjs/mobx-state-tree#dependency-injection)\n *\n * Please note that in child nodes access to the root is only possible\n * once the `afterAttach` hook has fired\n *\n * Returns an empty environment if the tree wasn't initialized with an environment\n *\n * @param target\n * @returns\n */\nexport function getEnv<T = any>(target: IAnyStateTreeNode): T {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n\n const node = getStateTreeNode(target)\n const env = node.root.environment\n if (!env) {\n return EMPTY_OBJECT as T\n }\n return env\n}\n\n/**\n * Performs a depth first walk through a tree.\n */\nexport function walk(\n target: IAnyStateTreeNode,\n processor: (item: IAnyStateTreeNode) => void\n): void {\n // check all arguments\n assertIsStateTreeNode(target, 1)\n assertIsFunction(processor, 2)\n\n const node = getStateTreeNode(target)\n // tslint:disable-next-line:no_unused-variable\n node.getChildren().forEach(child => {\n if (isStateTreeNode(child.storedValue)) {\n walk(child.storedValue, processor)\n }\n })\n processor(node.storedValue)\n}\n\nexport interface IModelReflectionPropertiesData {\n name: string\n properties: { [K: string]: IAnyType }\n}\n\n/**\n * Returns a reflection of the model type properties and name for either a model type or model node.\n *\n * @param typeOrNode\n * @returns\n */\nexport function getPropertyMembers(\n typeOrNode: IAnyModelType | IAnyStateTreeNode\n): IModelReflectionPropertiesData {\n let type: IAnyModelType\n\n if (isStateTreeNode(typeOrNode)) {\n type = getType(typeOrNode) as IAnyModelType\n } else {\n type = typeOrNode as IAnyModelType\n }\n\n assertArg(type, t => isModelType(t), \"model type or model instance\", 1)\n\n return {\n name: type.name,\n properties: { ...type.properties }\n }\n}\n\nexport interface IModelReflectionData extends IModelReflectionPropertiesData {\n actions: string[]\n views: string[]\n volatile: string[]\n flowActions: string[]\n}\n\n/**\n * Returns a reflection of the model node, including name, properties, views, volatile state,\n * and actions. `flowActions` is also provided as a separate array of names for any action that\n * came from a flow generator as well.\n *\n * In the case where a model has two actions: `doSomething` and `doSomethingWithFlow`, where\n * `doSomethingWithFlow` is a flow generator, the `actions` array will contain both actions,\n * i.e. [\"doSomething\", \"doSomethingWithFlow\"], and the `flowActions` array will contain only\n * the flow action, i.e. [\"doSomethingWithFlow\"].\n *\n * @param target\n * @returns\n */\nexport function getMembers(target: IAnyStateTreeNode): IModelReflectionData {\n const type = getStateTreeNode(target).type as unknown as IAnyModelType\n\n const reflected: IModelReflectionData = {\n ...getPropertyMembers(type),\n actions: [],\n volatile: [],\n views: [],\n flowActions: []\n }\n\n const props = Object.getOwnPropertyNames(target)\n props.forEach(key => {\n if (key in reflected.properties) {\n return\n }\n const descriptor = Object.getOwnPropertyDescriptor(target, key)!\n if (descriptor.get) {\n if (isComputedProp(target, key)) {\n reflected.views.push(key)\n } else {\n reflected.volatile.push(key)\n }\n return\n }\n if (descriptor.value._isFlowAction === true) {\n reflected.flowActions.push(key)\n }\n if (descriptor.value._isMSTAction === true) {\n reflected.actions.push(key)\n } else if (isObservableProp(target, key)) {\n reflected.volatile.push(key)\n } else {\n reflected.views.push(key)\n }\n })\n return reflected\n}\n\nexport function cast<\n O extends string | number | boolean | null | undefined = never\n>(snapshotOrInstance: O): O\nexport function cast<O = never>(\n snapshotOrInstance:\n | TypeOfValue<O>[\"CreationType\"]\n | TypeOfValue<O>[\"SnapshotType\"]\n | TypeOfValue<O>[\"Type\"]\n): O\n/**\n * Casts a node snapshot or instance type to an instance type so it can be assigned to a type instance.\n * Note that this is just a cast for the type system, this is, it won't actually convert a snapshot to an instance,\n * but just fool typescript into thinking so.\n * Either way, casting when outside an assignation operation won't compile.\n *\n * Example:\n * ```ts\n * const ModelA = types.model({\n * n: types.number\n * }).actions(self => ({\n * setN(aNumber: number) {\n * self.n = aNumber\n * }\n * }))\n *\n * const ModelB = types.model({\n * innerModel: ModelA\n * }).actions(self => ({\n * someAction() {\n * // this will allow the compiler to assign a snapshot to the property\n * self.innerModel = cast({ a: 5 })\n * }\n * }))\n * ```\n *\n * @param snapshotOrInstance Snapshot or instance\n * @returns The same object cast as an instance\n */\nexport function cast(snapshotOrInstance: any): any {\n return snapshotOrInstance as any\n}\n\n/**\n * Casts a node instance type to a snapshot type so it can be assigned to a type snapshot (e.g. to be used inside a create call).\n * Note that this is just a cast for the type system, this is, it won't actually convert an instance to a snapshot,\n * but just fool typescript into thinking so.\n *\n * Example:\n * ```ts\n * const ModelA = types.model({\n * n: types.number\n * }).actions(self => ({\n * setN(aNumber: number) {\n * self.n = aNumber\n * }\n * }))\n *\n * const ModelB = types.model({\n * innerModel: ModelA\n * })\n *\n * const a = ModelA.create({ n: 5 });\n * // this will allow the compiler to use a model as if it were a snapshot\n * const b = ModelB.create({ innerModel: castToSnapshot(a)})\n * ```\n *\n * @param snapshotOrInstance Snapshot or instance\n * @returns The same object cast as an input (creation) snapshot\n */\nexport function castToSnapshot<I>(\n snapshotOrInstance: I\n): Extract<I, IAnyStateTreeNode> extends never\n ? I\n : TypeOfValue<I>[\"CreationType\"] {\n return snapshotOrInstance as any\n}\n\n/**\n * Casts a node instance type to a reference snapshot type so it can be assigned to a reference snapshot (e.g. to be used inside a create call).\n * Note that this is just a cast for the type system, this is, it won't actually convert an instance to a reference snapshot,\n * but just fool typescript into thinking so.\n *\n * Example:\n * ```ts\n * const ModelA = types.model({\n * id: types.identifier,\n * n: types.number\n * }).actions(self => ({\n * setN(aNumber: number) {\n * self.n = aNumber\n * }\n * }))\n *\n * const ModelB = types.model({\n * refA: types.reference(ModelA)\n * })\n *\n * const a = ModelA.create({ id: 'someId', n: 5 });\n * // this will allow the compiler to use a model as if it were a reference snapshot\n * const b = ModelB.create({ refA: castToReferenceSnapshot(a)})\n * ```\n *\n * @param instance Instance\n * @returns The same object cast as a reference snapshot (string or number)\n */\nexport function castToReferenceSnapshot<I>(\n instance: I\n): Extract<I, IAnyStateTreeNode> extends never ? I : ReferenceIdentifier {\n return instance as any\n}\n\n/**\n * Returns the unique node id (not to be confused with the instance identifier) for a\n * given instance.\n * This id is a number that is unique for each instance.\n *\n * @export\n * @param target\n * @returns\n */\nexport function getNodeId(target: IAnyStateTreeNode): number {\n assertIsStateTreeNode(target, 1)\n\n return getStateTreeNode(target).nodeId\n}\n"]}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type AnyObjectNode, Hook, type IAnyType, type IDisposer, NodeLifeCycle } from "../../internal.ts";
|
|
2
|
-
type HookSubscribers = {
|
|
3
|
-
[Hook.afterAttach]: (node: AnyNode, hook: Hook) => void;
|
|
4
|
-
[Hook.afterCreate]: (node: AnyNode, hook: Hook) => void;
|
|
5
|
-
[Hook.afterCreationFinalization]: (node: AnyNode, hook: Hook) => void;
|
|
6
|
-
[Hook.beforeDestroy]: (node: AnyNode, hook: Hook) => void;
|
|
7
|
-
[Hook.beforeDetach]: (node: AnyNode, hook: Hook) => void;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
* @hidden
|
|
12
|
-
*/
|
|
13
|
-
export declare abstract class BaseNode<C, S, T> {
|
|
14
|
-
readonly type: IAnyType;
|
|
15
|
-
environment: any;
|
|
16
|
-
private _escapedSubpath?;
|
|
17
|
-
private _subpath;
|
|
18
|
-
get subpath(): string;
|
|
19
|
-
private _subpathUponDeath?;
|
|
20
|
-
get subpathUponDeath(): string | undefined;
|
|
21
|
-
private _pathUponDeath?;
|
|
22
|
-
protected get pathUponDeath(): string | undefined;
|
|
23
|
-
storedValue: any;
|
|
24
|
-
get value(): T;
|
|
25
|
-
private aliveAtom?;
|
|
26
|
-
private _state;
|
|
27
|
-
get state(): NodeLifeCycle;
|
|
28
|
-
set state(val: NodeLifeCycle);
|
|
29
|
-
private _hookSubscribers?;
|
|
30
|
-
protected abstract fireHook(name: Hook): void;
|
|
31
|
-
protected fireInternalHook(name: Hook): void;
|
|
32
|
-
registerHook<H extends Hook>(hook: H, hookHandler: HookSubscribers[H]): IDisposer;
|
|
33
|
-
private _parent;
|
|
34
|
-
get parent(): AnyObjectNode | null;
|
|
35
|
-
constructor(type: IAnyType, parent: AnyObjectNode | null, subpath: string, environment: any);
|
|
36
|
-
getReconciliationType(): IAnyType;
|
|
37
|
-
private pathAtom?;
|
|
38
|
-
protected baseSetParent(parent: AnyObjectNode | null, subpath: string): void;
|
|
39
|
-
get path(): string;
|
|
40
|
-
protected getEscapedPath(reportObserved: boolean): string;
|
|
41
|
-
get isRoot(): boolean;
|
|
42
|
-
abstract get root(): AnyObjectNode;
|
|
43
|
-
abstract setParent(newParent: AnyObjectNode | null, subpath: string | null): void;
|
|
44
|
-
abstract get snapshot(): S;
|
|
45
|
-
abstract getSnapshot(): S;
|
|
46
|
-
get isAlive(): boolean;
|
|
47
|
-
get isDetaching(): boolean;
|
|
48
|
-
get observableIsAlive(): boolean;
|
|
49
|
-
abstract die(): void;
|
|
50
|
-
abstract finalizeCreation(): void;
|
|
51
|
-
protected baseFinalizeCreation(whenFinalized?: () => void): void;
|
|
52
|
-
abstract finalizeDeath(): void;
|
|
53
|
-
protected baseFinalizeDeath(): void;
|
|
54
|
-
abstract aboutToDie(): void;
|
|
55
|
-
protected baseAboutToDie(): void;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
* @hidden
|
|
60
|
-
*/
|
|
61
|
-
export type AnyNode = BaseNode<any, any, any>;
|
|
62
|
-
export {};
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { createAtom } from "mobx";
|
|
2
|
-
import { EventHandlers, Hook, NodeLifeCycle, devMode, escapeJsonPath, fail } from "../../internal.js";
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
* @hidden
|
|
6
|
-
*/
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
-
export class BaseNode {
|
|
9
|
-
type;
|
|
10
|
-
environment;
|
|
11
|
-
_escapedSubpath;
|
|
12
|
-
_subpath;
|
|
13
|
-
get subpath() {
|
|
14
|
-
return this._subpath;
|
|
15
|
-
}
|
|
16
|
-
_subpathUponDeath;
|
|
17
|
-
get subpathUponDeath() {
|
|
18
|
-
return this._subpathUponDeath;
|
|
19
|
-
}
|
|
20
|
-
_pathUponDeath;
|
|
21
|
-
get pathUponDeath() {
|
|
22
|
-
return this._pathUponDeath;
|
|
23
|
-
}
|
|
24
|
-
storedValue; // usually the same type as the value, but not always (such as with references)
|
|
25
|
-
get value() {
|
|
26
|
-
return this.type.getValue(this);
|
|
27
|
-
}
|
|
28
|
-
aliveAtom;
|
|
29
|
-
_state = NodeLifeCycle.INITIALIZING;
|
|
30
|
-
get state() {
|
|
31
|
-
return this._state;
|
|
32
|
-
}
|
|
33
|
-
set state(val) {
|
|
34
|
-
const wasAlive = this.isAlive;
|
|
35
|
-
this._state = val;
|
|
36
|
-
const isAlive = this.isAlive;
|
|
37
|
-
if (this.aliveAtom && wasAlive !== isAlive) {
|
|
38
|
-
this.aliveAtom.reportChanged();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
_hookSubscribers;
|
|
42
|
-
fireInternalHook(name) {
|
|
43
|
-
if (this._hookSubscribers) {
|
|
44
|
-
this._hookSubscribers.emit(name, this, name);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
registerHook(hook, hookHandler) {
|
|
48
|
-
if (!this._hookSubscribers) {
|
|
49
|
-
this._hookSubscribers = new EventHandlers();
|
|
50
|
-
}
|
|
51
|
-
return this._hookSubscribers.register(hook, hookHandler);
|
|
52
|
-
}
|
|
53
|
-
_parent;
|
|
54
|
-
get parent() {
|
|
55
|
-
return this._parent;
|
|
56
|
-
}
|
|
57
|
-
constructor(type, parent, subpath, environment) {
|
|
58
|
-
this.type = type;
|
|
59
|
-
this.environment = environment;
|
|
60
|
-
this.environment = environment;
|
|
61
|
-
this.baseSetParent(parent, subpath);
|
|
62
|
-
}
|
|
63
|
-
getReconciliationType() {
|
|
64
|
-
return this.type;
|
|
65
|
-
}
|
|
66
|
-
pathAtom;
|
|
67
|
-
baseSetParent(parent, subpath) {
|
|
68
|
-
this._parent = parent;
|
|
69
|
-
this._subpath = subpath;
|
|
70
|
-
this._escapedSubpath = undefined; // regenerate when needed
|
|
71
|
-
if (this.pathAtom) {
|
|
72
|
-
this.pathAtom.reportChanged();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/*
|
|
76
|
-
* Returns (escaped) path representation as string
|
|
77
|
-
*/
|
|
78
|
-
get path() {
|
|
79
|
-
return this.getEscapedPath(true);
|
|
80
|
-
}
|
|
81
|
-
getEscapedPath(reportObserved) {
|
|
82
|
-
if (reportObserved) {
|
|
83
|
-
if (!this.pathAtom) {
|
|
84
|
-
this.pathAtom = createAtom(`path`);
|
|
85
|
-
}
|
|
86
|
-
this.pathAtom.reportObserved();
|
|
87
|
-
}
|
|
88
|
-
if (!this.parent) {
|
|
89
|
-
return "";
|
|
90
|
-
}
|
|
91
|
-
// regenerate escaped subpath if needed
|
|
92
|
-
if (this._escapedSubpath === undefined) {
|
|
93
|
-
this._escapedSubpath = !this._subpath ? "" : escapeJsonPath(this._subpath);
|
|
94
|
-
}
|
|
95
|
-
return (this.parent.getEscapedPath(reportObserved) + "/" + this._escapedSubpath);
|
|
96
|
-
}
|
|
97
|
-
get isRoot() {
|
|
98
|
-
return this.parent === null;
|
|
99
|
-
}
|
|
100
|
-
get isAlive() {
|
|
101
|
-
return this.state !== NodeLifeCycle.DEAD;
|
|
102
|
-
}
|
|
103
|
-
get isDetaching() {
|
|
104
|
-
return this.state === NodeLifeCycle.DETACHING;
|
|
105
|
-
}
|
|
106
|
-
get observableIsAlive() {
|
|
107
|
-
if (!this.aliveAtom) {
|
|
108
|
-
this.aliveAtom = createAtom(`alive`);
|
|
109
|
-
}
|
|
110
|
-
this.aliveAtom.reportObserved();
|
|
111
|
-
return this.isAlive;
|
|
112
|
-
}
|
|
113
|
-
baseFinalizeCreation(whenFinalized) {
|
|
114
|
-
if (devMode()) {
|
|
115
|
-
if (!this.isAlive) {
|
|
116
|
-
// istanbul ignore next
|
|
117
|
-
throw fail("assertion failed: cannot finalize the creation of a node that is already dead");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// goal: afterCreate hooks runs depth-first. After attach runs parent first, so on afterAttach the parent has completed already
|
|
121
|
-
if (this.state === NodeLifeCycle.CREATED) {
|
|
122
|
-
if (this.parent) {
|
|
123
|
-
if (this.parent.state !== NodeLifeCycle.FINALIZED) {
|
|
124
|
-
// parent not ready yet, postpone
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
this.fireHook(Hook.afterAttach);
|
|
128
|
-
}
|
|
129
|
-
this.state = NodeLifeCycle.FINALIZED;
|
|
130
|
-
if (whenFinalized) {
|
|
131
|
-
whenFinalized();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
baseFinalizeDeath() {
|
|
136
|
-
if (this._hookSubscribers) {
|
|
137
|
-
this._hookSubscribers.clearAll();
|
|
138
|
-
}
|
|
139
|
-
this._subpathUponDeath = this._subpath;
|
|
140
|
-
this._pathUponDeath = this.getEscapedPath(false);
|
|
141
|
-
this.baseSetParent(null, "");
|
|
142
|
-
this.state = NodeLifeCycle.DEAD;
|
|
143
|
-
}
|
|
144
|
-
baseAboutToDie() {
|
|
145
|
-
this.fireHook(Hook.beforeDestroy);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
//# sourceMappingURL=BaseNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseNode.js","sourceRoot":"","sources":["../../../src/core/node/BaseNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,MAAM,CAAA;AAE7C,OAAO,EAEL,aAAa,EACb,IAAI,EAGJ,aAAa,EACb,OAAO,EACP,cAAc,EACd,IAAI,EACL,MAAM,mBAAmB,CAAA;AAU1B;;;GAGG;AACH,6DAA6D;AAC7D,MAAM,OAAgB,QAAQ;IAgEjB;IAGF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ACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACjC,CAAC;YAED,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAA;YAEpC,IAAI,aAAa,EAAE,CAAC;gBAClB,aAAa,EAAE,CAAA;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAIS,iBAAiB;QACzB,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAA;QAClC,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAA;QACtC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;QAChD,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAA;IACjC,CAAC;IAIS,cAAc;QACtB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import { type IAtom, createAtom } from \"mobx\"\n\nimport {\n type AnyObjectNode,\n EventHandlers,\n Hook,\n type IAnyType,\n type IDisposer,\n NodeLifeCycle,\n devMode,\n escapeJsonPath,\n fail\n} from \"../../internal.ts\"\n\ntype HookSubscribers = {\n [Hook.afterAttach]: (node: AnyNode, hook: Hook) => void\n [Hook.afterCreate]: (node: AnyNode, hook: Hook) => void\n [Hook.afterCreationFinalization]: (node: AnyNode, hook: Hook) => void\n [Hook.beforeDestroy]: (node: AnyNode, hook: Hook) => void\n [Hook.beforeDetach]: (node: AnyNode, hook: Hook) => void\n}\n\n/**\n * @internal\n * @hidden\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport abstract class BaseNode<C, S, T> {\n private _escapedSubpath?: string\n\n private _subpath!: string\n get subpath() {\n return this._subpath\n }\n\n private _subpathUponDeath?: string\n get subpathUponDeath() {\n return this._subpathUponDeath\n }\n\n private _pathUponDeath?: string\n protected get pathUponDeath() {\n return this._pathUponDeath\n }\n\n storedValue!: any // usually the same type as the value, but not always (such as with references)\n get value(): T {\n return (this.type as any).getValue(this)\n }\n\n private aliveAtom?: IAtom\n private _state = NodeLifeCycle.INITIALIZING\n get state() {\n return this._state\n }\n set state(val: NodeLifeCycle) {\n const wasAlive = this.isAlive\n this._state = val\n const isAlive = this.isAlive\n\n if (this.aliveAtom && wasAlive !== isAlive) {\n this.aliveAtom.reportChanged()\n }\n }\n\n private _hookSubscribers?: EventHandlers<HookSubscribers>\n\n protected abstract fireHook(name: Hook): void\n\n protected fireInternalHook(name: Hook) {\n if (this._hookSubscribers) {\n this._hookSubscribers.emit(name, this, name)\n }\n }\n\n registerHook<H extends Hook>(\n hook: H,\n hookHandler: HookSubscribers[H]\n ): IDisposer {\n if (!this._hookSubscribers) {\n this._hookSubscribers = new EventHandlers()\n }\n return this._hookSubscribers.register(hook, hookHandler)\n }\n\n private _parent!: AnyObjectNode | null\n get parent() {\n return this._parent\n }\n\n constructor(\n readonly type: IAnyType,\n parent: AnyObjectNode | null,\n subpath: string,\n public environment: any\n ) {\n this.environment = environment\n this.baseSetParent(parent, subpath)\n }\n\n getReconciliationType() {\n return this.type\n }\n\n private pathAtom?: IAtom\n protected baseSetParent(parent: AnyObjectNode | null, subpath: string) {\n this._parent = parent\n this._subpath = subpath\n this._escapedSubpath = undefined // regenerate when needed\n if (this.pathAtom) {\n this.pathAtom.reportChanged()\n }\n }\n\n /*\n * Returns (escaped) path representation as string\n */\n get path(): string {\n return this.getEscapedPath(true)\n }\n\n protected getEscapedPath(reportObserved: boolean): string {\n if (reportObserved) {\n if (!this.pathAtom) {\n this.pathAtom = createAtom(`path`)\n }\n this.pathAtom.reportObserved()\n }\n if (!this.parent) {\n return \"\"\n }\n // regenerate escaped subpath if needed\n if (this._escapedSubpath === undefined) {\n this._escapedSubpath = !this._subpath ? \"\" : escapeJsonPath(this._subpath)\n }\n return (\n this.parent.getEscapedPath(reportObserved) + \"/\" + this._escapedSubpath\n )\n }\n\n get isRoot(): boolean {\n return this.parent === null\n }\n\n abstract get root(): AnyObjectNode\n\n abstract setParent(\n newParent: AnyObjectNode | null,\n subpath: string | null\n ): void\n\n abstract get snapshot(): S\n abstract getSnapshot(): S\n\n get isAlive() {\n return this.state !== NodeLifeCycle.DEAD\n }\n\n get isDetaching() {\n return this.state === NodeLifeCycle.DETACHING\n }\n\n get observableIsAlive() {\n if (!this.aliveAtom) {\n this.aliveAtom = createAtom(`alive`)\n }\n this.aliveAtom.reportObserved()\n return this.isAlive\n }\n\n abstract die(): void\n\n abstract finalizeCreation(): void\n\n protected baseFinalizeCreation(whenFinalized?: () => void) {\n if (devMode()) {\n if (!this.isAlive) {\n // istanbul ignore next\n throw fail(\n \"assertion failed: cannot finalize the creation of a node that is already dead\"\n )\n }\n }\n\n // goal: afterCreate hooks runs depth-first. After attach runs parent first, so on afterAttach the parent has completed already\n if (this.state === NodeLifeCycle.CREATED) {\n if (this.parent) {\n if (this.parent.state !== NodeLifeCycle.FINALIZED) {\n // parent not ready yet, postpone\n return\n }\n this.fireHook(Hook.afterAttach)\n }\n\n this.state = NodeLifeCycle.FINALIZED\n\n if (whenFinalized) {\n whenFinalized()\n }\n }\n }\n\n abstract finalizeDeath(): void\n\n protected baseFinalizeDeath() {\n if (this._hookSubscribers) {\n this._hookSubscribers.clearAll()\n }\n\n this._subpathUponDeath = this._subpath\n this._pathUponDeath = this.getEscapedPath(false)\n this.baseSetParent(null, \"\")\n this.state = NodeLifeCycle.DEAD\n }\n\n abstract aboutToDie(): void\n\n protected baseAboutToDie() {\n this.fireHook(Hook.beforeDestroy)\n }\n}\n\n/**\n * @internal\n * @hidden\n */\nexport type AnyNode = BaseNode<any, any, any>\n"]}
|
package/esm/core/node/Hook.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @hidden
|
|
3
|
-
*/
|
|
4
|
-
export declare enum Hook {
|
|
5
|
-
afterCreate = "afterCreate",
|
|
6
|
-
afterAttach = "afterAttach",
|
|
7
|
-
afterCreationFinalization = "afterCreationFinalization",
|
|
8
|
-
beforeDetach = "beforeDetach",
|
|
9
|
-
beforeDestroy = "beforeDestroy"
|
|
10
|
-
}
|
|
11
|
-
export interface IHooks {
|
|
12
|
-
[Hook.afterCreate]?: () => void;
|
|
13
|
-
[Hook.afterAttach]?: () => void;
|
|
14
|
-
[Hook.beforeDetach]?: () => void;
|
|
15
|
-
[Hook.beforeDestroy]?: () => void;
|
|
16
|
-
}
|
|
17
|
-
export type IHooksGetter<T> = (self: T) => IHooks;
|
package/esm/core/node/Hook.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @hidden
|
|
3
|
-
*/
|
|
4
|
-
export var Hook;
|
|
5
|
-
(function (Hook) {
|
|
6
|
-
Hook["afterCreate"] = "afterCreate";
|
|
7
|
-
Hook["afterAttach"] = "afterAttach";
|
|
8
|
-
Hook["afterCreationFinalization"] = "afterCreationFinalization";
|
|
9
|
-
Hook["beforeDetach"] = "beforeDetach";
|
|
10
|
-
Hook["beforeDestroy"] = "beforeDestroy";
|
|
11
|
-
})(Hook || (Hook = {}));
|
|
12
|
-
//# sourceMappingURL=Hook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Hook.js","sourceRoot":"","sources":["../../../src/core/node/Hook.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,IAMX;AAND,WAAY,IAAI;IACd,mCAA2B,CAAA;IAC3B,mCAA2B,CAAA;IAC3B,+DAAuD,CAAA;IACvD,qCAA6B,CAAA;IAC7B,uCAA+B,CAAA;AACjC,CAAC,EANW,IAAI,KAAJ,IAAI,QAMf","sourcesContent":["/**\n * @hidden\n */\nexport enum Hook {\n afterCreate = \"afterCreate\",\n afterAttach = \"afterAttach\",\n afterCreationFinalization = \"afterCreationFinalization\",\n beforeDetach = \"beforeDetach\",\n beforeDestroy = \"beforeDestroy\"\n}\n\nexport interface IHooks {\n [Hook.afterCreate]?: () => void\n [Hook.afterAttach]?: () => void\n [Hook.beforeDetach]?: () => void\n [Hook.beforeDestroy]?: () => void\n}\n\nexport type IHooksGetter<T> = (self: T) => IHooks\n"]}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type AnyNode, type AnyObjectNode, ComplexType, ObjectNode, ScalarNode, SimpleType } from "../../internal.ts";
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
* @hidden
|
|
5
|
-
*/
|
|
6
|
-
export declare function createObjectNode<C, S, T>(type: ComplexType<C, S, T>, parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: C | T): ObjectNode<C, S, T>;
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
* @hidden
|
|
10
|
-
*/
|
|
11
|
-
export declare function createScalarNode<C, S, T>(type: SimpleType<C, S, T>, parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: C): ScalarNode<C, S, T>;
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
* @hidden
|
|
15
|
-
*/
|
|
16
|
-
export declare function isNode(value: any): value is AnyNode;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ObjectNode, ScalarNode, fail, getStateTreeNodeSafe } from "../../internal.js";
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
* @hidden
|
|
5
|
-
*/
|
|
6
|
-
export function createObjectNode(type, parent, subpath, environment, initialValue) {
|
|
7
|
-
const existingNode = getStateTreeNodeSafe(initialValue);
|
|
8
|
-
if (existingNode) {
|
|
9
|
-
if (existingNode.parent) {
|
|
10
|
-
// istanbul ignore next
|
|
11
|
-
throw fail(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${parent ? parent.path : ""}/${subpath}', but it lives already at '${existingNode.path}'`);
|
|
12
|
-
}
|
|
13
|
-
if (parent) {
|
|
14
|
-
existingNode.setParent(parent, subpath);
|
|
15
|
-
}
|
|
16
|
-
// else it already has no parent since it is a pre-requisite
|
|
17
|
-
return existingNode;
|
|
18
|
-
}
|
|
19
|
-
// not a node, a snapshot
|
|
20
|
-
return new ObjectNode(type, parent, subpath, environment, initialValue);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @internal
|
|
24
|
-
* @hidden
|
|
25
|
-
*/
|
|
26
|
-
export function createScalarNode(type, parent, subpath, environment, initialValue) {
|
|
27
|
-
return new ScalarNode(type, parent, subpath, environment, initialValue);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
* @hidden
|
|
32
|
-
*/
|
|
33
|
-
export function isNode(value) {
|
|
34
|
-
return value instanceof ScalarNode || value instanceof ObjectNode;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=create-node.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-node.js","sourceRoot":"","sources":["../../../src/core/node/create-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,UAAU,EACV,UAAU,EAEV,IAAI,EACJ,oBAAoB,EACrB,MAAM,mBAAmB,CAAA;AAE1B;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAA0B,EAC1B,MAA4B,EAC5B,OAAe,EACf,WAAgB,EAChB,YAAmB;IAEnB,MAAM,YAAY,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAA;IACvD,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;YACxB,uBAAuB;YACvB,MAAM,IAAI,CACR,+HACE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EACzB,IAAI,OAAO,+BAA+B,YAAY,CAAC,IAAI,GAAG,CAC/D,CAAA;QACH,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,YAAY,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACzC,CAAC;QACD,4DAA4D;QAE5D,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,yBAAyB;IACzB,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,YAAiB,CAAC,CAAA;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAyB,EACzB,MAA4B,EAC5B,OAAe,EACf,WAAgB,EAChB,YAAe;IAEf,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;AACzE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,KAAU;IAC/B,OAAO,KAAK,YAAY,UAAU,IAAI,KAAK,YAAY,UAAU,CAAA;AACnE,CAAC","sourcesContent":["import {\n type AnyNode,\n type AnyObjectNode,\n ComplexType,\n ObjectNode,\n ScalarNode,\n SimpleType,\n fail,\n getStateTreeNodeSafe\n} from \"../../internal.ts\"\n\n/**\n * @internal\n * @hidden\n */\nexport function createObjectNode<C, S, T>(\n type: ComplexType<C, S, T>,\n parent: AnyObjectNode | null,\n subpath: string,\n environment: any,\n initialValue: C | T\n): ObjectNode<C, S, T> {\n const existingNode = getStateTreeNodeSafe(initialValue)\n if (existingNode) {\n if (existingNode.parent) {\n // istanbul ignore next\n throw fail(\n `Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${\n parent ? parent.path : \"\"\n }/${subpath}', but it lives already at '${existingNode.path}'`\n )\n }\n\n if (parent) {\n existingNode.setParent(parent, subpath)\n }\n // else it already has no parent since it is a pre-requisite\n\n return existingNode\n }\n\n // not a node, a snapshot\n return new ObjectNode(type, parent, subpath, environment, initialValue as C)\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function createScalarNode<C, S, T>(\n type: SimpleType<C, S, T>,\n parent: AnyObjectNode | null,\n subpath: string,\n environment: any,\n initialValue: C\n): ScalarNode<C, S, T> {\n return new ScalarNode(type, parent, subpath, environment, initialValue)\n}\n\n/**\n * @internal\n * @hidden\n */\nexport function isNode(value: any): value is AnyNode {\n return value instanceof ScalarNode || value instanceof ObjectNode\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type AnyObjectNode, type IAnyComplexType, ObjectNode } from "../../internal.ts";
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
* @hidden
|
|
5
|
-
*/
|
|
6
|
-
export declare class IdentifierCache {
|
|
7
|
-
private cacheId;
|
|
8
|
-
private cache;
|
|
9
|
-
private lastCacheModificationPerId;
|
|
10
|
-
constructor();
|
|
11
|
-
private updateLastCacheModificationPerId;
|
|
12
|
-
getLastCacheModificationPerId(identifier: string): string;
|
|
13
|
-
addNodeToCache(node: AnyObjectNode, lastCacheUpdate?: boolean): void;
|
|
14
|
-
mergeCache(node: AnyObjectNode): void;
|
|
15
|
-
notifyDied(node: AnyObjectNode): void;
|
|
16
|
-
splitCache(splitNode: AnyObjectNode): IdentifierCache;
|
|
17
|
-
has(type: IAnyComplexType, identifier: string): boolean;
|
|
18
|
-
resolve<IT extends IAnyComplexType>(type: IT, identifier: string): ObjectNode<IT["CreationType"], IT["SnapshotType"], IT["TypeWithoutSTN"]> | null;
|
|
19
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { entries, observable, values } from "mobx";
|
|
2
|
-
import { fail, mobxShallow } from "../../internal.js";
|
|
3
|
-
let identifierCacheId = 0;
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
* @hidden
|
|
7
|
-
*/
|
|
8
|
-
export class IdentifierCache {
|
|
9
|
-
cacheId = identifierCacheId++;
|
|
10
|
-
// n.b. in cache all identifiers are normalized to strings
|
|
11
|
-
cache = observable.map();
|
|
12
|
-
// last time the cache (array) for a given time changed
|
|
13
|
-
// n.b. it is not really the time, but just an integer that gets increased after each modification to the array
|
|
14
|
-
lastCacheModificationPerId = observable.map();
|
|
15
|
-
constructor() { }
|
|
16
|
-
updateLastCacheModificationPerId(identifier) {
|
|
17
|
-
const lcm = this.lastCacheModificationPerId.get(identifier);
|
|
18
|
-
// we start at 1 since 0 means no update since cache creation
|
|
19
|
-
this.lastCacheModificationPerId.set(identifier, lcm === undefined ? 1 : lcm + 1);
|
|
20
|
-
}
|
|
21
|
-
getLastCacheModificationPerId(identifier) {
|
|
22
|
-
const modificationId = this.lastCacheModificationPerId.get(identifier) || 0;
|
|
23
|
-
return `${this.cacheId}-${modificationId}`;
|
|
24
|
-
}
|
|
25
|
-
addNodeToCache(node, lastCacheUpdate = true) {
|
|
26
|
-
if (node.identifierAttribute) {
|
|
27
|
-
const identifier = node.identifier;
|
|
28
|
-
if (!this.cache.has(identifier)) {
|
|
29
|
-
this.cache.set(identifier, observable.array([], mobxShallow));
|
|
30
|
-
}
|
|
31
|
-
const set = this.cache.get(identifier);
|
|
32
|
-
if (set.indexOf(node) !== -1) {
|
|
33
|
-
throw fail(`Already registered`);
|
|
34
|
-
}
|
|
35
|
-
set.push(node);
|
|
36
|
-
if (lastCacheUpdate) {
|
|
37
|
-
this.updateLastCacheModificationPerId(identifier);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
mergeCache(node) {
|
|
42
|
-
values(node.identifierCache.cache).forEach(nodes => nodes.forEach(child => {
|
|
43
|
-
this.addNodeToCache(child);
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
notifyDied(node) {
|
|
47
|
-
if (node.identifierAttribute) {
|
|
48
|
-
const id = node.identifier;
|
|
49
|
-
const set = this.cache.get(id);
|
|
50
|
-
if (set) {
|
|
51
|
-
set.remove(node);
|
|
52
|
-
// remove empty sets from cache
|
|
53
|
-
if (!set.length) {
|
|
54
|
-
this.cache.delete(id);
|
|
55
|
-
}
|
|
56
|
-
this.updateLastCacheModificationPerId(node.identifier);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
splitCache(splitNode) {
|
|
61
|
-
const newCache = new IdentifierCache();
|
|
62
|
-
// The slash is added here so we only match children of the splitNode. In version 5.1.8 and
|
|
63
|
-
// earlier there was no trailing slash, so non children that started with the same path string
|
|
64
|
-
// were being matched incorrectly.
|
|
65
|
-
const basePath = splitNode.path + "/";
|
|
66
|
-
entries(this.cache).forEach(([id, nodes]) => {
|
|
67
|
-
let modified = false;
|
|
68
|
-
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
69
|
-
const node = nodes[i];
|
|
70
|
-
if (node === splitNode || node.path.indexOf(basePath) === 0) {
|
|
71
|
-
newCache.addNodeToCache(node, false); // no need to update lastUpdated since it is a whole new cache
|
|
72
|
-
nodes.splice(i, 1);
|
|
73
|
-
// remove empty sets from cache
|
|
74
|
-
if (!nodes.length) {
|
|
75
|
-
this.cache.delete(id);
|
|
76
|
-
}
|
|
77
|
-
modified = true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (modified) {
|
|
81
|
-
this.updateLastCacheModificationPerId(id);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return newCache;
|
|
85
|
-
}
|
|
86
|
-
has(type, identifier) {
|
|
87
|
-
const set = this.cache.get(identifier);
|
|
88
|
-
if (!set) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
return set.some(candidate => type.isAssignableFrom(candidate.type));
|
|
92
|
-
}
|
|
93
|
-
resolve(type, identifier) {
|
|
94
|
-
const set = this.cache.get(identifier);
|
|
95
|
-
if (!set) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
const matches = set.filter(candidate => type.isAssignableFrom(candidate.type));
|
|
99
|
-
switch (matches.length) {
|
|
100
|
-
case 0:
|
|
101
|
-
return null;
|
|
102
|
-
case 1:
|
|
103
|
-
return matches[0];
|
|
104
|
-
default:
|
|
105
|
-
throw fail(`Cannot resolve a reference to type '${type.name}' with id: '${identifier}' unambigously, there are multiple candidates: ${matches
|
|
106
|
-
.map(n => n.path)
|
|
107
|
-
.join(", ")}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=identifier-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identifier-cache.js","sourceRoot":"","sources":["../../../src/core/node/identifier-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAEzE,OAAO,EAIL,IAAI,EACJ,WAAW,EACZ,MAAM,mBAAmB,CAAA;AAE1B,IAAI,iBAAiB,GAAG,CAAC,CAAA;AAEzB;;;GAGG;AACH,MAAM,OAAO,eAAe;IAClB,OAAO,GAAG,iBAAiB,EAAE,CAAA;IAErC,0DAA0D;IAClD,KAAK,GAAG,UAAU,CAAC,GAAG,EAA2C,CAAA;IAEzE,uDAAuD;IACvD,+GAA+G;IACvG,0BAA0B,GAAG,UAAU,CAAC,GAAG,EAAkB,CAAA;IAErE,gBAAe,CAAC;IAER,gCAAgC,CAAC,UAAkB;QACzD,MAAM,GAAG,GAAG,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAC3D,6DAA6D;QAC7D,IAAI,CAAC,0BAA0B,CAAC,GAAG,CACjC,UAAU,EACV,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAChC,CAAA;IACH,CAAC;IAED,6BAA6B,CAAC,UAAkB;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QAC3E,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,cAAc,EAAE,CAAA;IAC5C,CAAC;IAED,cAAc,CAAC,IAAmB,EAAE,eAAe,GAAG,IAAI;QACxD,IAAI,IAAI,CAAC,mBAAmB,EAAE,C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QACF,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,GAAG,CAAC,IAAqB,EAAE,UAAkB;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACtC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IACrE,CAAC;IAED,OAAO,CACL,IAAQ,EACR,UAAkB;QAMlB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACtC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,IAAI,CAAA;QACb,CAAC;QACD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CACrC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CACtC,CAAA;QACD,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;YACvB,KAAK,CAAC;gBACJ,OAAO,IAAI,CAAA;YACb,KAAK,CAAC;gBACJ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAA;YACnB;gBACE,MAAM,IAAI,CACR,uCACE,IAAI,CAAC,IACP,eAAe,UAAU,kDAAkD,OAAO;qBAC/E,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;qBAChB,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAA;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { type IObservableArray, entries, observable, values } from \"mobx\"\n\nimport {\n type AnyObjectNode,\n type IAnyComplexType,\n ObjectNode,\n fail,\n mobxShallow\n} from \"../../internal.ts\"\n\nlet identifierCacheId = 0\n\n/**\n * @internal\n * @hidden\n */\nexport class IdentifierCache {\n private cacheId = identifierCacheId++\n\n // n.b. in cache all identifiers are normalized to strings\n private cache = observable.map<string, IObservableArray<AnyObjectNode>>()\n\n // last time the cache (array) for a given time changed\n // n.b. it is not really the time, but just an integer that gets increased after each modification to the array\n private lastCacheModificationPerId = observable.map<string, number>()\n\n constructor() {}\n\n private updateLastCacheModificationPerId(identifier: string) {\n const lcm = this.lastCacheModificationPerId.get(identifier)\n // we start at 1 since 0 means no update since cache creation\n this.lastCacheModificationPerId.set(\n identifier,\n lcm === undefined ? 1 : lcm + 1\n )\n }\n\n getLastCacheModificationPerId(identifier: string): string {\n const modificationId = this.lastCacheModificationPerId.get(identifier) || 0\n return `${this.cacheId}-${modificationId}`\n }\n\n addNodeToCache(node: AnyObjectNode, lastCacheUpdate = true): void {\n if (node.identifierAttribute) {\n const identifier = node.identifier!\n if (!this.cache.has(identifier)) {\n this.cache.set(\n identifier,\n observable.array<AnyObjectNode>([], mobxShallow)\n )\n }\n const set = this.cache.get(identifier)!\n if (set.indexOf(node) !== -1) {\n throw fail(`Already registered`)\n }\n set.push(node)\n if (lastCacheUpdate) {\n this.updateLastCacheModificationPerId(identifier)\n }\n }\n }\n\n mergeCache(node: AnyObjectNode) {\n values(node.identifierCache!.cache).forEach(nodes =>\n nodes.forEach(child => {\n this.addNodeToCache(child)\n })\n )\n }\n\n notifyDied(node: AnyObjectNode) {\n if (node.identifierAttribute) {\n const id = node.identifier!\n const set = this.cache.get(id)\n if (set) {\n set.remove(node)\n // remove empty sets from cache\n if (!set.length) {\n this.cache.delete(id)\n }\n this.updateLastCacheModificationPerId(node.identifier!)\n }\n }\n }\n\n splitCache(splitNode: AnyObjectNode): IdentifierCache {\n const newCache = new IdentifierCache()\n // The slash is added here so we only match children of the splitNode. In version 5.1.8 and\n // earlier there was no trailing slash, so non children that started with the same path string\n // were being matched incorrectly.\n const basePath = splitNode.path + \"/\"\n entries(this.cache).forEach(([id, nodes]) => {\n let modified = false\n for (let i = nodes.length - 1; i >= 0; i--) {\n const node = nodes[i]\n if (node === splitNode || node.path.indexOf(basePath) === 0) {\n newCache.addNodeToCache(node, false) // no need to update lastUpdated since it is a whole new cache\n nodes.splice(i, 1)\n // remove empty sets from cache\n if (!nodes.length) {\n this.cache.delete(id)\n }\n modified = true\n }\n }\n if (modified) {\n this.updateLastCacheModificationPerId(id)\n }\n })\n return newCache\n }\n\n has(type: IAnyComplexType, identifier: string): boolean {\n const set = this.cache.get(identifier)\n if (!set) {\n return false\n }\n return set.some(candidate => type.isAssignableFrom(candidate.type))\n }\n\n resolve<IT extends IAnyComplexType>(\n type: IT,\n identifier: string\n ): ObjectNode<\n IT[\"CreationType\"],\n IT[\"SnapshotType\"],\n IT[\"TypeWithoutSTN\"]\n > | null {\n const set = this.cache.get(identifier)\n if (!set) {\n return null\n }\n const matches = set.filter(candidate =>\n type.isAssignableFrom(candidate.type)\n )\n switch (matches.length) {\n case 0:\n return null\n case 1:\n return matches[0]\n default:\n throw fail(\n `Cannot resolve a reference to type '${\n type.name\n }' with id: '${identifier}' unambigously, there are multiple candidates: ${matches\n .map(n => n.path)\n .join(\", \")}`\n )\n }\n }\n}\n"]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines what MST should do when running into reads / writes to objects that have died.
|
|
3
|
-
* - `"warn"`: Print a warning (default).
|
|
4
|
-
* - `"error"`: Throw an exception.
|
|
5
|
-
* - "`ignore`": Do nothing.
|
|
6
|
-
*/
|
|
7
|
-
export type LivelinessMode = "warn" | "error" | "ignore";
|
|
8
|
-
/**
|
|
9
|
-
* Defines what MST should do when running into reads / writes to objects that have died.
|
|
10
|
-
* By default it will print a warning.
|
|
11
|
-
* Use the `"error"` option to easy debugging to see where the error was thrown and when the offending read / write took place
|
|
12
|
-
*
|
|
13
|
-
* @param mode `"warn"`, `"error"` or `"ignore"`
|
|
14
|
-
*/
|
|
15
|
-
export declare function setLivelinessChecking(mode: LivelinessMode): void;
|
|
16
|
-
/**
|
|
17
|
-
* Returns the current liveliness checking mode.
|
|
18
|
-
*
|
|
19
|
-
* @returns `"warn"`, `"error"` or `"ignore"`
|
|
20
|
-
*/
|
|
21
|
-
export declare function getLivelinessChecking(): LivelinessMode;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated use LivelinessMode instead
|
|
24
|
-
* @hidden
|
|
25
|
-
*/
|
|
26
|
-
export type LivelynessMode = LivelinessMode;
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated use setLivelinessChecking instead
|
|
29
|
-
* @hidden
|
|
30
|
-
*
|
|
31
|
-
* Defines what MST should do when running into reads / writes to objects that have died.
|
|
32
|
-
* By default it will print a warning.
|
|
33
|
-
* Use the `"error"` option to easy debugging to see where the error was thrown and when the offending read / write took place
|
|
34
|
-
*
|
|
35
|
-
* @param mode `"warn"`, `"error"` or `"ignore"`
|
|
36
|
-
*/
|
|
37
|
-
export declare function setLivelynessChecking(mode: LivelinessMode): void;
|