diff options
Diffstat (limited to 'subprojects/frontend/src/RootStore.ts')
-rw-r--r-- | subprojects/frontend/src/RootStore.ts | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/subprojects/frontend/src/RootStore.ts b/subprojects/frontend/src/RootStore.ts index b84c0ce0..e277c808 100644 --- a/subprojects/frontend/src/RootStore.ts +++ b/subprojects/frontend/src/RootStore.ts | |||
@@ -9,11 +9,20 @@ import { makeAutoObservable, runInAction } from 'mobx'; | |||
9 | 9 | ||
10 | import PWAStore from './PWAStore'; | 10 | import PWAStore from './PWAStore'; |
11 | import type EditorStore from './editor/EditorStore'; | 11 | import type EditorStore from './editor/EditorStore'; |
12 | import Compressor from './persistence/Compressor'; | ||
12 | import ThemeStore from './theme/ThemeStore'; | 13 | import ThemeStore from './theme/ThemeStore'; |
13 | 14 | ||
14 | const log = getLogger('RootStore'); | 15 | const log = getLogger('RootStore'); |
15 | 16 | ||
16 | export default class RootStore { | 17 | export default class RootStore { |
18 | private readonly compressor = new Compressor((text) => | ||
19 | this.setInitialValue(text), | ||
20 | ); | ||
21 | |||
22 | private initialValue: string | undefined; | ||
23 | |||
24 | private editorStoreClass: typeof EditorStore | undefined; | ||
25 | |||
17 | editorStore: EditorStore | undefined; | 26 | editorStore: EditorStore | undefined; |
18 | 27 | ||
19 | readonly pwaStore: PWAStore; | 28 | readonly pwaStore: PWAStore; |
@@ -22,10 +31,12 @@ export default class RootStore { | |||
22 | 31 | ||
23 | disposed = false; | 32 | disposed = false; |
24 | 33 | ||
25 | constructor(initialValue: string) { | 34 | constructor() { |
26 | this.pwaStore = new PWAStore(); | 35 | this.pwaStore = new PWAStore(); |
27 | this.themeStore = new ThemeStore(); | 36 | this.themeStore = new ThemeStore(); |
28 | makeAutoObservable(this, { | 37 | makeAutoObservable<RootStore, 'compressor' | 'editorStoreClass'>(this, { |
38 | compressor: false, | ||
39 | editorStoreClass: false, | ||
29 | pwaStore: false, | 40 | pwaStore: false, |
30 | themeStore: false, | 41 | themeStore: false, |
31 | }); | 42 | }); |
@@ -35,11 +46,27 @@ export default class RootStore { | |||
35 | if (this.disposed) { | 46 | if (this.disposed) { |
36 | return; | 47 | return; |
37 | } | 48 | } |
38 | this.editorStore = new EditorStore(initialValue, this.pwaStore); | 49 | this.editorStoreClass = EditorStore; |
50 | if (this.initialValue !== undefined) { | ||
51 | this.setInitialValue(this.initialValue); | ||
52 | } | ||
39 | }); | 53 | }); |
40 | })().catch((error) => { | 54 | })().catch((error) => { |
41 | log.error('Failed to load EditorStore', error); | 55 | log.error('Failed to load EditorStore', error); |
42 | }); | 56 | }); |
57 | this.compressor.decompressInitial(); | ||
58 | } | ||
59 | |||
60 | private setInitialValue(initialValue: string): void { | ||
61 | this.initialValue = initialValue; | ||
62 | if (this.editorStoreClass !== undefined) { | ||
63 | const EditorStore = this.editorStoreClass; | ||
64 | this.editorStore = new EditorStore( | ||
65 | this.initialValue, | ||
66 | this.pwaStore, | ||
67 | (text) => this.compressor.compress(text), | ||
68 | ); | ||
69 | } | ||
43 | } | 70 | } |
44 | 71 | ||
45 | dispose(): void { | 72 | dispose(): void { |
@@ -47,6 +74,7 @@ export default class RootStore { | |||
47 | return; | 74 | return; |
48 | } | 75 | } |
49 | this.editorStore?.dispose(); | 76 | this.editorStore?.dispose(); |
77 | this.compressor.dispose(); | ||
50 | this.disposed = true; | 78 | this.disposed = true; |
51 | } | 79 | } |
52 | } | 80 | } |