diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2021-07-01 12:31:07 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2021-07-01 12:31:07 +0200 |
commit | 8595c9a22830b1baacc49bb694d70389b2539eba (patch) | |
tree | cb496cd34661a0d3ec4c9b5a333e948f24e437f4 /language-web/src/main/js/RootStore.jsx | |
parent | Convert to React app (diff) | |
download | refinery-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.jsx | 30 |
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 @@ | |||
1 | import { makeAutoObservable } from 'mobx'; | ||
2 | import React, { createContext, useContext } from 'react'; | ||
3 | |||
4 | import EditorStore from './editor/EditorStore'; | ||
5 | |||
6 | export default class RootStore { | ||
7 | editorStore; | ||
8 | |||
9 | constructor() { | ||
10 | this.editorStore = new EditorStore(); | ||
11 | makeAutoObservable(this); | ||
12 | } | ||
13 | } | ||
14 | |||
15 | const StoreContext = createContext(undefined); | ||
16 | |||
17 | export const RootStoreProvider = ({ children, rootStore }) => ( | ||
18 | <StoreContext.Provider value={rootStore}> | ||
19 | {children} | ||
20 | </StoreContext.Provider> | ||
21 | ); | ||
22 | |||
23 | /** @returns {RootStore} */ | ||
24 | export 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 | }; | ||