相关疑难解决方法(0)

如何在多个文件中拆分 Mobx 状态树模型?

我有一个 Mobx 状态树模型已经长得太长了,我想将它拆分到多个 javascript 文件中。

下面是部分代码的演示:

///file1.js
 import { types } from "mobx-state-tree";

export const ExampleModel = types
.model("Example", {
    id: types.identifier,
    name: types.optional(types.string, ""),
    anotherName: types.optional(types.string, ""),

})
.views(self => ({
    get test() {
        return "test"
    }
}))
.views(self => ({
    get anotherTest() {
        return "anotherTest"
    }
}))
.actions(self => ({
    setName(name) {
        self.name = name
    }
}))
.actions(self => ({
    setAnotherName(name) {
        self.anotherName = name
    }
}))
Run Code Online (Sandbox Code Playgroud)

我想要的是将其拆分为两个文件,例如:

///file1.js
import { types } from "mobx-state-tree";

export const ExampleModel …
Run Code Online (Sandbox Code Playgroud)

mobx-state-tree

4
推荐指数
1
解决办法
1620
查看次数

标签 统计

mobx-state-tree ×1