aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js/RootStore.jsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-07-01 12:31:07 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-07-01 12:31:07 +0200
commit8595c9a22830b1baacc49bb694d70389b2539eba (patch)
treecb496cd34661a0d3ec4c9b5a333e948f24e437f4 /language-web/src/main/js/RootStore.jsx
parentConvert to React app (diff)
downloadrefinery-8595c9a22830b1baacc49bb694d70389b2539eba.tar.gz
refinery-8595c9a22830b1baacc49bb694d70389b2539eba.tar.zst
refinery-8595c9a22830b1baacc49bb694d70389b2539eba.zip
Add material-ui and mobx integration
Diffstat (limited to 'language-web/src/main/js/RootStore.jsx')
-rw-r--r--language-web/src/main/js/RootStore.jsx30
1 files changed, 30 insertions, 0 deletions
diff --git a/language-web/src/main/js/RootStore.jsx b/language-web/src/main/js/RootStore.jsx
new file mode 100644
index 00000000..1ee2823d
--- /dev/null
+++ b/language-web/src/main/js/RootStore.jsx
@@ -0,0 +1,30 @@
1import { makeAutoObservable } from 'mobx';
2import React, { createContext, useContext } from 'react';
3
4import EditorStore from './editor/EditorStore';
5
6export default class RootStore {
7 editorStore;
8
9 constructor() {
10 this.editorStore = new EditorStore();
11 makeAutoObservable(this);
12 }
13}
14
15const StoreContext = createContext(undefined);
16
17export const RootStoreProvider = ({ children, rootStore }) => (
18 <StoreContext.Provider value={rootStore}>
19 {children}
20 </StoreContext.Provider>
21);
22
23/** @returns {RootStore} */
24export const useRootStore = () => {
25 const rootStore = useContext(StoreContext);
26 if (!rootStore) {
27 throw new Error('useRootStore must be used within RootStoreProvider');
28 }
29 return rootStore;
30};