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
import{getSnapshot,types,getIdentifier}from"@gadgetinc/mobx-quick-tree";constKeyword=/*#__PURE__*/types.model("Keyword",{id: types.identifier,name: types.string,});constKeywords=/*#__PURE__*/types.model("Keywords",{keywords: types.map(Keyword),});letrootState: any;constCarType=/*#__PURE__*/types.model("CarType",{id: types.identifier,name: types.string,keyword: types.reference(Keyword,{get(identifier,parent){console.log("I am never called when using createReadOnly? ");returnrootState.keywords.keywords.get(identifier);},set(value){constid=getIdentifier(value);rootState.keywords.keywords.set(id,value);returnid;},}),});constCarTypes=/*#__PURE__*/types.model("CarTypes",{carTypes: types.map(CarType),});constRootState=/*#__PURE__*/types.model("RootState",{carTypes: CarTypes,keywords: Keywords,});rootState=RootState.createReadOnly({carTypes: {carTypes: {"1": {id: "1",name: "I am a cartype",keyword: "1",},"2": {id: "2",name: "I am the second cartype",keyword: "2",},},},keywords: {keywords: {"1": {id: "1",name: "I am a keyword",},},},});console.log({rootSnapshot: getSnapshot(rootState),keywordOnFirstCardType: rootState.carTypes.carTypes.get("1").keyword,keywordNameOnFirstCardType: rootState.carTypes.carTypes.get("1").keyword.name,keywordOnSecondCardType: rootState.carTypes.carTypes.get("2").keyword,/** * This should never return a name of a car type! */keywordNameOnSecondCardType:
rootState.carTypes.carTypes.get("2").keyword.name,});
Notice how the getter is never called, and at the bottom reading a keyword actually returns a car type.
The text was updated successfully, but these errors were encountered:
I am finally giving
mobx-quick-tree
a try but ran into several issues.The biggest one seems to be that whenever you are using
types.reference()
things start behaving wierd when usingcreateReadOnly
.While using
createReadOnly
:It never calls the getter you pass to types.reference. It only seems to do some magic on the MST type you pass in as the first argument.
It seems to share the identifiers of all maps in the tree returning instances of other types.
This is best explained by the following example:
https://codesandbox.io/p/sandbox/dreamy-oskar-forked-wm655g?workspaceId=f29c6df7-7887-4b7e-aac0-96fbcc5d85ea
Notice how the getter is never called, and at the bottom reading a keyword actually returns a car type.
The text was updated successfully, but these errors were encountered: