mobx-keystone 2.0.0 → 2.2.0
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/CHANGELOG.md +33 -0
- package/README.md +1 -1
- package/dist/mobx-keystone.esm.js +2561 -1214
- package/dist/mobx-keystone.esm.mjs +2561 -1214
- package/dist/mobx-keystone.umd.js +2566 -1220
- package/dist/types/actionMiddlewares/transactionMiddleware.d.ts +1 -1
- package/dist/types/actionMiddlewares/undoMiddleware.d.ts +11 -12
- package/dist/types/modelShared/modelDecorator.d.ts +5 -2
- package/dist/types/modelShared/prop.d.ts +42 -29
- package/dist/types/parent/arrayPaths.d.ts +1 -0
- package/dist/types/parent/treeOrder.d.ts +1 -0
- package/dist/types/patch/applyPatches.d.ts +2 -1
- package/dist/types/ref/Ref.d.ts +1 -4
- package/dist/types/ref/modelRefIdIndex.d.ts +1 -0
- package/dist/types/ref/nodesById.d.ts +1 -0
- package/dist/types/ref/refIdIndex.d.ts +1 -0
- package/dist/types/snapshot/SnapshotOf.d.ts +4 -4
- package/dist/types/snapshot/applySnapshot.d.ts +2 -1
- package/dist/types/snapshot/fromSnapshot.d.ts +2 -5
- package/dist/types/snapshot/getSnapshot.d.ts +1 -1
- package/dist/types/tweaker/changeRollback.d.ts +1 -0
- package/dist/types/tweaker/tweakedChangeListeners.d.ts +1 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/schemas.d.ts +41 -37
- package/dist/types/types/tProp.d.ts +12 -6
- package/dist/types/types/types.d.ts +6 -6
- package/dist/types/types/utility/typeToStoredData.d.ts +14 -10
- package/dist/types/types/utility/typesCodecCore.d.ts +3 -0
- package/dist/types/utils/ModelPool.d.ts +7 -2
- package/dist/types/utils/chunks.d.ts +1 -0
- package/dist/types/utils/types.d.ts +6 -0
- package/dist/types/wrappers/ArraySet.d.ts +1 -0
- package/package.json +5 -3
- package/src/action/modelFlow.ts +35 -66
- package/src/actionMiddlewares/actionTrackingMiddleware.ts +41 -71
- package/src/actionMiddlewares/transactionMiddleware.ts +41 -42
- package/src/actionMiddlewares/undoMiddleware.ts +63 -35
- package/src/context/context.ts +15 -36
- package/src/dataModel/utils.ts +5 -28
- package/src/deepChange/onDeepChange.ts +44 -126
- package/src/model/BaseModel.ts +7 -5
- package/src/model/utils.ts +5 -10
- package/src/modelShared/modelDecorator.ts +16 -30
- package/src/modelShared/prop.ts +115 -111
- package/src/modelShared/sharedInternalModel.ts +2 -2
- package/src/parent/arrayPaths.ts +239 -0
- package/src/parent/coreObjectChildren.ts +300 -48
- package/src/parent/onChildAttachedTo.ts +130 -44
- package/src/parent/path.ts +10 -12
- package/src/parent/setParent.ts +27 -15
- package/src/parent/treeOrder.ts +53 -0
- package/src/parent/walkTree.ts +0 -73
- package/src/patch/applyPatches.ts +31 -26
- package/src/patch/patchRecorder.ts +13 -28
- package/src/ref/core.ts +69 -46
- package/src/ref/modelRefIdIndex.ts +131 -0
- package/src/ref/nodesById.ts +60 -0
- package/src/ref/refIdIndex.ts +209 -0
- package/src/rootStore/rootStore.ts +1 -3
- package/src/snapshot/SnapshotOf.ts +24 -48
- package/src/snapshot/applySnapshot.ts +27 -19
- package/src/snapshot/fromPlainObjectSnapshot.ts +3 -8
- package/src/snapshot/fromSnapshot.ts +12 -9
- package/src/snapshot/getSnapshot.ts +1 -1
- package/src/snapshot/internal.ts +67 -12
- package/src/snapshot/reconcileModelSnapshot.ts +5 -3
- package/src/snapshot/reconcilePlainObjectSnapshot.ts +3 -1
- package/src/treeUtils/draft.ts +6 -1
- package/src/treeUtils/sandbox.ts +10 -7
- package/src/tweaker/changeRollback.ts +218 -0
- package/src/tweaker/core.ts +33 -20
- package/src/tweaker/treeNodeMetadata.ts +12 -2
- package/src/tweaker/tweak.ts +181 -18
- package/src/tweaker/tweakArray.ts +127 -77
- package/src/tweaker/tweakPlainObject.ts +65 -46
- package/src/tweaker/tweakedChangeListeners.ts +61 -0
- package/src/tweaker/typeChecking.ts +5 -104
- package/src/types/arrayBased/typesArray.ts +23 -30
- package/src/types/arrayBased/typesTuple.ts +16 -25
- package/src/types/createCachedTypeCheck.ts +509 -94
- package/src/types/index.ts +1 -0
- package/src/types/objectBased/typesDataModelData.ts +7 -8
- package/src/types/objectBased/typesObject.ts +11 -15
- package/src/types/objectBased/typesRecord.ts +12 -19
- package/src/types/schemas.ts +59 -71
- package/src/types/tProp.ts +29 -29
- package/src/types/utility/typeToStoredData.ts +22 -21
- package/src/types/utility/typesCodecCore.ts +5 -0
- package/src/types/utility/typesCodecSupport.ts +3 -3
- package/src/types/utility/typesMap.ts +43 -51
- package/src/types/utility/typesRefinement.ts +7 -8
- package/src/types/utility/typesSkipCheck.ts +7 -8
- package/src/types/utility/typesTag.ts +7 -8
- package/src/utils/ModelPool.ts +76 -37
- package/src/utils/chunks.ts +271 -0
- package/src/utils/decorators.ts +5 -5
- package/src/utils/index.ts +38 -20
- package/src/utils/types.ts +5 -0
- package/src/wrappers/ArraySet.ts +27 -14
- package/src/wrappers/ObjectMap.ts +1 -6
- package/src/wrappers/asMap.ts +1 -21
- package/src/wrappers/asSet.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
- Now requires TypeScript 5.4 or newer (the types use the built-in `NoInfer`).
|
|
6
|
+
- Faster TypeScript type-checking of models and runtime types: the snapshot, model data and `types.object` type mappings now create far fewer type instantiations (about 35% fewer in a typical model-heavy project), with no change to the resulting types. `tProp` defaults, `fromSnapshot(type, snapshot)`, `getSnapshot(type, value)` and `applySnapshot` no longer infer their type parameter from the data / snapshot argument, which makes those calls much cheaper to type-check (e.g. about 40% fewer instantiations for a typed `fromSnapshot` call). The `@model` decorator also no longer computes the creation data type of the decorated class. A typed `fromSnapshot(type, snapshot)` call now also accepts the output snapshot type of `type` (which must always round-trip, as with `applySnapshot` and the untyped `fromSnapshot(snapshot)`), so round trips such as `fromSnapshot(M, getSnapshot(m))` no longer compare the output and input snapshot types (about 65% cheaper to type-check).
|
|
7
|
+
- Smaller and faster declaration (`.d.ts`) emit for exported model classes: the types of `idProp` and `tProp` properties (`TypedModelIdProp`, `TypedMaybeOptionalModelProp`, `TypedOptionalModelProp`) and `CodecFromEncoded` are now exported, so emitted declarations reference them by name instead of expanding them inline.
|
|
8
|
+
- Fixed the types of `tProp` codec props (e.g. `tProp(types.dateAsTimestamp)`) after `.withSetter()`, `.withSnapshotProcessor()` or `.withTransform()`: `$` and snapshots now use the encoded type (e.g. `number`) instead of the runtime type (e.g. `Date`). The new `ModelPropWithSetter`, `ModelPropWithSnapshotProcessor` and `ModelPropWithTransform` types describe the props these modifiers return.
|
|
9
|
+
- Fixed `applySnapshot` throwing when the snapshot adds an object under a key named like an `Object.prototype` member (e.g. `toString` or `constructor`).
|
|
10
|
+
- Fixed `Draft`'s `isDirty` not being cached and `commit` / `reset` not running as MobX actions with MobX 6.
|
|
11
|
+
- `fromSnapshot` (and `cloneTreeValue` for plain objects / arrays) now reports a clear error when the snapshot contains tree nodes, instead of a generic "unsupported snapshot".
|
|
12
|
+
- Fixed `ArraySet` set operations (`union`, `intersection`, `isSubsetOf`, etc.) throwing on runtimes without the native ES2025 `Set` methods.
|
|
13
|
+
|
|
14
|
+
## 2.1.0
|
|
15
|
+
|
|
16
|
+
- [BREAKING CHANGE] `UndoStore` keeps undo/redo events as frozen data, making recording ~4x faster and undo/redo ~3x faster:
|
|
17
|
+
- Snapshots and patches store events as `{ $frozen: true, data: event }`. Older snapshots still load, but earlier versions cannot load newer ones.
|
|
18
|
+
- Events passed when creating an `UndoStore` must be wrapped with `frozen(event)`.
|
|
19
|
+
- `undoQueue` / `redoQueue` events are plain objects, and attached states are no longer copied.
|
|
20
|
+
- Performance on large trees: operations that used to rescan or rebuild state for the whole tree now only update what changed (e.g. at 16,000 items, from milliseconds to microseconds):
|
|
21
|
+
- array splices (`shift`, `unshift`, `splice`, `detach`);
|
|
22
|
+
- `rootRef` / `resolveId` and `getRefsResolvingTo`;
|
|
23
|
+
- structural `applyPatches` / `applySnapshot`, which also makes undo/redo no longer quadratic when the `UndoStore` is inside the tracked tree;
|
|
24
|
+
- `getSnapshot` / `onSnapshot` after splices and key changes;
|
|
25
|
+
- `onChildAttachedTo`;
|
|
26
|
+
- runtime type checking of large arrays, records and `ObjectMap`s, and of key changes in deep trees;
|
|
27
|
+
- transactions, which no longer build patches to roll back.
|
|
28
|
+
- Tree nodes use ~30% less memory and are ~15% faster to create. Models without MobX decorators no longer get a MobX observable administration, so `isObservableObject(model)` is now `false` for them.
|
|
29
|
+
- Rejected tree changes (e.g. assigning a `Map`, a node that already has a parent, or the same node twice) now leave the tree unchanged instead of half-changed.
|
|
30
|
+
- Inserting an array item at its own index (e.g. `arr.unshift(arr[0])`) now throws instead of putting the same node in the array twice.
|
|
31
|
+
- `applySnapshot` / `applyPatches` now undo their changes when they throw partway.
|
|
32
|
+
- Fixed `transactionMiddleware` / `@transaction` not fully restoring the state when the failed action detached, changed and reattached a model.
|
|
33
|
+
- Fixed `applySnapshot` / `applyPatches` not reusing a model whose id had changed.
|
|
34
|
+
- Fixed `onAttachedToRootStore` not being called for models inside a plain tree node attached to a root store.
|
|
35
|
+
|
|
3
36
|
## 2.0.0
|
|
4
37
|
|
|
5
38
|
- [BREAKING CHANGE] Preserve repeated property names and array indexes in type-check error paths when validating an attached subtree. Paths supplied to `TypeCheckError` and `TypeCheckErrorFailure` are now consistently treated as relative to the checked value; manually supplied rooted paths are no longer detected automatically.
|
package/README.md
CHANGED
|
@@ -136,7 +136,7 @@ This library requires a modern JavaScript environment with support for:
|
|
|
136
136
|
|
|
137
137
|
In practice, this covers current browsers and Node.js releases, but not Internet Explorer.
|
|
138
138
|
|
|
139
|
-
TypeScript 5.
|
|
139
|
+
When using TypeScript, version 5.4 or newer is required. Legacy decorators remain supported by `mobx-keystone`; see the [installation guide](https://mobx-keystone.js.org/installation) for the required compiler configuration and the MobX 7 compatibility note.
|
|
140
140
|
|
|
141
141
|
## Installation
|
|
142
142
|
|