@servicetitan/standalone-root 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/components/standalone-root-provider/standalone-root-provider.d.ts +3 -2
- package/dist/components/standalone-root-provider/standalone-root-provider.d.ts.map +1 -1
- package/dist/components/standalone-root-provider/standalone-root-provider.js +12 -11
- package/dist/components/standalone-root-provider/standalone-root-provider.js.map +1 -1
- package/dist/enums/root-section.d.ts +7 -2
- package/dist/enums/root-section.d.ts.map +1 -1
- package/dist/enums/root-section.js +9 -4
- package/dist/enums/root-section.js.map +1 -1
- package/dist/stores/standalone-root.store.d.ts +10 -9
- package/dist/stores/standalone-root.store.d.ts.map +1 -1
- package/dist/stores/standalone-root.store.js +47 -28
- package/dist/stores/standalone-root.store.js.map +1 -1
- package/dist/utils/symbols.d.ts +1 -1
- package/dist/utils/symbols.d.ts.map +1 -1
- package/dist/utils/symbols.js +1 -1
- package/dist/utils/symbols.js.map +1 -1
- package/dist/utils/tokens.d.ts +3 -2
- package/dist/utils/tokens.d.ts.map +1 -1
- package/dist/utils/tokens.js +2 -1
- package/dist/utils/tokens.js.map +1 -1
- package/package.json +2 -2
- package/src/components/standalone-root-provider/standalone-root-provider.tsx +22 -18
- package/src/enums/root-section.ts +7 -2
- package/src/stores/standalone-root.store.ts +45 -27
- package/src/utils/symbols.ts +1 -1
- package/src/utils/tokens.ts +8 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { makeObservable, observable, runInAction } from 'mobx';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
UserDetails,
|
|
5
5
|
PartitionInfo,
|
|
6
6
|
PartitionsClientApi,
|
|
7
|
-
|
|
7
|
+
CurrentUserClientApi,
|
|
8
8
|
} from '@servicetitan/marketing-services-api/identity';
|
|
9
|
-
import { LoadStatus, SymbolTokenDataType } from '@servicetitan/standalone-ui';
|
|
10
9
|
import { inject, injectable } from '@servicetitan/react-ioc';
|
|
11
10
|
import {
|
|
12
11
|
AppConfigApi,
|
|
13
12
|
AppSettings,
|
|
14
13
|
} from '@servicetitan/marketing-services-api/dist/common/app-config.mrk.api';
|
|
14
|
+
import { LoadStatus, SymbolTokenDataType } from '@servicetitan/standalone-ui';
|
|
15
15
|
import { TenantManagementApi, TenantModel } from '@servicetitan/standalone-tm-api';
|
|
16
16
|
import { OnboardingApi, OnboardingResponse } from '@servicetitan/marketing-services-api/settings';
|
|
17
17
|
|
|
18
|
-
import { Events } from '../utils/events';
|
|
19
|
-
import { EventEmitter } from '../utils/event-emitter';
|
|
20
18
|
import {
|
|
21
19
|
storageKeyForUser,
|
|
22
20
|
storageKeyForLocale,
|
|
@@ -26,10 +24,12 @@ import {
|
|
|
26
24
|
storageKeyForAppSettings,
|
|
27
25
|
storageKeyForTenantConfigs,
|
|
28
26
|
} from '../utils/storage-keys';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
27
|
+
import { RootSection } from '../enums';
|
|
28
|
+
import { Events } from '../utils/events';
|
|
29
|
+
import { EventEmitter } from '../utils/event-emitter';
|
|
30
|
+
import { REFRESH_SECTIONS_TOKEN, SIDE_EFFECTS_TOKEN } from '../utils/tokens';
|
|
31
31
|
import { cultureKeyInCoreConfigs, defaultLocale, defaultTimezone } from '../utils/constants';
|
|
32
|
-
import { eventEmitterSymbol, isInitializedSymbol,
|
|
32
|
+
import { eventEmitterSymbol, isInitializedSymbol, sideEffectsSymbol } from '../utils/symbols';
|
|
33
33
|
|
|
34
34
|
@injectable()
|
|
35
35
|
export class StandaloneRootStore {
|
|
@@ -52,8 +52,10 @@ export class StandaloneRootStore {
|
|
|
52
52
|
@inject(CurrentUserClientApi) private readonly currentUserClientApi: CurrentUserClientApi,
|
|
53
53
|
@inject(OnboardingApi) private readonly onboardingApi: OnboardingApi,
|
|
54
54
|
@inject(PartitionsClientApi) private readonly partitionsApi: PartitionsClientApi,
|
|
55
|
-
@inject(
|
|
56
|
-
private readonly
|
|
55
|
+
@inject(SIDE_EFFECTS_TOKEN)
|
|
56
|
+
private readonly sideEffects: SymbolTokenDataType<typeof SIDE_EFFECTS_TOKEN>,
|
|
57
|
+
@inject(REFRESH_SECTIONS_TOKEN)
|
|
58
|
+
private readonly refreshSections: SymbolTokenDataType<typeof REFRESH_SECTIONS_TOKEN>,
|
|
57
59
|
) {
|
|
58
60
|
this.initializeEventEmitter();
|
|
59
61
|
makeObservable(this);
|
|
@@ -100,12 +102,25 @@ export class StandaloneRootStore {
|
|
|
100
102
|
const isSuccess = this.syncFromStorage();
|
|
101
103
|
|
|
102
104
|
if (isSuccess) {
|
|
103
|
-
|
|
105
|
+
const registeredSideEffects = this.registeredSideEffects;
|
|
106
|
+
|
|
107
|
+
if (registeredSideEffects?.length || this.refreshSections?.length) {
|
|
108
|
+
const distinctSections = Array.from(
|
|
109
|
+
new Set([
|
|
110
|
+
...(this.registeredSideEffects ?? []),
|
|
111
|
+
...(this.refreshSections ?? []),
|
|
112
|
+
]),
|
|
113
|
+
);
|
|
114
|
+
|
|
104
115
|
await Promise.all(
|
|
105
|
-
|
|
116
|
+
distinctSections.map(section =>
|
|
106
117
|
this.mapModifiableSectionToFetcher[section](),
|
|
107
118
|
),
|
|
108
119
|
);
|
|
120
|
+
|
|
121
|
+
if (registeredSideEffects?.length) {
|
|
122
|
+
this.unregisterSideEffects();
|
|
123
|
+
}
|
|
109
124
|
}
|
|
110
125
|
} else {
|
|
111
126
|
await fetchAll();
|
|
@@ -116,8 +131,6 @@ export class StandaloneRootStore {
|
|
|
116
131
|
this.setIsInitialized(true);
|
|
117
132
|
}
|
|
118
133
|
|
|
119
|
-
this.removeRegisteredChanges();
|
|
120
|
-
|
|
121
134
|
const timezoneFetched = this.tenantConfigs.TimeZone;
|
|
122
135
|
|
|
123
136
|
if (timezoneFetched) {
|
|
@@ -158,22 +171,22 @@ export class StandaloneRootStore {
|
|
|
158
171
|
}
|
|
159
172
|
|
|
160
173
|
dispose = () => {
|
|
161
|
-
this.
|
|
174
|
+
this.registerSideEffects();
|
|
162
175
|
this.unregisterGlobalSyncListener();
|
|
163
176
|
};
|
|
164
177
|
|
|
165
|
-
private
|
|
166
|
-
if (this.
|
|
167
|
-
(window as any)[
|
|
178
|
+
private registerSideEffects = () => {
|
|
179
|
+
if (this.sideEffects?.length) {
|
|
180
|
+
(window as any)[sideEffectsSymbol] = this.sideEffects;
|
|
168
181
|
}
|
|
169
182
|
};
|
|
170
183
|
|
|
171
|
-
private
|
|
172
|
-
(window as any)[
|
|
184
|
+
private unregisterSideEffects = () => {
|
|
185
|
+
(window as any)[sideEffectsSymbol] = undefined;
|
|
173
186
|
};
|
|
174
187
|
|
|
175
188
|
private unregisterGlobalSyncListener = () => {
|
|
176
|
-
this.eventEmitter.off(Events.SyncFromStorage, this.
|
|
189
|
+
this.eventEmitter.off(Events.SyncFromStorage, this.globalSyncListener);
|
|
177
190
|
};
|
|
178
191
|
|
|
179
192
|
private initializeEventEmitter = () => {
|
|
@@ -188,10 +201,10 @@ export class StandaloneRootStore {
|
|
|
188
201
|
};
|
|
189
202
|
|
|
190
203
|
private registerGlobalSyncListener = () => {
|
|
191
|
-
this.eventEmitter.on(Events.SyncFromStorage, this.
|
|
204
|
+
this.eventEmitter.on(Events.SyncFromStorage, this.globalSyncListener);
|
|
192
205
|
};
|
|
193
206
|
|
|
194
|
-
private
|
|
207
|
+
private globalSyncListener = (instanceSymbol: symbol) => {
|
|
195
208
|
if (instanceSymbol !== this.currentInstanceSymbol) {
|
|
196
209
|
this.syncFromStorage();
|
|
197
210
|
}
|
|
@@ -322,13 +335,18 @@ export class StandaloneRootStore {
|
|
|
322
335
|
return !!(window as any)[isInitializedSymbol];
|
|
323
336
|
}
|
|
324
337
|
|
|
325
|
-
private get
|
|
326
|
-
return (window as any)[
|
|
338
|
+
private get registeredSideEffects(): typeof this.sideEffects {
|
|
339
|
+
return (window as any)[sideEffectsSymbol];
|
|
327
340
|
}
|
|
328
341
|
|
|
329
|
-
private get mapModifiableSectionToFetcher(): Record<
|
|
342
|
+
private get mapModifiableSectionToFetcher(): Record<RootSection, () => void> {
|
|
330
343
|
return {
|
|
331
|
-
[
|
|
344
|
+
[RootSection.Tenant]: this.fetchTenant,
|
|
345
|
+
[RootSection.TenantConfigs]: this.fetchTenantConfigs,
|
|
346
|
+
[RootSection.User]: this.fetchUser,
|
|
347
|
+
[RootSection.AppSettings]: this.fetchAppSettings,
|
|
348
|
+
[RootSection.Onboarding]: this.fetchOnboarding,
|
|
349
|
+
[RootSection.Partitions]: this.fetchPartitions,
|
|
332
350
|
};
|
|
333
351
|
}
|
|
334
352
|
}
|
package/src/utils/symbols.ts
CHANGED
|
@@ -4,4 +4,4 @@ const registeredChangesSymbolKey = 'standalone-root-modifiable-changes-symbol-ke
|
|
|
4
4
|
|
|
5
5
|
export const isInitializedSymbol = Symbol.for(rootSymbolKey);
|
|
6
6
|
export const eventEmitterSymbol = Symbol.for(eventEmitterSymbolKey);
|
|
7
|
-
export const
|
|
7
|
+
export const sideEffectsSymbol = Symbol.for(registeredChangesSymbolKey);
|
package/src/utils/tokens.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { symbolToken } from '@servicetitan/react-ioc';
|
|
2
|
-
import {
|
|
2
|
+
import { RootSection } from '../enums';
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
'
|
|
4
|
+
export const SIDE_EFFECTS_TOKEN = symbolToken<RootSection[] | undefined>(
|
|
5
|
+
'SIDE_EFFECTS_TOKEN',
|
|
6
|
+
false,
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export const REFRESH_SECTIONS_TOKEN = symbolToken<RootSection[] | undefined>(
|
|
10
|
+
'REFRESH_SECTIONS_TOKEN',
|
|
6
11
|
false,
|
|
7
12
|
);
|