diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2021-08-22 19:54:51 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2021-08-22 19:54:51 +0200 |
commit | 8cbf8fdcfdceab8a330bdc82e4260a55c125c37d (patch) | |
tree | 0354dcc6ce0704fc953e7665ecfcc700609549a2 /language-web/src/main/js/RootStore.tsx | |
parent | Bump Material-UI version (diff) | |
download | refinery-8cbf8fdcfdceab8a330bdc82e4260a55c125c37d.tar.gz refinery-8cbf8fdcfdceab8a330bdc82e4260a55c125c37d.tar.zst refinery-8cbf8fdcfdceab8a330bdc82e4260a55c125c37d.zip |
Covert language-web to TypeScript
Diffstat (limited to 'language-web/src/main/js/RootStore.tsx')
-rw-r--r-- | language-web/src/main/js/RootStore.tsx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/language-web/src/main/js/RootStore.tsx b/language-web/src/main/js/RootStore.tsx new file mode 100644 index 00000000..2159f440 --- /dev/null +++ b/language-web/src/main/js/RootStore.tsx | |||
@@ -0,0 +1,28 @@ | |||
1 | |||
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 | } | ||
12 | } | ||
13 | |||
14 | const StoreContext = createContext<RootStore | undefined>(undefined); | ||
15 | |||
16 | export const RootStoreProvider: React.FC<{ rootStore: RootStore }> = ({ children, rootStore }) => ( | ||
17 | <StoreContext.Provider value={rootStore}> | ||
18 | {children} | ||
19 | </StoreContext.Provider> | ||
20 | ); | ||
21 | |||
22 | export const useRootStore = () => { | ||
23 | const rootStore = useContext(StoreContext); | ||
24 | if (!rootStore) { | ||
25 | throw new Error('useRootStore must be used within RootStoreProvider'); | ||
26 | } | ||
27 | return rootStore; | ||
28 | }; | ||