Skip to content

Context through the tree hierarchy #2162

Discussion options

You must be logged in to vote

Yes, you are correct that the environment is global. I don't think we have an equivalent.

If anyone wants to see the code in action, this does not work:

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

const envA = {
  name: "envA",
};

const envC = {
  name: "envC",
};

(async function () {
  const ModelC = t.model("ModelC", {}).views((self) => ({
    get environmentName() {
      return getEnv(self).name;
    },
  }));
  const ModelB = t
    .model("ModelB", {
      c: t.maybe(ModelC),
    })
    .views((self) => ({
      get environmentName() {
        return getEnv(self).name;
      },
    }));
  const ModelA = t
    .model("ModelA", {
      b: t.maybe(ModelB),
    })
    .views((self) => (

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@coolsoftwaretyler
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@coolsoftwaretyler
Comment options

@samskiter
Comment options

@samskiter
Comment options

@coolsoftwaretyler
Comment options

Answer selected by samskiter
@samskiter
Comment options

@coolsoftwaretyler
Comment options

Comment options

You must be logged in to vote
1 reply
@coolsoftwaretyler
Comment options

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