diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-26 19:59:04 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-26 20:02:08 +0100 |
commit | 4ef4306cf401829905f764845ed78ac072fb94b6 (patch) | |
tree | 980a91a11cb1ac5f730d72c385e542edd0617d82 /packages/renderer/src/stores | |
parent | refactor: Clarify main process architecture (diff) | |
download | sophie-4ef4306cf401829905f764845ed78ac072fb94b6.tar.gz sophie-4ef4306cf401829905f764845ed78ac072fb94b6.tar.zst sophie-4ef4306cf401829905f764845ed78ac072fb94b6.zip |
refactor: Make all stores optional
This reduces boilerplate and helps with config file robustness: if a
field is missing from the config file, it will be replaced with its
default value.
Diffstat (limited to 'packages/renderer/src/stores')
-rw-r--r-- | packages/renderer/src/stores/RootStore.ts | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/packages/renderer/src/stores/RootStore.ts b/packages/renderer/src/stores/RootStore.ts index 20e0afa..f7f37f0 100644 --- a/packages/renderer/src/stores/RootStore.ts +++ b/packages/renderer/src/stores/RootStore.ts | |||
@@ -28,7 +28,6 @@ import { | |||
28 | } from 'mobx-state-tree'; | 28 | } from 'mobx-state-tree'; |
29 | import { | 29 | import { |
30 | BrowserViewBounds, | 30 | BrowserViewBounds, |
31 | emptySharedStore, | ||
32 | sharedStore, | 31 | sharedStore, |
33 | SophieRenderer, | 32 | SophieRenderer, |
34 | ThemeSource, | 33 | ThemeSource, |
@@ -50,7 +49,7 @@ export function getEnv(model: IAnyStateTreeNode): RootEnv { | |||
50 | } | 49 | } |
51 | 50 | ||
52 | export const rootStore = types.model('RootStore', { | 51 | export const rootStore = types.model('RootStore', { |
53 | shared: sharedStore, | 52 | shared: types.optional(sharedStore, {}), |
54 | }).actions((self) => ({ | 53 | }).actions((self) => ({ |
55 | setBrowserViewBounds(bounds: BrowserViewBounds) { | 54 | setBrowserViewBounds(bounds: BrowserViewBounds) { |
56 | getEnv(self).ipc.setBrowserViewBounds(bounds); | 55 | getEnv(self).ipc.setBrowserViewBounds(bounds); |
@@ -78,9 +77,7 @@ export interface RootStore extends Instance<typeof rootStore> {} | |||
78 | * @param ipc The `sophieRenderer` context bridge. | 77 | * @param ipc The `sophieRenderer` context bridge. |
79 | */ | 78 | */ |
80 | export function createAndConnectRootStore(ipc: SophieRenderer): RootStore { | 79 | export function createAndConnectRootStore(ipc: SophieRenderer): RootStore { |
81 | const store = rootStore.create({ | 80 | const store = rootStore.create({}, { |
82 | shared: emptySharedStore, | ||
83 | }, { | ||
84 | ipc, | 81 | ipc, |
85 | }); | 82 | }); |
86 | 83 | ||