mobxjs/mobx-state-tree
Fork: 641 Star: 6949 (更新于 2024-10-31 02:44:18)
license: MIT
Language: TypeScript .
Full-featured reactive state management without the boilerplate
最后发布版本: v7.0.0-pre.2 ( 2024-08-02 01:56:53)
mobx-state-tree
What is mobx-state-tree?
Technically speaking, mobx-state-tree (also known as MST) is a state container system built on MobX, a functional reactive state library.
This may not mean much to you, and that’s okay. I’ll explain it like this: MobX is a state management "engine", and MobX-State-Tree gives it structure and common tools you need for your app. MST is valuable in a large team but also useful in smaller applications when you expect your code to scale rapidly. And if we compare it to Redux, MST offers better performance and much less boilerplate code than Redux!
MobX is one of the most popular Redux alternatives and is used (along with MobX-State-Tree) by companies worldwide. MST plays very well with TypeScript, React, and React Native, especially when paired with mobx-react-lite. It supports multiple stores, async actions and side effects, enables extremely targeted re-renders for React apps, and much more -- all in a package with zero dependencies other than MobX itself.
Note: you don't need to know how to use MobX in order to use MST.
Getting started
See the Getting started tutorial or follow the free egghead.io course.
👉 Official docs can be found at http://mobx-state-tree.js.org/
Quick Code Example
There's nothing quite like looking at some code to get a feel for a library. Check out this small example of an author and list of tweets by that author.
import { types } from "mobx-state-tree" // alternatively: import { t } from "mobx-state-tree"
// Define a couple models
const Author = types.model({
id: types.identifier,
firstName: types.string,
lastName: types.string
})
const Tweet = types.model({
id: types.identifier,
author: types.reference(Author), // stores just the `id` reference!
body: types.string,
timestamp: types.number
})
// Define a store just like a model
const RootStore = types.model({
authors: types.array(Author),
tweets: types.array(Tweet)
})
// Instantiate a couple model instances
const jamon = Author.create({
id: "jamon",
firstName: "Jamon",
lastName: "Holmgren"
})
const tweet = Tweet.create({
id: "1",
author: jamon.id, // just the ID needed here
body: "Hello world!",
timestamp: Date.now()
})
// Now instantiate the store!
const rootStore = RootStore.create({
authors: [jamon],
tweets: [tweet]
})
// Ready to use in a React component, if that's your target.
import { observer } from "mobx-react-lite"
const MyComponent = observer((props) => {
return <div>Hello, {rootStore.authors[0].firstName}!</div>
})
// Note: since this component is "observed", any changes to rootStore.authors[0].firstName
// will result in a re-render! If you're not using React, you can also "listen" to changes
// using `onSnapshot`: https://mobx-state-tree.js.org/concepts/snapshots
Thanks!
- Michel Weststrate for creating MobX, MobX-State-Tree, and MobX-React.
- Infinite Red for supporting ongoing maintenance on MST.
- Mendix for sponsoring and providing the opportunity to work on exploratory projects like MST.
- Dan Abramov's work on Redux has strongly influenced the idea of snapshots and transactional actions in MST.
- Giulio Canti's work on tcomb and type systems in general has strongly influenced the type system of MST.
- All the early adopters encouraging to pursue this whole idea and proving it is something feasible.
最近版本更新:(数据更新于 2024-10-11 13:14:50)
2024-08-02 01:56:53 v7.0.0-pre.2
2024-07-12 10:01:59 v7.0.0-pre.1
2024-07-08 03:20:47 v6.0.1
2024-05-07 03:16:58 v6.0.0
2024-04-17 22:49:13 v6.0.0-pre.3
2024-04-17 22:32:30 v5.4.2
2024-03-11 03:59:57 v6.0.0-pre.2
2024-03-01 23:38:19 v5.4.2-pre.1
2024-02-06 09:47:53 v5.4.1
2023-11-28 06:01:02 v5.4.0
主题(topics):
hacktoberfest, mobx, mobx-state-tree, mst, observable, redux, snapshot, state-management, state-tree
mobxjs/mobx-state-tree同语言 TypeScript最近更新仓库
2024-11-22 01:36:46 twentyhq/twenty
2024-11-21 20:34:48 CopilotKit/CopilotKit
2024-11-21 16:58:07 labring/FastGPT
2024-11-21 16:14:54 RSSNext/Follow
2024-11-21 16:12:23 x-extends/vxe-table
2024-11-21 14:55:41 continuedev/continue