aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared/src/stores/SharedStoreBase.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/shared/src/stores/SharedStoreBase.ts')
-rw-r--r--packages/shared/src/stores/SharedStoreBase.ts70
1 files changed, 70 insertions, 0 deletions
diff --git a/packages/shared/src/stores/SharedStoreBase.ts b/packages/shared/src/stores/SharedStoreBase.ts
new file mode 100644
index 0000000..8d6624b
--- /dev/null
+++ b/packages/shared/src/stores/SharedStoreBase.ts
@@ -0,0 +1,70 @@
1/*
2 * Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import {
22 IJsonPatch,
23 Instance,
24 types,
25 SnapshotIn,
26 SnapshotOut,
27 IAnyModelType,
28} from 'mobx-state-tree';
29
30import GlobalSettingsBase from './GlobalSettingsBase';
31import ProfileBase from './Profile';
32import ServiceBase from './ServiceBase';
33
34export function defineSharedStoreModel<
35 TG extends IAnyModelType,
36 TP extends IAnyModelType,
37 TS extends IAnyModelType,
38>(globalSettings: TG, profile: TP, service: TS) {
39 return types.model('SharedStore', {
40 settings: types.optional(globalSettings, {}),
41 profilesById: types.map(profile),
42 profiles: types.array(types.reference(profile)),
43 servicesById: types.map(service),
44 services: types.array(types.reference(service)),
45 shouldUseDarkColors: false,
46 });
47}
48
49const SharedStoreBase = /* @__PURE__ */ (() =>
50 defineSharedStoreModel(GlobalSettingsBase, ProfileBase, ServiceBase))();
51
52/*
53 eslint-disable-next-line @typescript-eslint/no-redeclare --
54 Intentionally naming the type the same as the store definition.
55*/
56interface SharedStoreBase extends Instance<typeof SharedStoreBase> {}
57
58export default SharedStoreBase;
59
60export interface SharedStoreSnapshotIn
61 extends SnapshotIn<typeof SharedStoreBase> {}
62
63export interface SharedStoreSnapshotOut
64 extends SnapshotOut<typeof SharedStoreBase> {}
65
66export interface SharedStoreListener {
67 onSnapshot(snapshot: SharedStoreSnapshotIn): void;
68
69 onPatch(patches: IJsonPatch[]): void;
70}