Coder Social home page Coder Social logo

jeloagnasin / mobx-keystone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xaviergonz/mobx-keystone

0.0 1.0 0.0 3.46 MB

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more

Home Page: https://mobx-keystone.js.org

License: MIT License

TypeScript 99.65% JavaScript 0.35%

mobx-keystone's Introduction

mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more

npm license types

CircleCI Coveralls github Netlify Status

Full documentation can be found on the site:

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 (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 of the core design goals of mobx-keystone it to offer a great Typescript syntax out of the box, be it for models (and other kind of data such as plain objects and arrays) or for its generated snapshots.

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

Because state trees are living, mutable models, actions are straight-forward 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 captures a small piece 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 4 (with its gotchas) or 5 (recommended)
  • Proxies (when using mobx 5+)
  • 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 >= 3.6.2 is recommended, though it might work with older versions.

Installation

npm install mobx-keystone

yarn add mobx-keystone

Full documentation

Full documentation can be found on mobx-keystone.js.org

mobx-keystone's People

Contributors

xaviergonz avatar sisp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.