Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xaviergonz/mobx-keystone
A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://github.com/xaviergonz/mobx-keystone
data-trees frp functional-reactive-programming immutability mobx mobx-keystone mobx-state-tree mutability reactive snapshots state-management state-tree
Last synced: about 4 hours ago
JSON representation
A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
- Host: GitHub
- URL: https://github.com/xaviergonz/mobx-keystone
- Owner: xaviergonz
- License: mit
- Created: 2019-05-15T19:09:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-28T16:35:21.000Z (14 days ago)
- Last Synced: 2024-12-05T06:04:37.488Z (7 days ago)
- Topics: data-trees, frp, functional-reactive-programming, immutability, mobx, mobx-keystone, mobx-state-tree, mutability, reactive, snapshots, state-management, state-tree
- Language: TypeScript
- Homepage: https://mobx-keystone.js.org
- Size: 26.4 MB
- Stars: 555
- Watchers: 10
- Forks: 25
- Open Issues: 54
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome - mobx-keystone - A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more (TypeScript)
- awesome-state - mobx-keystone
- awesome-react-state-management - mobx-keystone - A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more (List)
README
mobx-keystone
A MobX powered state management solution based on data trees with first-class support for TypeScript, snapshots, patches and much more> ### Full documentation can be found on the site:
>
> ## [mobx-keystone.js.org](https://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](https://mobx-keystone.js.org/examples/todo-list).
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`](https://mobx.js.org) and [`mobx-react`](https://github.com/mobxjs/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/WeakSetIn 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`