mobx-keystone 1.18.0 → 1.19.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 +4 -0
- package/README.md +85 -29
- package/dist/mobx-keystone.esm.js +49 -20
- package/dist/mobx-keystone.esm.mjs +49 -20
- package/dist/mobx-keystone.umd.js +49 -20
- package/dist/types/modelShared/prop.d.ts +45 -7
- package/dist/types/wrappers/ArraySet.d.ts +84 -2
- package/dist/types/wrappers/ObjectMap.d.ts +84 -2
- package/package.json +1 -1
- package/src/model/getModelMetadata.ts +10 -10
- package/src/modelShared/prop.ts +59 -8
- package/src/modelShared/sharedInternalModel.ts +43 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
- Added `idProp.withGenerator(...)` to define per-model ID generation for `idProp` fields, including inheritance-aware behavior in `ExtendedModel`.
|
|
6
|
+
|
|
3
7
|
## 1.18.0
|
|
4
8
|
|
|
5
9
|
- Added `defineModelMixin` and `composeMixins` helpers for type-safe class-model mixin composition without per-factory cast boilerplate.
|
package/README.md
CHANGED
|
@@ -36,35 +36,91 @@
|
|
|
36
36
|
|
|
37
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
38
|
|
|
39
|
-
## Introduction
|
|
40
|
-
|
|
41
|
-
`mobx-keystone`
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
39
|
+
## Introduction
|
|
40
|
+
|
|
41
|
+
`mobx-keystone` helps you build complex client-side apps with a single source of truth, mutable model code, and immutable traceability built in.
|
|
42
|
+
You write straightforward actions and computed values, while the library gives you snapshots, patches, undo/redo, and runtime protection on top.
|
|
43
|
+
|
|
44
|
+
You can think of it as a TypeScript-first model layer on top of MobX that scales better as your domain grows.
|
|
45
|
+
|
|
46
|
+
### Quick links
|
|
47
|
+
|
|
48
|
+
- [Installation](https://mobx-keystone.js.org/installation)
|
|
49
|
+
- [Class Models](https://mobx-keystone.js.org/class-models)
|
|
50
|
+
- [Todo List Example](https://mobx-keystone.js.org/examples/todo-list)
|
|
51
|
+
- [MST Migration Guide](https://mobx-keystone.js.org/mst-migration-guide)
|
|
52
|
+
- [API docs](https://mobx-keystone.js.org/api/)
|
|
53
|
+
|
|
54
|
+
### Quick glance
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { computed } from "mobx"
|
|
58
|
+
import { Model, model, modelAction, prop, registerRootStore } from "mobx-keystone"
|
|
59
|
+
|
|
60
|
+
@model("todo/Todo")
|
|
61
|
+
class Todo extends Model({
|
|
62
|
+
text: prop<string>(""),
|
|
63
|
+
done: prop(false),
|
|
64
|
+
}) {
|
|
65
|
+
@modelAction
|
|
66
|
+
toggle() {
|
|
67
|
+
this.done = !this.done
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@model("todo/Store")
|
|
72
|
+
class TodoStore extends Model({
|
|
73
|
+
todos: prop<Todo[]>(() => []),
|
|
74
|
+
}) {
|
|
75
|
+
@computed
|
|
76
|
+
get pendingCount() {
|
|
77
|
+
return this.todos.filter((t) => !t.done).length
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@modelAction
|
|
81
|
+
addTodo(text: string) {
|
|
82
|
+
this.todos.push(new Todo({ text }))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const store = new TodoStore({})
|
|
87
|
+
registerRootStore(store)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Why teams choose mobx-keystone
|
|
91
|
+
|
|
92
|
+
- Mutable action code with protected updates, so state changes stay explicit and safe.
|
|
93
|
+
- Runtime snapshots and JSON patches for persistence, sync, replay, and debugging.
|
|
94
|
+
- Built-in primitives for references, transactions, action middlewares, and undo/redo.
|
|
95
|
+
- Strong TypeScript inference for models, snapshots, and actions.
|
|
96
|
+
- Composable domain models that stay maintainable as app complexity grows.
|
|
97
|
+
- Seamless integration with MobX and `mobx-react`.
|
|
98
|
+
|
|
99
|
+
### What users are saying
|
|
100
|
+
|
|
101
|
+
> "I've never been so in love with a tool. [...] In my eyes it is the perfect state management tool for TS/React projects. [...] Building complex clientside apps has never been so easy and fun for me."
|
|
102
|
+
>
|
|
103
|
+
> - [@finallyblueskies](https://github.com/finallyblueskies), [#538](https://github.com/xaviergonz/mobx-keystone/issues/538)
|
|
104
|
+
|
|
105
|
+
> "I'm absolutely loving this project. [...] It's taken all the best bits from mobx and mobx-state-tree and put them into a single package that's a joy to work with. [...] You've literally thought of everything!"
|
|
106
|
+
>
|
|
107
|
+
> - [@robclouth](https://github.com/robclouth), [#146](https://github.com/xaviergonz/mobx-keystone/issues/146)
|
|
108
|
+
|
|
109
|
+
### How it works
|
|
110
|
+
|
|
111
|
+
At the center of `mobx-keystone` is a _living tree_ of mutable but strictly protected models, arrays, and plain objects.
|
|
112
|
+
You update state through model actions, and immutable structurally shared snapshots are derived automatically.
|
|
113
|
+
|
|
114
|
+
This gives you mutability where it helps developer experience, plus immutable traceability where it helps reliability.
|
|
115
|
+
|
|
116
|
+
Trees can only be modified by actions that belong to the same subtree.
|
|
117
|
+
Actions are replayable and can be distributed, and fine-grained changes can be observed as JSON patches.
|
|
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).
|
|
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
|
+
|
|
122
|
+
`mobx-keystone` consists of composable _models_ that capture domain state and behavior together.
|
|
123
|
+
Model instances are created from props, protect their own updates, and reconcile efficiently when applying snapshots.
|
|
68
124
|
|
|
69
125
|
## Requirements
|
|
70
126
|
|