I would like to ask you if there's any way of sharing actions between models in mobx-state-tree?
Let's consider this example (login action of AuthModel):
import { types } from "mobx-state-tree";
const UIModel = types
.model({
globalLoading: types.boolean,
})
.actions((self) => ({
setGlobalLoading(value) {
self.globalLoading = value;
},
}));
const AuthModel = types
.model({
userData: types.maybeNull(types.User),
})
.actions((self) => ({
login() {
// call UIModel.setGlobalLoading(true) somehow
},
}));
const RootModel = types.model({
ui: UIModel,
auth: AuthModel,
});
RootModel.create({
auth: {
userData: null
},
ui: {
globalLoading: false
}
})
Is there any way to somehow "inject" reference to UIModel inside AuthModel? I can't find anything like this in docs or examples I've seen online.