about summary refs log tree commit diff
path: root/src/state/env.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/env.ts')
-rw-r--r--src/state/env.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/state/env.ts b/src/state/env.ts
new file mode 100644
index 000000000..90a2cab5e
--- /dev/null
+++ b/src/state/env.ts
@@ -0,0 +1,27 @@
+/**
+ * The environment is a place where services and shared dependencies between
+ * models live. They are made available to every model via dependency injection.
+ */
+
+import {getEnv, IStateTreeNode} from 'mobx-state-tree'
+
+export class Environment {
+  constructor() {}
+
+  async setup() {}
+}
+
+/**
+ * Extension to the MST models that adds the environment property.
+ * Usage:
+ *
+ *   .extend(withEnvironment)
+ *
+ */
+export const withEnvironment = (self: IStateTreeNode) => ({
+  views: {
+    get environment() {
+      return getEnv<Environment>(self)
+    },
+  },
+})