When does a node become dead? #2140
-
I am seeing issues of these types
So, I am trying to understand under which cases does a node become dead.
Are there some other cases? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @aniket-banyal - I have a few ideas that might be helpful One specific case you missed in your listLet's say you have three levels in a tree:
Here's code to that effect: import { types } from "mobx-state-tree";
(async function () {
const Person = types.model("Person", {
name: types.string,
});
const Company = types.model("Company", {
name: types.string,
employee: Person,
});
const RootStore = types
.model("RootStore", {
company: Company,
})
.actions((self) => ({
changeCompanies(name: string, personName: string) {
const person2 = Person.create({ name: personName });
self.company = Company.create({
name,
employee: person2,
});
},
}));
const person1 = Person.create({ name: "John" });
const company = Company.create({
name: "Acme",
employee: person1,
});
const root = RootStore.create({
company,
});
console.log(person1.name);
root.changeCompanies("Acme 2", "Jane");
console.log(person1.name);
})(); This is similar to your first case, but I wanted to clarify that the node doesn't have to be a part of a collection like an Digging through the code for
|
Beta Was this translation helpful? Give feedback.
Hey @aniket-banyal - I have a few ideas that might be helpful
One specific case you missed in your list
Let's say you have three levels in a tree:
company
company
knows about anemployee
, which is an instance of aPerson
nodecompany
gets changed into a new company with a differentPerson
. The originalPerson
is now dead (this example got more morbid than I expected).Here's code to that effect: