mobx-keystone 1.2.0 → 1.4.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +82 -82
  3. package/dist/mobx-keystone.esm.js +825 -526
  4. package/dist/mobx-keystone.esm.mjs +825 -526
  5. package/dist/mobx-keystone.umd.js +833 -536
  6. package/dist/types/model/Model.d.ts +1 -1
  7. package/dist/types/modelShared/prop.d.ts +32 -34
  8. package/dist/types/types/objectBased/typesDataModelData.d.ts +1 -1
  9. package/dist/types/types/objectBased/typesModel.d.ts +1 -1
  10. package/package.json +18 -17
  11. package/src/action/modelAction.ts +52 -52
  12. package/src/action/wrapInAction.ts +144 -144
  13. package/src/computedTree/computedTree.ts +99 -99
  14. package/src/dataModel/BaseDataModel.ts +185 -185
  15. package/src/model/BaseModel.ts +269 -269
  16. package/src/model/Model.ts +1 -1
  17. package/src/model/newModel.ts +151 -151
  18. package/src/modelShared/modelDecorator.ts +66 -67
  19. package/src/modelShared/modelInfo.ts +1 -1
  20. package/src/modelShared/modelSymbols.ts +3 -3
  21. package/src/modelShared/prop.ts +138 -126
  22. package/src/modelShared/sharedInternalModel.ts +115 -125
  23. package/src/parent/coreObjectChildren.ts +169 -165
  24. package/src/parent/getChildrenObjects.ts +25 -25
  25. package/src/parent/path.ts +1 -1
  26. package/src/parent/path2.ts +27 -27
  27. package/src/parent/setParent.ts +1 -3
  28. package/src/parent/walkTree.ts +182 -182
  29. package/src/patch/applyPatches.ts +172 -172
  30. package/src/redux/redux.ts +114 -114
  31. package/src/snapshot/index.ts +6 -6
  32. package/src/snapshot/internal.ts +6 -2
  33. package/src/snapshot/reconcileArraySnapshot.ts +61 -61
  34. package/src/snapshot/reconcilePlainObjectSnapshot.ts +68 -68
  35. package/src/snapshot/reconcileSnapshot.ts +78 -78
  36. package/src/tweaker/core.ts +79 -79
  37. package/src/tweaker/tweak.ts +185 -185
  38. package/src/tweaker/tweakArray.ts +451 -433
  39. package/src/tweaker/tweakPlainObject.ts +99 -80
  40. package/src/types/objectBased/typesDataModelData.ts +179 -179
  41. package/src/types/objectBased/typesModel.ts +196 -196
  42. package/src/types/objectBased/typesObjectMap.ts +2 -2
  43. package/src/types/tProp.ts +55 -26
  44. package/src/types/utility/typesUnchecked.ts +38 -38
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.4.0
4
+
5
+ - Use a proxy to decorate model classes to reduce the inheritance level of models by one.
6
+ - Create object children cache only when there are actually children to save some memory in objects/arrays that don't have children of type object.
7
+ - Cache props/tProps to save some memory in model definitions.
8
+
9
+ ## 1.3.0
10
+
11
+ - Big memory optimizations for model definitions with many properties (very little changes for model instances though). This change now makes Proxy support a requirement.
12
+ - Minor speed optimizations.
13
+
3
14
  ## 1.2.0
4
15
 
5
16
  - TypeCheckError now includes a new `message` field, a new `typeCheckedValue` field and no longer requires a parameter for the `throw()` method.
