Skip to content

Does detach remove the computed values from cache? #2133

Discussion options

You must be logged in to vote

@Dummy26 - I think so. Here's an experiment that seems to evaluate a computed view after the model was detached:

https://codesandbox.io/p/sandbox/silly-galileo-ly4msx?file=%2Fsrc%2Findex.ts%3A17%2C22

Code:

import { t, detach } from "mobx-state-tree";

const Car = t
  .model({
    brand: t.string,
    model: t.string,
    year: t.number,
  })
  .views((self) => ({
    get makeModelYear(): string {
      const { brand, model, year } = self;
      console.log("evaluating");
      return `${brand} ${model} ${year}`;
    },
  }));

const ParentModel = t
  .model({
    car: t.maybe(Car),
  })
  .actions((self) => ({
    detachCar() {
      detach(self.car);
    },
  }));

const myCar = Car.create(

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@aniket-banyal
Comment options

@coolsoftwaretyler
Comment options

Answer selected by aniket-banyal
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants