@concord-consortium/mobx-state-tree

中文文档
6.0.0-cc.1发布于 2024/05/29MITTypeScriptESM + CJS零依赖近 30 天下载 2761

透视、交易、 MobX 电源状态容器

中文使用文档
文档目录3 节
  1. 什么是黑帮国家树?
  2. 快速代码示例
  3. 谢谢!
logo

黑道-州-树木

npm version CircleCI Have a question? Ask on GitHub Discussions!

什么是黑帮国家树?

从技术上讲,暴徒州立树(又名:MST)是一个州立集装箱系统,其基础是: 移动X功能反应状态库.

这对你来说可能没什么意义, 我将这样解释: MobX是一个州管理"引擎",而MobX-State-Tree给了它一些你应用所需的结构和通用工具. MST在大型团队中很有价值,但当您期望您的代码能快速缩放时,在更小的应用中也会有用. 如果我们把它比作Redux, MST 提供更好的性能,并且比Redux少得多的锅炉板代码!

移动X是 最受欢迎的Redux替代品之一 并被世界各地的公司(连同MobX-State-Tree)使用。 MST 与 TypeScript, React, 和 React Industrial 玩得非常好, 特别是配对时 暴徒- 反应- 立特它支持多个商店、同步动作和副作用,使得极具针对性地重新发布React apps, 以及更多 -- -- 所有软件包中都有 零依赖关系 除了MobX本身.

注:您不需要知道如何使用MobX来使用MST.

开始

见 开始 教程或跟随空闲 蛋头.io课程。 。 。 .

官方文件可在 http://mobx-state-tree.js.org/ 互联网档案馆的存檔,存档日期2013-12-22

快速代码示例

没有什么比看一些代码更像 去感受图书馆。 看看作者的这个小例子和作者的微博列表.

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

谢谢!

版本与发布记录

@concord-consortium/mobx-state-tree 共发布 5 个版本,首次发布于 2022/08/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.0-cc.1latest2024/05/292 年前
5.4.0-cc.12024/02/052 年前
5.1.8-cc.22023/07/273 年前
5.1.8-cc.12023/05/033 年前
5.1.5-cc.12022/08/254 年前

关于 @concord-consortium/mobx-state-tree 的常见问题

@concord-consortium/mobx-state-tree 是什么?

透视、交易、 MobX 电源状态容器

如何安装 @concord-consortium/mobx-state-tree?

在项目目录运行 npm install @concord-consortium/mobx-state-tree,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:mobx(^6.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@concord-consortium/mobx-state-tree 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@concord-consortium/mobx-state-tree 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@concord-consortium/mobx-state-tree 可以商用吗?

@concord-consortium/mobx-state-tree 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@concord-consortium/mobx-state-tree 的下载量有多少?

根据 npm 官方下载统计,@concord-consortium/mobx-state-tree 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,761 次,日均约 92 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@concord-consortium/mobx-state-tree 还在维护吗?

最新版本 6.0.0-cc.1 发布于 2024/05/29(2 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/08/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。