mobx-keystone 1.20.0 → 1.22.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 +864 -853
- package/README.md +61 -61
- package/dist/mobx-keystone.esm.js +11336 -11148
- package/dist/mobx-keystone.esm.mjs +11336 -11148
- package/dist/mobx-keystone.umd.js +12229 -11738
- package/dist/types/actionMiddlewares/undoMiddleware.d.ts +1 -1
- package/dist/types/modelShared/prop.d.ts +5 -0
- package/dist/types/redux/connectReduxDevTools.d.ts +17 -4
- package/dist/types/ref/Ref.d.ts +1 -1
- package/dist/types/treeUtils/sandbox.d.ts +1 -1
- package/dist/types/types/TypeChecker.d.ts +1 -1
- package/dist/types/types/arrayBased/typesArray.d.ts +1 -1
- package/dist/types/types/arrayBased/typesTuple.d.ts +1 -1
- package/dist/types/types/objectBased/typesArraySet.d.ts +1 -1
- package/dist/types/types/objectBased/typesDataModelData.d.ts +1 -1
- package/dist/types/types/objectBased/typesModel.d.ts +1 -1
- package/dist/types/types/objectBased/typesObject.d.ts +3 -3
- package/dist/types/types/objectBased/typesObjectMap.d.ts +1 -1
- package/dist/types/types/objectBased/typesRecord.d.ts +1 -1
- package/dist/types/types/primitiveBased/typesPrimitive.d.ts +1 -1
- package/dist/types/types/types.d.ts +3 -3
- package/dist/types/types/utility/typesCodec.d.ts +1 -6
- package/dist/types/types/utility/typesCodecCore.d.ts +1 -1
- package/dist/types/types/utility/typesOr.d.ts +1 -1
- package/dist/types/types/utility/typesRefinement.d.ts +1 -1
- package/dist/types/types/utility/typesSkipCheck.d.ts +1 -1
- package/dist/types/types/utility/typesTag.d.ts +1 -1
- package/dist/types/wrappers/ObjectMap.d.ts +2 -0
- package/dist/types/wrappers/asMap.d.ts +10 -6
- package/package.json +14 -12
- package/src/action/applyAction.ts +125 -114
- package/src/action/applyMethodCall.ts +37 -37
- package/src/action/isModelAction.ts +16 -16
- package/src/action/middleware.ts +137 -137
- package/src/action/modelFlow.ts +240 -240
- package/src/action/modelFlowPromiseGenerator.ts +127 -125
- package/src/action/pendingActions.ts +42 -42
- package/src/action/wrapInAction.ts +156 -156
- package/src/actionMiddlewares/actionSerialization/actionSerialization.ts +1 -1
- package/src/actionMiddlewares/actionSerialization/applySerializedAction.ts +172 -172
- package/src/actionMiddlewares/actionSerialization/arraySerializer.ts +20 -20
- package/src/actionMiddlewares/actionSerialization/dateSerializer.ts +17 -17
- package/src/actionMiddlewares/actionSerialization/mapSerializer.ts +42 -42
- package/src/actionMiddlewares/actionSerialization/objectPathSerializer.ts +50 -50
- package/src/actionMiddlewares/actionSerialization/objectSnapshotSerializer.ts +21 -21
- package/src/actionMiddlewares/actionSerialization/plainObjectSerializer.ts +24 -32
- package/src/actionMiddlewares/actionSerialization/primitiveSerializer.ts +51 -51
- package/src/actionMiddlewares/actionSerialization/setSerializer.ts +37 -37
- package/src/actionMiddlewares/actionTrackingMiddleware.ts +3 -3
- package/src/actionMiddlewares/onActionMiddleware.ts +2 -2
- package/src/actionMiddlewares/readonlyMiddleware.ts +2 -2
- package/src/actionMiddlewares/transactionMiddleware.ts +4 -4
- package/src/actionMiddlewares/undoMiddleware.ts +804 -796
- package/src/actionMiddlewares/utils.ts +2 -2
- package/src/computedTree/computedTree.ts +143 -143
- package/src/context/context.ts +1 -1
- package/src/dataModel/BaseDataModel.ts +194 -192
- package/src/dataModel/actions.ts +1 -1
- package/src/dataModel/newDataModel.ts +57 -57
- package/src/deepChange/index.ts +1 -1
- package/src/deepChange/onDeepChange.ts +244 -244
- package/src/frozen/Frozen.ts +146 -146
- package/src/globalConfig/globalConfig.ts +107 -107
- package/src/index.ts +24 -24
- package/src/model/BaseModel.ts +275 -273
- package/src/model/ModelConstructorOptions.ts +15 -15
- package/src/model/getModelMetadata.ts +51 -51
- package/src/model/index.ts +6 -6
- package/src/model/mixins.ts +288 -288
- package/src/model/newModel.ts +301 -301
- package/src/model/utils.ts +249 -249
- package/src/modelShared/modelDecorator.ts +260 -253
- package/src/modelShared/modelInfo.ts +50 -50
- package/src/modelShared/modelSymbols.ts +3 -3
- package/src/modelShared/newModel.ts +25 -25
- package/src/modelShared/prop.ts +713 -684
- package/src/modelShared/sharedInternalModel.ts +427 -417
- package/src/modelShared/utils.ts +24 -24
- package/src/parent/core.ts +65 -65
- package/src/parent/coreObjectChildren.ts +180 -180
- package/src/parent/detach.ts +47 -47
- package/src/parent/findParent.ts +1 -1
- package/src/parent/getChildrenObjects.ts +25 -25
- package/src/parent/path.ts +386 -381
- package/src/parent/setParent.ts +149 -149
- package/src/parent/walkTree.ts +1 -1
- package/src/patch/applyPatches.ts +187 -187
- package/src/patch/jsonPatch.ts +108 -108
- package/src/patch/patchRecorder.ts +6 -1
- package/src/redux/connectReduxDevTools.ts +39 -7
- package/src/redux/redux.ts +6 -2
- package/src/ref/Ref.ts +1 -1
- package/src/ref/core.ts +339 -345
- package/src/ref/customRef.ts +3 -3
- package/src/ref/rootRef.ts +100 -100
- package/src/rootStore/attachDetach.ts +89 -89
- package/src/rootStore/rootStore.ts +1 -1
- package/src/snapshot/SnapshotOf.ts +104 -104
- package/src/snapshot/SnapshotProcessingError.ts +45 -45
- package/src/snapshot/applySnapshot.ts +177 -181
- package/src/snapshot/cloneTreeValue.ts +30 -30
- package/src/snapshot/fromArraySnapshot.ts +27 -33
- package/src/snapshot/fromModelSnapshot.ts +70 -70
- package/src/snapshot/fromPlainObjectSnapshot.ts +47 -42
- package/src/snapshot/fromSnapshot.ts +198 -198
- package/src/snapshot/getSnapshot.ts +80 -79
- package/src/snapshot/index.ts +8 -8
- package/src/snapshot/internal.ts +230 -230
- package/src/snapshot/reconcileArraySnapshot.ts +70 -70
- package/src/snapshot/reconcileModelSnapshot.ts +155 -150
- package/src/snapshot/reconcilePlainObjectSnapshot.ts +72 -72
- package/src/snapshot/reconcileSnapshot.ts +88 -88
- package/src/standardActions/actions.ts +64 -64
- package/src/standardActions/objectActions.ts +60 -60
- package/src/transforms/ImmutableDate.ts +93 -93
- package/src/transforms/asMap.ts +50 -50
- package/src/transforms/asSet.ts +22 -22
- package/src/transforms/bigint.ts +20 -20
- package/src/transforms/date.ts +40 -40
- package/src/treeUtils/deepEquals.ts +55 -55
- package/src/treeUtils/sandbox.ts +6 -3
- package/src/tweaker/TweakerPriority.ts +9 -9
- package/src/tweaker/tweak.ts +4 -3
- package/src/tweaker/tweakArray.ts +530 -475
- package/src/tweaker/tweakFrozen.ts +42 -42
- package/src/tweaker/tweakModel.ts +1 -1
- package/src/tweaker/tweakPlainObject.ts +355 -355
- package/src/tweaker/typeChecking.ts +101 -101
- package/src/types/SnapshotTypeMismatchError.ts +46 -46
- package/src/types/TypeCheckError.ts +183 -184
- package/src/types/TypeChecker.ts +202 -185
- package/src/types/arrayBased/typesArray.ts +136 -137
- package/src/types/arrayBased/typesTuple.ts +138 -139
- package/src/types/createPerEntryCachedCheck.ts +166 -160
- package/src/types/index.ts +6 -6
- package/src/types/objectBased/typesArraySet.ts +133 -134
- package/src/types/objectBased/typesDataModelData.ts +203 -204
- package/src/types/objectBased/typesModel.ts +220 -221
- package/src/types/objectBased/typesObject.ts +308 -310
- package/src/types/objectBased/typesObjectMap.ts +142 -143
- package/src/types/objectBased/typesRecord.ts +156 -157
- package/src/types/objectBased/typesRef.ts +89 -89
- package/src/types/primitiveBased/typesEnum.ts +63 -63
- package/src/types/primitiveBased/typesPrimitive.ts +219 -220
- package/src/types/registerDefaultStandardTypeResolvers.ts +21 -21
- package/src/types/resolveTypeChecker.ts +78 -78
- package/src/types/schemas.ts +208 -208
- package/src/types/tProp.ts +277 -268
- package/src/types/typeCheck.ts +21 -21
- package/src/types/typeCheckErrorUtils.ts +23 -23
- package/src/types/types.ts +142 -142
- package/src/types/utility/typeToStoredData.ts +37 -37
- package/src/types/utility/typesBigInt.ts +15 -15
- package/src/types/utility/typesCodec.ts +41 -38
- package/src/types/utility/typesCodecCore.ts +178 -178
- package/src/types/utility/typesCodecSupport.ts +806 -806
- package/src/types/utility/typesDate.ts +27 -27
- package/src/types/utility/typesMap.ts +253 -222
- package/src/types/utility/typesOr.ts +263 -259
- package/src/types/utility/typesRefinement.ts +131 -125
- package/src/types/utility/typesSet.ts +110 -110
- package/src/types/utility/typesSkipCheck.ts +69 -70
- package/src/types/utility/typesTag.ts +88 -82
- package/src/types/utility/typesUnchecked.ts +40 -40
- package/src/utils/AnyFunction.ts +4 -4
- package/src/utils/ModelPool.ts +59 -59
- package/src/utils/chainFns.ts +18 -18
- package/src/utils/decorators.ts +274 -274
- package/src/utils/errorDiagnostics.ts +204 -204
- package/src/utils/index.ts +443 -372
- package/src/wrappers/ArraySet.ts +156 -156
- package/src/wrappers/ObjectMap.ts +155 -136
- package/src/wrappers/asMap.ts +65 -30
- package/src/wrappers/asSet.ts +3 -3
package/README.md
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="./apps/site/static/img/logo.png" height="128" />
|
|
3
|
-
<h1 align="center">mobx-keystone</h1>
|
|
4
|
-
</p>
|
|
5
|
-
<p align="center">
|
|
6
|
-
<i>A MobX powered state management solution based on data trees with first-class support for TypeScript, snapshots, patches and much more</i>
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<a aria-label="NPM version" href="https://www.npmjs.com/package/mobx-keystone">
|
|
11
|
-
<img src="https://img.shields.io/npm/v/mobx-keystone.svg?style=for-the-badge&logo=npm&labelColor=333" />
|
|
12
|
-
</a>
|
|
13
|
-
<a aria-label="License" href="./LICENSE">
|
|
14
|
-
<img src="https://img.shields.io/npm/l/mobx-keystone.svg?style=for-the-badge&labelColor=333" />
|
|
15
|
-
</a>
|
|
16
|
-
<a aria-label="Types" href="./packages/lib/tsconfig.json">
|
|
17
|
-
<img src="https://img.shields.io/npm/types/mobx-keystone.svg?style=for-the-badge&logo=typescript&labelColor=333" />
|
|
18
|
-
</a>
|
|
19
|
-
<br />
|
|
20
|
-
<a aria-label="CI" href="https://github.com/xaviergonz/mobx-keystone/actions/workflows/main.yml">
|
|
21
|
-
<img src="https://img.shields.io/github/actions/workflow/status/xaviergonz/mobx-keystone/main.yml?branch=master&label=CI&logo=github&style=for-the-badge&labelColor=333" />
|
|
22
|
-
</a>
|
|
23
|
-
<a aria-label="Codecov" href="https://codecov.io/gh/xaviergonz/mobx-keystone">
|
|
24
|
-
<img src="https://img.shields.io/codecov/c/github/xaviergonz/mobx-keystone?token=6MLRFUBK8V&label=codecov&logo=codecov&style=for-the-badge&labelColor=333" />
|
|
25
|
-
</a>
|
|
26
|
-
<a aria-label="Netlify Status" href="https://app.netlify.com/sites/mobx-keystone/deploys">
|
|
27
|
-
<img src="https://img.shields.io/netlify/c5f60bcb-c1ff-4d04-ad14-1fc34ddbb429?label=netlify&logo=netlify&style=for-the-badge&labelColor=333" />
|
|
28
|
-
</a>
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
> ### Full documentation can be found on the site:
|
|
32
|
-
>
|
|
33
|
-
> ## [mobx-keystone.js.org](https://mobx-keystone.js.org)
|
|
34
|
-
|
|
35
|
-
#### New! Y.js bindings for `mobx-keystone` are now available in the `mobx-keystone-yjs` package as well as a working example in the examples section of the online docs.
|
|
36
|
-
|
|
37
|
-
#### New! Loro CRDT bindings for `mobx-keystone` are now available in the `mobx-keystone-loro` package with native move operation support for arrays, as well as a working example in the examples section of the online docs.
|
|
38
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./apps/site/static/img/logo.png" height="128" />
|
|
3
|
+
<h1 align="center">mobx-keystone</h1>
|
|
4
|
+
</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<i>A MobX powered state management solution based on data trees with first-class support for TypeScript, snapshots, patches and much more</i>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a aria-label="NPM version" href="https://www.npmjs.com/package/mobx-keystone">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/mobx-keystone.svg?style=for-the-badge&logo=npm&labelColor=333" />
|
|
12
|
+
</a>
|
|
13
|
+
<a aria-label="License" href="./LICENSE">
|
|
14
|
+
<img src="https://img.shields.io/npm/l/mobx-keystone.svg?style=for-the-badge&labelColor=333" />
|
|
15
|
+
</a>
|
|
16
|
+
<a aria-label="Types" href="./packages/lib/tsconfig.json">
|
|
17
|
+
<img src="https://img.shields.io/npm/types/mobx-keystone.svg?style=for-the-badge&logo=typescript&labelColor=333" />
|
|
18
|
+
</a>
|
|
19
|
+
<br />
|
|
20
|
+
<a aria-label="CI" href="https://github.com/xaviergonz/mobx-keystone/actions/workflows/main.yml">
|
|
21
|
+
<img src="https://img.shields.io/github/actions/workflow/status/xaviergonz/mobx-keystone/main.yml?branch=master&label=CI&logo=github&style=for-the-badge&labelColor=333" />
|
|
22
|
+
</a>
|
|
23
|
+
<a aria-label="Codecov" href="https://codecov.io/gh/xaviergonz/mobx-keystone">
|
|
24
|
+
<img src="https://img.shields.io/codecov/c/github/xaviergonz/mobx-keystone?token=6MLRFUBK8V&label=codecov&logo=codecov&style=for-the-badge&labelColor=333" />
|
|
25
|
+
</a>
|
|
26
|
+
<a aria-label="Netlify Status" href="https://app.netlify.com/sites/mobx-keystone/deploys">
|
|
27
|
+
<img src="https://img.shields.io/netlify/c5f60bcb-c1ff-4d04-ad14-1fc34ddbb429?label=netlify&logo=netlify&style=for-the-badge&labelColor=333" />
|
|
28
|
+
</a>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
> ### Full documentation can be found on the site:
|
|
32
|
+
>
|
|
33
|
+
> ## [mobx-keystone.js.org](https://mobx-keystone.js.org)
|
|
34
|
+
|
|
35
|
+
#### New! Y.js bindings for `mobx-keystone` are now available in the `mobx-keystone-yjs` package as well as a working example in the examples section of the online docs.
|
|
36
|
+
|
|
37
|
+
#### New! Loro CRDT bindings for `mobx-keystone` are now available in the `mobx-keystone-loro` package with native move operation support for arrays, as well as a working example in the examples section of the online docs.
|
|
38
|
+
|
|
39
39
|
## Introduction
|
|
40
40
|
|
|
41
41
|
`mobx-keystone` helps you build complex client-side apps with a single source of truth, mutable model code, and immutable traceability built in.
|
|
@@ -94,7 +94,7 @@ registerRootStore(store)
|
|
|
94
94
|
- Built-in primitives for references, transactions, action middlewares, and undo/redo.
|
|
95
95
|
- Strong TypeScript inference for models, snapshots, and actions.
|
|
96
96
|
- Composable domain models that stay maintainable as app complexity grows.
|
|
97
|
-
- Seamless integration with MobX and `mobx-react`.
|
|
97
|
+
- Seamless integration with MobX and `mobx-react-lite`.
|
|
98
98
|
|
|
99
99
|
### What users are saying
|
|
100
100
|
|
|
@@ -116,29 +116,29 @@ This gives you mutability where it helps developer experience, plus immutable tr
|
|
|
116
116
|
Trees can only be modified by actions that belong to the same subtree.
|
|
117
117
|
Actions are replayable and can be distributed, and fine-grained changes can be observed as JSON patches.
|
|
118
118
|
|
|
119
|
-
Because `mobx-keystone` uses MobX behind the scenes, it integrates naturally with [`mobx`](https://mobx.js.org) and [`mobx-react`](https://github.com/mobxjs/mobx-react).
|
|
119
|
+
Because `mobx-keystone` uses MobX behind the scenes, it integrates naturally with [`mobx`](https://mobx.js.org) and [`mobx-react-lite`](https://github.com/mobxjs/mobx/tree/main/packages/mobx-react-lite).
|
|
120
120
|
The snapshot and middleware system also makes it possible to replace a Redux reducer/store pair with model-driven state and connect Redux devtools.
|
|
121
121
|
|
|
122
122
|
`mobx-keystone` consists of composable _models_ that capture domain state and behavior together.
|
|
123
123
|
Model instances are created from props, protect their own updates, and reconcile efficiently when applying snapshots.
|
|
124
|
-
|
|
125
|
-
## Requirements
|
|
126
|
-
|
|
127
|
-
This library requires a more or less modern JavaScript environment to work, namely one with support for:
|
|
128
|
-
|
|
129
|
-
- MobX 6, 5, or 4 (with its gotchas)
|
|
130
|
-
- Proxies
|
|
131
|
-
- Symbols
|
|
132
|
-
- WeakMap/WeakSet
|
|
133
|
-
|
|
134
|
-
In other words, it should work on mostly anything except _it won't work in Internet Explorer_.
|
|
135
|
-
|
|
136
|
-
If you are using TypeScript, then version >= 4.2.0 is recommended, though it _might_ work with older versions.
|
|
137
|
-
|
|
138
|
-
## Installation
|
|
139
|
-
|
|
140
|
-
> `npm install mobx-keystone`
|
|
141
|
-
|
|
142
|
-
> `yarn add mobx-keystone`
|
|
143
|
-
|
|
144
|
-
> `pnpm add mobx-keystone`
|
|
124
|
+
|
|
125
|
+
## Requirements
|
|
126
|
+
|
|
127
|
+
This library requires a more or less modern JavaScript environment to work, namely one with support for:
|
|
128
|
+
|
|
129
|
+
- MobX 6, 5, or 4 (with its gotchas)
|
|
130
|
+
- Proxies
|
|
131
|
+
- Symbols
|
|
132
|
+
- WeakMap/WeakSet
|
|
133
|
+
|
|
134
|
+
In other words, it should work on mostly anything except _it won't work in Internet Explorer_.
|
|
135
|
+
|
|
136
|
+
If you are using TypeScript, then version >= 4.2.0 is recommended, though it _might_ work with older versions.
|
|
137
|
+
|
|
138
|
+
## Installation
|
|
139
|
+
|
|
140
|
+
> `npm install mobx-keystone`
|
|
141
|
+
|
|
142
|
+
> `yarn add mobx-keystone`
|
|
143
|
+
|
|
144
|
+
> `pnpm add mobx-keystone`
|