diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-10-07 19:44:41 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-11-05 19:41:14 +0100 |
commit | abe176d0888c0fdcc803ddafe71a5cee9f4b63a0 (patch) | |
tree | ea7d5722c8e981ba540e648fbacbfd0e4a55768a /subprojects/frontend/src/RootStore.ts | |
parent | fix: test and lint failures (diff) | |
download | refinery-abe176d0888c0fdcc803ddafe71a5cee9f4b63a0.tar.gz refinery-abe176d0888c0fdcc803ddafe71a5cee9f4b63a0.tar.zst refinery-abe176d0888c0fdcc803ddafe71a5cee9f4b63a0.zip |
refactor(frontend): improve HMR experience
Use a HMR acceptor as in
https://github.com/vitejs/vite/issues/10227#issuecomment-1256969751
Also updates frontend tooling to the latest version
(yarn now support typescript 4.8.4)
Diffstat (limited to 'subprojects/frontend/src/RootStore.ts')
-rw-r--r-- | subprojects/frontend/src/RootStore.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/subprojects/frontend/src/RootStore.ts b/subprojects/frontend/src/RootStore.ts new file mode 100644 index 00000000..54a80501 --- /dev/null +++ b/subprojects/frontend/src/RootStore.ts | |||
@@ -0,0 +1,47 @@ | |||
1 | import { getLogger } from 'loglevel'; | ||
2 | import { makeAutoObservable, runInAction } from 'mobx'; | ||
3 | |||
4 | import PWAStore from './PWAStore'; | ||
5 | import type EditorStore from './editor/EditorStore'; | ||
6 | import ThemeStore from './theme/ThemeStore'; | ||
7 | |||
8 | const log = getLogger('RootStore'); | ||
9 | |||
10 | export default class RootStore { | ||
11 | editorStore: EditorStore | undefined; | ||
12 | |||
13 | readonly pwaStore: PWAStore; | ||
14 | |||
15 | readonly themeStore: ThemeStore; | ||
16 | |||
17 | disposed = false; | ||
18 | |||
19 | constructor(initialValue: string) { | ||
20 | this.pwaStore = new PWAStore(); | ||
21 | this.themeStore = new ThemeStore(); | ||
22 | makeAutoObservable(this, { | ||
23 | pwaStore: false, | ||
24 | themeStore: false, | ||
25 | }); | ||
26 | import('./editor/EditorStore') | ||
27 | .then(({ default: EditorStore }) => { | ||
28 | runInAction(() => { | ||
29 | if (this.disposed) { | ||
30 | return; | ||
31 | } | ||
32 | this.editorStore = new EditorStore(initialValue, this.pwaStore); | ||
33 | }); | ||
34 | }) | ||
35 | .catch((error) => { | ||
36 | log.error('Failed to load EditorStore', error); | ||
37 | }); | ||
38 | } | ||
39 | |||
40 | dispose(): void { | ||
41 | if (this.disposed) { | ||
42 | return; | ||
43 | } | ||
44 | this.editorStore?.dispose(); | ||
45 | this.disposed = true; | ||
46 | } | ||
47 | } | ||