You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 11, 2026. It is now read-only.
// Import packageimport{configureStore}from"mst-storebooster";// Import:// RootStore - MST tree model,// RootStoreModel - type of RootStore (aka Instance<RootStore>)// RootStoreEnv - type of a global MST environment object with utils or tree nodes or trees themselves// Any other MST tree models that were instantiated inside RootStoreimport{RootStore,RootStoreModel,RootStoreEnv,bookPhoneWidgetStoreInstance,// ...other instances}from"src/stores/models";exporttypeInstantiatedStoresType=typeofInstantiatedStoresBox;exporttypeBusType=typeofBus;exportconstInstantiatedStoresBox={// master system's store instances;// other teams will have to mock instance that exist on the Bus for development;// they will not be distrubited with a package;// e.g., this store doesn't exist on the Bus -> Do not mockbookPhoneWidgetStore: bookPhoneWidgetStoreInstance,// e.g., a team needs some data from this store and gets access to it via Bus -> Mock path to this part of dataIexistOntheBusStore: IexistOntheBusStoreInstance,// other teams' store instances;// master system will need these instances in dev;// It is team's duty to provide these instances in their npm packagesteam1RootStore: {// all instances of team1 stores must be put inside this objectteam1StoreForSth: team1StoreForSthInstance,},team2RootStore: {// all instances of team2 stores wiil be put inside this objectteam2StoreForSth: team2StoreForSthInstance,},};// all properties and their values must be declared in RootStoreEnv.// Properties below are given as an example, they might not exist on the BusexportconstBus={// master system's bus data// other teams will haver to mock these for developmentcommonLogoutUser: ()=>{// some common util},commonUserData: {// some common data needed for all teams},iExist: IexistOntheBusStore[0].doI.exist,// other teams' bus data// It is team's duty to provide these instances in their npm packagesteam1StoreParts: {// some parts from the store of a team that master system needschangeSth: team1StoreForSth.modelOfSth.changeSth,// ... other parts},team2StoreParts: {// some parts from the store of a team that master system needschangeSth: team2StoreForSth.modelOfSth.changeSth,// ... other parts},};// create root store with necessary stores and types// and export all utilsexportconst{ StoreProvider, useInject }=configureStore<RootStoreModel,RootStoreEnv,InstantiatedStoresType,BusType>({
RootStore,
InstantiatedStoresBox,
Bus,});
How to use created utils
StoreProvider
// import created StoreProvider util in App.tsximport{StoreProvider}from"src/stores";// wrap your element in it<StoreProvider>AppEntryPoint-Bomjour!<App/></StoreProvider>;
useInject
importReact,{FC}from"react";import{observer}from"mobx-react-lite";import{RootStoreModel,useInject}from"src/stores";// create store selector function for injecting part of the Root store into a component;// only one paramater and it is of type of RootStoreModel// return value can be any data structure or primitivesconstmapStore=({ bookPhoneWidgetStore }: RootStoreModel)=>bookPhoneWidgetStore.phoneInfo.changeView;// observe changes via MRL **observer**exportconstSomeNestedElement: FC<{}>=observer((props)=>{// types are inferredconstchangeView=useInject(mapStore);consthandleChangeView=()=>changeView("newPage");return(<divclassName={"some class"}><buttonclassName={"another class"}onClick={handleChangeView}/></div>);});