Normally, in Mobx state tree (MST) if you want to change state of tree/node, you must write so many functions to change them.
For example:
exportconstItem=types
.model("Item",{
title:types.string,
price:types.string
})
.actions((self)=>({
changeTitle:(title:string)=>{
self.title=title;
},
changePrice:(price:string)=>{
self.price=price;
}
}))
if you have n properties, you must write n functions to change them (like changeTitle and changePrice in above example), which can make you feel tired because of the long code.
My package is solution. With my package, we can be "lazy", avoid writing so many functions.
Install
yarn add mobx mobx-state-tree easy-update-mst
My package require mobx and mobx state tree
Usage/Examples
In your model
import{types,Instance}from"mobx-state-tree";
import{ActionUpdate}from'easy-update-mst';
exportconstUserModel=types.model("User Model",{
id:types.identifier,
name:types.string,
job:types.model({
code:types.optional(types.string,'Javascript'),
exp:types.optional(types.number,1.5),
})
})
// another action
.actions(()=>({
doSomething(){
}
}))
// inject action update to model
.actions(ActionUpdate);
Now in your component you can use function setMobxState and setMobxDeepState to change state.
For example: