1.11.1 • Published 2 months ago

mobx-keystone v1.11.1

Weekly downloads
1,269
License
MIT
Repository
github
Last release
2 months ago

Full documentation can be found on the site:

mobx-keystone.js.org

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.

Introduction

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.

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. Unlike MobX itself, mobx-keystone is very opinionated about how data should be structured and updated. This makes it possible to solve many common problems out of the box.

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). From this living tree, immutable, structurally shared snapshots are automatically generated.

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.

To see some code and get a glimpse of how it works check the Todo List Example.

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.

Although mutable sounds scary to some, fear not, actions have many interesting properties. By default trees can only be modified by using an action that belongs to the same subtree. Furthermore, actions are replayable and can be used to distribute changes.

Moreover, because changes can be detected on a fine-grained level, JSON patches are supported out of the box. Simply subscribing to the patch stream of a tree is another way to sync diffs with, for example, back-end servers or other clients.

Since mobx-keystone uses MobX behind the scenes, it integrates seamlessly with mobx and mobx-react. 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. This makes it possible to connect the Redux devtools to mobx-keystone.

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.

Requirements

This library requires a more or less modern JavaScript environment to work, namely one with support for:

  • MobX 6, 5, or 4 (with its gotchas)
  • Proxies
  • Symbols
  • WeakMap/WeakSet

In other words, it should work on mostly anything except it won't work in Internet Explorer.

If you are using TypeScript, then version >= 4.2.0 is recommended, though it might work with older versions.

Installation

npm install mobx-keystone

yarn add mobx-keystone

1.11.1

2 months ago

1.11.0

2 months ago

1.10.2

5 months ago

1.10.1

8 months ago

1.10.0

8 months ago

1.9.0

11 months ago

1.8.3

11 months ago

1.8.2

11 months ago

1.8.1

11 months ago

1.8.0

11 months ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

2 years ago

1.6.5

1 year ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.68.6

3 years ago

0.69.2

2 years ago

0.69.1

2 years ago

0.69.4

2 years ago

0.69.3

2 years ago

0.69.0

2 years ago

0.69.9

2 years ago

0.69.6

2 years ago

0.69.5

2 years ago

0.69.8

2 years ago

0.69.7

2 years ago

0.67.4

3 years ago

0.67.5

3 years ago

0.68.1-alpha.2

3 years ago

0.68.1-alpha

3 years ago

0.68.3

3 years ago

0.68.2

3 years ago

0.68.5

3 years ago

0.68.4

3 years ago

0.68.1

3 years ago

0.68.0

3 years ago

0.67.2-alpha.1

3 years ago

0.67.3

3 years ago

0.67.2

3 years ago

0.67.1

3 years ago

0.67.1-alpha.1

3 years ago

0.67.0

3 years ago

0.67.0-alpha.1

3 years ago

0.64.1

3 years ago

0.65.0

3 years ago

0.66.1

3 years ago

0.66.0

3 years ago

0.64.0

3 years ago

0.63.2

3 years ago

0.63.0

3 years ago

0.63.1

3 years ago

0.62.0

3 years ago

0.61.3

3 years ago

0.61.2

3 years ago

0.61.1

3 years ago

0.61.0

3 years ago

0.60.7

3 years ago

0.60.6

3 years ago

0.60.5

3 years ago

0.60.3-alpha

3 years ago

0.60.3

3 years ago

0.60.4

3 years ago

0.60.2

3 years ago

0.60.1

3 years ago

0.60.0

3 years ago

0.59.0

4 years ago

0.56.1

4 years ago

0.56.2

4 years ago

0.57.0

4 years ago

0.57.1

4 years ago

0.57.0-alpha.1

4 years ago

0.57.0-alpha.2

4 years ago

0.58.1

4 years ago

0.58.2

4 years ago

0.58.0

4 years ago

0.56.0

4 years ago

0.55.2

4 years ago

0.55.1

4 years ago

0.55.2-alpha

4 years ago

0.55.0

4 years ago

0.54.0

4 years ago

0.53.0

4 years ago

0.51.0

4 years ago

0.51.1

4 years ago

0.52.0

4 years ago

0.50.0

4 years ago

0.49.0

4 years ago

0.48.5

4 years ago

0.48.4

4 years ago

0.48.3

4 years ago

0.48.2

4 years ago

0.48.1-alpha

4 years ago

0.48.1

4 years ago

0.48.0

4 years ago

0.47.1

4 years ago

0.47.0

4 years ago

0.46.0

4 years ago

0.45.5

4 years ago

0.45.4

4 years ago

0.45.3

4 years ago

0.45.3-alpha.0

4 years ago

0.45.2

4 years ago

0.45.1

4 years ago

0.44.0

4 years ago

0.45.0

4 years ago

0.43.1

5 years ago

0.43.0

5 years ago

0.42.1

5 years ago

0.42.0

5 years ago

0.41.0

5 years ago

0.40.0

5 years ago

0.39.0

5 years ago

0.38.0

5 years ago

0.37.0

5 years ago

0.36.1

5 years ago

0.36.0

5 years ago

0.35.0

5 years ago

0.34.0

5 years ago

0.33.0

5 years ago

0.32.0

5 years ago

0.31.0

5 years ago

0.30.1

5 years ago

0.30.0

5 years ago

0.29.0

5 years ago

0.28.4

5 years ago

0.28.3

5 years ago

0.28.2

5 years ago

0.28.1

5 years ago

0.28.0

5 years ago

0.27.0

5 years ago

0.26.7

5 years ago

0.26.6

5 years ago

0.26.5

5 years ago

0.26.4

5 years ago

0.26.3-alpha.1

5 years ago

0.26.3

5 years ago

0.26.2

5 years ago

0.26.1

5 years ago

0.26.0

5 years ago

0.25.3

5 years ago

0.25.2

5 years ago

0.25.1

5 years ago

0.25.0

5 years ago

0.25.0-alpha.1

5 years ago

0.24.1

5 years ago

0.24.0

5 years ago

0.23.2

5 years ago

0.23.1

5 years ago

0.23.0

5 years ago

0.22.1

5 years ago

0.22.0

5 years ago

0.21.0

5 years ago

0.20.2

5 years ago

0.20.1

5 years ago

0.20.0

5 years ago

0.19.1

5 years ago

0.19.0

5 years ago

0.18.0

5 years ago

0.17.4

5 years ago

0.17.3

5 years ago

0.17.2

5 years ago

0.17.1

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.0

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.1

5 years ago

0.12.0-alpha.1

5 years ago

0.13.0

5 years ago

0.12.4

5 years ago

0.12.3

5 years ago

0.12.2

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.4

5 years ago

0.11.3

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.14

5 years ago

0.9.12

5 years ago