diff options
author | 2021-12-23 15:48:58 +0100 | |
---|---|---|
committer | 2021-12-23 15:48:58 +0100 | |
commit | b5d16a8068ed55b784f8e10f19a99cc7f11b8bc7 (patch) | |
tree | d819b4bb607f5b046451e15385c16804d5f43fcf /packages/renderer/src/index.tsx | |
parent | feat: Main to renderer store synchronization (diff) | |
download | sophie-b5d16a8068ed55b784f8e10f19a99cc7f11b8bc7.tar.gz sophie-b5d16a8068ed55b784f8e10f19a99cc7f11b8bc7.tar.zst sophie-b5d16a8068ed55b784f8e10f19a99cc7f11b8bc7.zip |
feat: Add react and mobx integration
Diffstat (limited to 'packages/renderer/src/index.tsx')
-rw-r--r-- | packages/renderer/src/index.tsx | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/packages/renderer/src/index.tsx b/packages/renderer/src/index.tsx index 37daaa6..34b21de 100644 --- a/packages/renderer/src/index.tsx +++ b/packages/renderer/src/index.tsx | |||
@@ -2,56 +2,49 @@ import '@fontsource/roboto/300.css'; | |||
2 | import '@fontsource/roboto/400.css'; | 2 | import '@fontsource/roboto/400.css'; |
3 | import '@fontsource/roboto/500.css'; | 3 | import '@fontsource/roboto/500.css'; |
4 | import '@fontsource/roboto/700.css'; | 4 | import '@fontsource/roboto/700.css'; |
5 | import { applyPatch, applySnapshot } from 'mobx-state-tree'; | 5 | import { observer } from 'mobx-react-lite'; |
6 | import Button from "@mui/material/Button"; | 6 | import Button from "@mui/material/Button"; |
7 | import CssBaseline from "@mui/material/CssBaseline"; | 7 | import CssBaseline from "@mui/material/CssBaseline"; |
8 | import { | ||
9 | unstable_createMuiStrictModeTheme as createTheme, | ||
10 | ThemeProvider, | ||
11 | } from '@mui/material/styles'; | ||
12 | import React from 'react'; | 8 | import React from 'react'; |
13 | import { render } from 'react-dom'; | 9 | import { render } from 'react-dom'; |
14 | import { sharedStore } from '@sophie/shared'; | ||
15 | 10 | ||
11 | import { StoreProvider, useStore } from './components/StoreProvider'; | ||
12 | import { ThemeProvider } from './components/ThemeProvider'; | ||
16 | import { exposeToReduxDevtools } from './devTools'; | 13 | import { exposeToReduxDevtools } from './devTools'; |
14 | import { createAndConnectRootStore } from './stores/RootStore'; | ||
17 | 15 | ||
18 | const isDevelopment = import.meta.env.MODE === 'development'; | 16 | const isDevelopment = import.meta.env.MODE === 'development'; |
19 | 17 | ||
20 | const store = sharedStore.create(); | 18 | const store = createAndConnectRootStore(window.sophieRenderer); |
21 | 19 | ||
22 | if (isDevelopment) { | 20 | if (isDevelopment) { |
23 | exposeToReduxDevtools(store); | 21 | exposeToReduxDevtools(store); |
24 | } | 22 | } |
25 | 23 | ||
26 | window.sophieRenderer.setSharedStoreListener({ | 24 | const Example = observer(() => { |
27 | onSnapshot(snapshot) { | 25 | const { shared: { clickCount } } = useStore(); |
28 | applySnapshot(store, snapshot); | ||
29 | }, | ||
30 | onPatch(patch) { | ||
31 | applyPatch(store, patch); | ||
32 | }, | ||
33 | }); | ||
34 | 26 | ||
35 | const theme = createTheme({ | 27 | return ( |
36 | palette: { | 28 | <Button |
37 | mode: 'dark', | 29 | variant="contained" |
38 | }, | 30 | onClick={() => store.buttonClick()} |
31 | > | ||
32 | Hello Sophie! {clickCount} | ||
33 | </Button> | ||
34 | ); | ||
39 | }); | 35 | }); |
40 | 36 | ||
41 | function App() { | 37 | function Root(): JSX.Element { |
42 | return ( | 38 | return ( |
43 | <React.StrictMode> | 39 | <React.StrictMode> |
44 | <ThemeProvider theme={theme}> | 40 | <StoreProvider store={store}> |
45 | <CssBaseline enableColorScheme /> | 41 | <ThemeProvider> |
46 | <Button | 42 | <CssBaseline enableColorScheme /> |
47 | variant="contained" | 43 | <Example /> |
48 | onClick={window.sophieRenderer.buttonClick} | 44 | </ThemeProvider> |
49 | > | 45 | </StoreProvider> |
50 | Hello Sophie! | ||
51 | </Button> | ||
52 | </ThemeProvider> | ||
53 | </React.StrictMode> | 46 | </React.StrictMode> |
54 | ); | 47 | ); |
55 | } | 48 | } |
56 | 49 | ||
57 | render(<App />, document.querySelector('#app')); | 50 | render(<Root />, document.querySelector('#app')); |