Merge branch '19783-picking-tweak' refs #19783
[arvados-workbench2.git] / src / common / service-provider.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 class ServicesProvider {
6
7     private static instance: ServicesProvider;
8
9     private store;
10     private services;
11
12     private constructor() {}
13
14     public static getInstance(): ServicesProvider {
15         if (!ServicesProvider.instance) {
16             ServicesProvider.instance = new ServicesProvider();
17         }
18
19         return ServicesProvider.instance;
20     }
21
22     public setServices(newServices): void {
23         if (!this.services) {
24             this.services = newServices;
25         }
26     }
27
28     public getServices() {
29         if (!this.services) {
30             throw "Please check if services have been set in the index.ts before the app is initiated"; // eslint-disable-line no-throw-literal
31         }
32         return this.services;
33     }
34
35     public setStore(newStore): void {
36         if (!this.store) {
37             this.store = newStore;
38         }
39     }
40
41     public getStore() {
42         if (!this.store) {
43             throw "Please check if store has been set in the index.ts before the app is initiated"; // eslint-disable-line no-throw-literal
44         }
45
46         return this.store;
47     }
48 }
49
50 export default ServicesProvider.getInstance();