mobx-keystone 1.17.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 CHANGED
@@ -1,10 +1,20 @@
1
1
  # Change Log
2
2
 
3
- ## 1.17.0
3
+ ## 1.19.0
4
4
 
5
- - Performance: model auto type-checking is now faster for updates in large or deeply nested models. Type checks now re-run only for changed properties while unchanged branches reuse cached results, reducing repeated validation work during frequent updates. This is an internal optimization and does not change the public API.
5
+ - Added `idProp.withGenerator(...)` to define per-model ID generation for `idProp` fields, including inheritance-aware behavior in `ExtendedModel`.
6
6
 
7
- ## 1.16.0
7
+ ## 1.18.0
8
+
9
+ - Added `defineModelMixin` and `composeMixins` helpers for type-safe class-model mixin composition without per-factory cast boilerplate.
10
+ - Fix: preserve intermediate model props when composing extended/decorated model classes in inheritance chains (for example chained mixins), so runtime-composed classes keep all props from previous composition steps.
11
+ - Fix: `composeMixins` now keeps mixin-added model prop typing markers for non-function fields, so `ModelData<>` and `ModelCreationData<>` reflect mixed-in props.
12
+
13
+ ## 1.17.0
14
+
15
+ - Performance: model auto type-checking is now faster for updates in large or deeply nested models. Type checks now re-run only for changed properties while unchanged branches reuse cached results, reducing repeated validation work during frequent updates. This is an internal optimization and does not change the public API.
16
+
17
+ ## 1.16.0
8
18
 
9
19
  - Fixed a long-standing bug: model auto type-checking now enforces ancestor property refinements (for example refinements on `a.b`) when mutating nested child model data (for example `a.b.x`), while still avoiding unnecessary ancestor checks when no refinement is present on the path.
10
20
  - Performance: reduced runtime type-check overhead by caching object prop checker resolution, avoiding success-path child path allocations in object/array/tuple/record checks, and narrowing `types.or` branch checks by base type.
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` 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.
42
-
43
- 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.
44
- Unlike MobX itself, `mobx-keystone` is very opinionated about how data should be structured and updated.
45
- This makes it possible to solve many common problems out of the box.
46
-
47
- 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).
48
- From this living tree, immutable, structurally shared snapshots are automatically generated.
49
-
50
- 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.
51
-
52
- 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).
53
-
54
- 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.
55
-
56
- Although mutable sounds scary to some, fear not, actions have many interesting properties.
57
- By default trees can only be modified by using an action that belongs to the same subtree.
58
- Furthermore, actions are replayable and can be used to distribute changes.
59
-
60
- Moreover, because changes can be detected on a fine-grained level, JSON patches are supported out of the box.
61
- Simply subscribing to the patch stream of a tree is another way to sync diffs with, for example, back-end servers or other clients.
62
-
63
- 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).
64
- 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.
65
- This makes it possible to connect the Redux devtools to `mobx-keystone`.
66
-
67
- 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.
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