package/README.md CHANGED
@@ -1,82 +1,82 @@
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/workflow/status/xaviergonz/mobx-keystone/CI?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
- ## Introduction
36
-
37
- `mobx-keystone` is a state container that combines the _simplicity and ease of mutable data_ with the _traceability of immutable data_ and the _reactiveness and performance of observable data_, all with a fully compatible TypeScript syntax.
38
-
39
- Simply put, it tries to combine the best features of both immutability (transactionality, traceability and composition) and mutability (discoverability, co-location and encapsulation) based approaches to state management; everything to provide the best developer experience possible.
40
- Unlike MobX itself, `mobx-keystone` is very opinionated about how data should be structured and updated.
41
- This makes it possible to solve many common problems out of the box.
42
-
43
- Central in `mobx-keystone` is the concept of a _living tree_. The tree consists of mutable, but strictly protected objects (models, arrays and plain objects).
44
- From this living tree, immutable, structurally shared snapshots are automatically generated.
45
-
46
- Another core design goal of `mobx-keystone` is to offer a great TypeScript syntax out of the box, be it for models (and other kinds of data such as plain objects and arrays) or for its generated snapshots.
47
-
48
- To see some code and get a glimpse of how it works check the [Todo List Example](https://mobx-keystone.js.org/examples/todo-list).
49
-
50
- Because state trees are living, mutable models, actions are straightforward to write; just modify local instance properties where appropriate. It is not necessary to produce a new state tree yourself, `mobx-keystone`'s snapshot functionality will derive one for you automatically.
51
-
52
- Although mutable sounds scary to some, fear not, actions have many interesting properties.
53
- By default trees can only be modified by using an action that belongs to the same subtree.
54
- Furthermore, actions are replayable and can be used to distribute changes.
55
-
56
- Moreover, because changes can be detected on a fine-grained level, JSON patches are supported out of the box.
57
- Simply subscribing to the patch stream of a tree is another way to sync diffs with, for example, back-end servers or other clients.
58
-
59
- Since `mobx-keystone` uses MobX behind the scenes, it integrates seamlessly with [`mobx`](https://mobx.js.org) and [`mobx-react`](https://github.com/mobxjs/mobx-react).
60
- Even cooler, because it supports snapshots, action middlewares and replayable actions out of the box, it is possible to replace a Redux store and reducer with a MobX data model.
61
- This makes it possible to connect the Redux devtools to `mobx-keystone`.
62
-
63
- Like React, `mobx-keystone` consists of composable components, called _models_, which capture small pieces of state. They are instantiated from props and after that manage and protect their own internal state (using actions). Moreover, when applying snapshots, tree nodes are reconciled as much as possible.
64
-
65
- ## Requirements
66
-
67
- This library requires a more or less modern JavaScript environment to work, namely one with support for:
68
-
69
- - MobX 6, 5, or 4 (with its gotchas)
70
- - Proxies (when using MobX 5, or MobX 6 with the proxies setting enabled)
71
- - Symbols
72
- - WeakMap/WeakSet
73
-
74
- In other words, it should work on mostly anything except _it won't work in Internet Explorer_.
75
-
76
- If you are using TypeScript, then version >= 4.2.0 is recommended, though it _might_ work with older versions.
77
-
78
- ## Installation
79
-
80
- > `npm install mobx-keystone`
81
-
82
- > `yarn add mobx-keystone`
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
+ ## Introduction
36
+
37
+ `mobx-keystone` is a state container that combines the _simplicity and ease of mutable data_ with the _traceability of immutable data_ and the _reactiveness and performance of observable data_, all with a fully compatible TypeScript syntax.
38
+
39
+ Simply put, it tries to combine the best features of both immutability (transactionality, traceability and composition) and mutability (discoverability, co-location and encapsulation) based approaches to state management; everything to provide the best developer experience possible.
40
+ Unlike MobX itself, `mobx-keystone` is very opinionated about how data should be structured and updated.
41
+ This makes it possible to solve many common problems out of the box.
42
+
43
+ Central in `mobx-keystone` is the concept of a _living tree_. The tree consists of mutable, but strictly protected objects (models, arrays and plain objects).
44
+ From this living tree, immutable, structurally shared snapshots are automatically generated.
45
+
46
+ Another core design goal of `mobx-keystone` is to offer a great TypeScript syntax out of the box, be it for models (and other kinds of data such as plain objects and arrays) or for its generated snapshots.
47
+
48
+ To see some code and get a glimpse of how it works check the [Todo List Example](https://mobx-keystone.js.org/examples/todo-list).
49
+
50
+ Because state trees are living, mutable models, actions are straightforward to write; just modify local instance properties where appropriate. It is not necessary to produce a new state tree yourself, `mobx-keystone`'s snapshot functionality will derive one for you automatically.
51
+
52
+ Although mutable sounds scary to some, fear not, actions have many interesting properties.
53
+ By default trees can only be modified by using an action that belongs to the same subtree.
54
+ Furthermore, actions are replayable and can be used to distribute changes.
55
+
56
+ Moreover, because changes can be detected on a fine-grained level, JSON patches are supported out of the box.
57
+ Simply subscribing to the patch stream of a tree is another way to sync diffs with, for example, back-end servers or other clients.
58
+
59
+ Since `mobx-keystone` uses MobX behind the scenes, it integrates seamlessly with [`mobx`](https://mobx.js.org) and [`mobx-react`](https://github.com/mobxjs/mobx-react).
60
+ Even cooler, because it supports snapshots, action middlewares and replayable actions out of the box, it is possible to replace a Redux store and reducer with a MobX data model.
61
+ This makes it possible to connect the Redux devtools to `mobx-keystone`.
62
+
63
+ Like React, `mobx-keystone` consists of composable components, called _models_, which capture small pieces of state. They are instantiated from props and after that manage and protect their own internal state (using actions). Moreover, when applying snapshots, tree nodes are reconciled as much as possible.
64
+
65
+ ## Requirements
66
+
67
+ This library requires a more or less modern JavaScript environment to work, namely one with support for:
68
+
69
+ - MobX 6, 5, or 4 (with its gotchas)
70
+ - Proxies
71
+ - Symbols
72
+ - WeakMap/WeakSet
73
+
74
+ In other words, it should work on mostly anything except _it won't work in Internet Explorer_.
75
+
76
+ If you are using TypeScript, then version >= 4.2.0 is recommended, though it _might_ work with older versions.
77
+
78
+ ## Installation
79
+
80
+ > `npm install mobx-keystone`
81
+
82
+ > `yarn add mobx-keystone`