diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-27 01:02:02 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-02-08 21:43:17 +0100 |
commit | da610a51f49807d1409f36b98e06e89447a4202b (patch) | |
tree | a4f7911f45ca52626ef02f370c3f260d33f8272e /packages/main/src/stores/Profile.ts | |
parent | refactor: Coding conventions (diff) | |
download | sophie-da610a51f49807d1409f36b98e06e89447a4202b.tar.gz sophie-da610a51f49807d1409f36b98e06e89447a4202b.tar.zst sophie-da610a51f49807d1409f36b98e06e89447a4202b.zip |
refactor: Extract config handling
Move the handling of the contents of the config file out of the stores
and into dedicated files to simplify the code of the stores.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/stores/Profile.ts')
-rw-r--r-- | packages/main/src/stores/Profile.ts | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/packages/main/src/stores/Profile.ts b/packages/main/src/stores/Profile.ts index ec2a64b..0fd486e 100644 --- a/packages/main/src/stores/Profile.ts +++ b/packages/main/src/stores/Profile.ts | |||
@@ -18,19 +18,17 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { | 21 | import { Profile as ProfileBase } from '@sophie/shared'; |
22 | Profile as ProfileBase, | ||
23 | ProfileSettingsSnapshotIn, | ||
24 | } from '@sophie/shared'; | ||
25 | import { getSnapshot, Instance } from 'mobx-state-tree'; | 22 | import { getSnapshot, Instance } from 'mobx-state-tree'; |
26 | 23 | ||
27 | import generateId from '../utils/generateId'; | 24 | import overrideProps from '../utils/overrideProps'; |
28 | 25 | ||
29 | export interface ProfileConfig extends ProfileSettingsSnapshotIn { | 26 | import ProfileSettings from './ProfileSettings'; |
30 | id?: string | undefined; | 27 | import type ProfileConfig from './config/ProfileConfig'; |
31 | } | ||
32 | 28 | ||
33 | const Profile = ProfileBase.views((self) => ({ | 29 | const Profile = overrideProps(ProfileBase, { |
30 | settings: ProfileSettings, | ||
31 | }).views((self) => ({ | ||
34 | get config(): ProfileConfig { | 32 | get config(): ProfileConfig { |
35 | const { id, settings } = self; | 33 | const { id, settings } = self; |
36 | return { ...getSnapshot(settings), id }; | 34 | return { ...getSnapshot(settings), id }; |
@@ -44,17 +42,3 @@ const Profile = ProfileBase.views((self) => ({ | |||
44 | interface Profile extends Instance<typeof Profile> {} | 42 | interface Profile extends Instance<typeof Profile> {} |
45 | 43 | ||
46 | export default Profile; | 44 | export default Profile; |
47 | |||
48 | export type ProfileSettingsSnapshotWithId = [string, ProfileSettingsSnapshotIn]; | ||
49 | |||
50 | export function addMissingProfileIds( | ||
51 | profileConfigs: ProfileConfig[] | undefined, | ||
52 | ): ProfileSettingsSnapshotWithId[] { | ||
53 | return (profileConfigs ?? []).map((profileConfig) => { | ||
54 | const { id, ...settings } = profileConfig; | ||
55 | return [ | ||
56 | typeof id === 'undefined' ? generateId(settings.name) : id, | ||
57 | settings, | ||
58 | ]; | ||
59 | }); | ||
60 | } | ||