@applicaster/zapp-react-native-utils 14.0.0-alpha.3471443312 → 14.0.0-alpha.3497255033
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/actionsExecutor/ActionExecutorContext.tsx +60 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticPlayerListener.ts +5 -2
- package/analyticsUtils/AnalyticsEvents/helper.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/__tests__/analyticsUtils.test.js +0 -11
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +150 -29
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +8 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +27 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +112 -3
- package/appUtils/focusManagerAux/utils/utils.ios.ts +35 -0
- package/appUtils/platform/platformUtils.ts +33 -3
- package/appUtils/playerManager/conts.ts +21 -0
- package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
- package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
- package/arrayUtils/index.ts +6 -1
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/index.ts +1 -1
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +78 -4
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- package/manifestUtils/defaultManifestConfigurations/player.js +188 -2
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +12 -0
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/navigationUtils/index.ts +20 -17
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- package/playerUtils/getPlayerActionButtons.ts +1 -1
- package/playerUtils/index.ts +51 -0
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +12 -13
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +14 -9
- package/reactHooks/feed/useFeedLoader.tsx +36 -47
- package/reactHooks/feed/useInflatedUrl.ts +23 -29
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/layout/isTablet/index.ts +7 -3
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/screenPickerUtils/index.ts +13 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +1 -1
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +19 -1
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from "@applicaster/zapp-pipes-v2-client";
|
|
19
19
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
20
20
|
import { ENDPOINT_TAGS } from "../../types";
|
|
21
|
+
import { isNilOrEmpty } from "../../reactUtils/helpers";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* will match any occurrence in a string of one or more word characters
|
|
@@ -75,15 +76,19 @@ export const getInflatedDataSourceUrl: GetInflatedDataSourceUrl = ({
|
|
|
75
76
|
* https://foo.com/shows/A1234
|
|
76
77
|
*/
|
|
77
78
|
|
|
78
|
-
if (!
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
if (!isNilOrEmpty(mapping)) {
|
|
80
|
+
if (!source) {
|
|
81
|
+
if (__DEV__) {
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
throw new Error(
|
|
84
|
+
"getInflatedDataSourceUrl: source is empty while mapping is provided"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
return source || null;
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
// Hack because in tv we expect to get key names instead of values from the fake entry
|
|
@@ -193,28 +198,17 @@ export function useInflatedUrl({
|
|
|
193
198
|
|
|
194
199
|
const url = useMemo(
|
|
195
200
|
() =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
: feedUrl,
|
|
207
|
-
[feedUrl, mapping]
|
|
201
|
+
getInflatedDataSourceUrl({
|
|
202
|
+
source: feedUrl,
|
|
203
|
+
contexts: {
|
|
204
|
+
entry: entryContext,
|
|
205
|
+
screen: screenContext,
|
|
206
|
+
search: getSearchContext(searchContext, mapping),
|
|
207
|
+
},
|
|
208
|
+
mapping,
|
|
209
|
+
}),
|
|
210
|
+
[entryContext, feedUrl, mapping, screenContext, searchContext]
|
|
208
211
|
);
|
|
209
212
|
|
|
210
|
-
if (!feedUrl) {
|
|
211
|
-
logger.warning({
|
|
212
|
-
message: "Required parameter feedUrl is missing",
|
|
213
|
-
data: { feedUrl },
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
213
|
return url;
|
|
220
214
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAppDispatch,
|
|
3
|
+
ZappPipes,
|
|
4
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
5
|
+
import { applyScreenRouteDefaults } from "@applicaster/zapp-react-native-redux/ZappPipes/feedProcessor";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { useScreenResolvers } from "../../actionsExecutor/screenResolver";
|
|
8
|
+
import { useRoute } from "../navigation";
|
|
9
|
+
import { useScreenStateStore } from "../navigation/useScreenStateStore";
|
|
10
|
+
|
|
11
|
+
export const useLoadPipesDataDispatch = () => {
|
|
12
|
+
const screenStateStore = useScreenStateStore();
|
|
13
|
+
const resolvers = useScreenResolvers();
|
|
14
|
+
const dispatch = useAppDispatch();
|
|
15
|
+
|
|
16
|
+
const { pathname, screenData } = useRoute();
|
|
17
|
+
|
|
18
|
+
const riverId =
|
|
19
|
+
(screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
|
|
20
|
+
screenData?.id;
|
|
21
|
+
|
|
22
|
+
const onLoadCB = (options) => (data, _err) => {
|
|
23
|
+
options?.callback?.();
|
|
24
|
+
|
|
25
|
+
if (data) {
|
|
26
|
+
applyScreenRouteDefaults(data, screenStateStore, pathname);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return React.useCallback(
|
|
31
|
+
(
|
|
32
|
+
url: string,
|
|
33
|
+
options: {
|
|
34
|
+
callback?: (data: unknown, error?: Error | null | undefined) => void;
|
|
35
|
+
riverId?: string;
|
|
36
|
+
clearCache?: boolean;
|
|
37
|
+
silentRefresh?: boolean;
|
|
38
|
+
parentFeed?: string;
|
|
39
|
+
} = {},
|
|
40
|
+
{
|
|
41
|
+
withResolvers = false,
|
|
42
|
+
withScreenRouteMapping = false,
|
|
43
|
+
}: {
|
|
44
|
+
withResolvers?: boolean;
|
|
45
|
+
withScreenRouteMapping?: boolean;
|
|
46
|
+
} = {}
|
|
47
|
+
) => {
|
|
48
|
+
if (url) {
|
|
49
|
+
dispatch(
|
|
50
|
+
ZappPipes.loadPipesData(url, {
|
|
51
|
+
riverId,
|
|
52
|
+
resolvers: withResolvers ? resolvers : undefined,
|
|
53
|
+
...options,
|
|
54
|
+
callback: withScreenRouteMapping
|
|
55
|
+
? onLoadCB(options)
|
|
56
|
+
: options?.callback,
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[]
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
-
import { View } from "react-native";
|
|
3
|
+
import { View, ViewStyle } from "react-native";
|
|
4
4
|
|
|
5
5
|
import { platformSelect } from "../../reactUtils";
|
|
6
6
|
|
|
@@ -49,13 +49,13 @@ export const useSequentialRenderItem = (data: Data) => {
|
|
|
49
49
|
const readyToDisplay =
|
|
50
50
|
index === 0 ? true : arePreviousComponentsReady(index);
|
|
51
51
|
|
|
52
|
-
const displayStyle = {
|
|
52
|
+
const displayStyle: ViewStyle = {
|
|
53
53
|
display: readyToDisplay ? "flex" : "none",
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
const readyStyle = {
|
|
57
57
|
visibility: readyToDisplay ? "visible" : "hidden",
|
|
58
|
-
};
|
|
58
|
+
} as ViewStyle;
|
|
59
59
|
|
|
60
60
|
const style = platformSelect({
|
|
61
61
|
tvos: readyStyle,
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { NativeModules, Platform } from "react-native";
|
|
2
2
|
|
|
3
|
+
export const isAndroidTablet = () => {
|
|
4
|
+
const { initialProps } = NativeModules.QuickBrickCommunicationModule;
|
|
5
|
+
|
|
6
|
+
return initialProps?.is_tablet;
|
|
7
|
+
};
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* Determines wether the given device is a tablet based on dimensions, orientation, and platform
|
|
5
11
|
* @param {Object} dimensions - Dimensions object passed to the function
|
|
@@ -13,9 +19,7 @@ export const isTablet = (
|
|
|
13
19
|
if (Platform?.OS === "ios") {
|
|
14
20
|
return Platform?.isPad;
|
|
15
21
|
} else if (Platform?.OS === "android") {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return initialProps?.is_tablet;
|
|
22
|
+
return isAndroidTablet();
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
const { width } = dimensions || {};
|
|
@@ -14,7 +14,7 @@ import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
|
|
|
14
14
|
import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
|
|
15
15
|
import { useConnectionInfo } from "../connection";
|
|
16
16
|
|
|
17
|
-
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
17
|
+
import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
18
18
|
import { useNavbarState } from "../screen";
|
|
19
19
|
|
|
20
20
|
export { useNavigation } from "./useNavigation";
|
|
@@ -127,11 +127,13 @@ export function isNavBarVisible(
|
|
|
127
127
|
|
|
128
128
|
export const useBackHandler = (cb: () => boolean) => {
|
|
129
129
|
useEffect(() => {
|
|
130
|
-
|
|
130
|
+
if (!isWeb()) {
|
|
131
|
+
const unsubscribe = BackHandler.addEventListener("hardwareBackPress", cb);
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
return () => {
|
|
134
|
+
unsubscribe.remove();
|
|
135
|
+
};
|
|
136
|
+
}
|
|
135
137
|
}, [cb]);
|
|
136
138
|
};
|
|
137
139
|
|
|
@@ -28,14 +28,19 @@ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
|
28
28
|
|
|
29
29
|
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
30
30
|
|
|
31
|
-
export const useRoute = (
|
|
31
|
+
export const useRoute = (
|
|
32
|
+
useLegacy = true
|
|
33
|
+
): {
|
|
32
34
|
screenData: VariousScreenData;
|
|
33
35
|
pathname: string;
|
|
34
36
|
} => {
|
|
35
37
|
const pathname = usePathname() || "";
|
|
36
38
|
const navigator = useNavigation();
|
|
39
|
+
const screenContext = useContext(ScreenDataContext);
|
|
37
40
|
|
|
38
|
-
const screenDataContext =
|
|
41
|
+
const screenDataContext = useLegacy
|
|
42
|
+
? legacyScreenData(screenContext)
|
|
43
|
+
: screenContext;
|
|
39
44
|
|
|
40
45
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
41
46
|
"plugins",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
1
|
import { useRivers } from "./useRivers";
|
|
3
2
|
|
|
3
|
+
export const getHomeRiver = (rivers: Record<string, ZappRiver>) =>
|
|
4
|
+
Object.values(rivers).find((river: ZappRiver) => river.home);
|
|
5
|
+
|
|
4
6
|
export const useHomeRiver = () => {
|
|
5
7
|
const rivers = useRivers();
|
|
6
8
|
|
|
7
|
-
return
|
|
9
|
+
return getHomeRiver(rivers);
|
|
8
10
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getFocusableId = (id) => `PickerItem.${id}`;
|
|
2
|
+
|
|
3
|
+
export const getPickerSelectorId = (id) => `PickerSelector.${id}`;
|
|
4
|
+
|
|
5
|
+
export const SCREEN_PICKER_CONTAINER = "ScreenPickerContainer";
|
|
6
|
+
|
|
7
|
+
export const getScreenPickerId = (id) => `${SCREEN_PICKER_CONTAINER}.${id}`;
|
|
8
|
+
|
|
9
|
+
export const getScreenPickerSelectorContainerId = (id) =>
|
|
10
|
+
`${getScreenPickerId(id)}-screen-selector`;
|
|
11
|
+
|
|
12
|
+
export const getScreenPickerContentContainerId = (id) =>
|
|
13
|
+
`${getScreenPickerId(id)}-screen-container`;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { BehaviorSubject } from "rxjs";
|
|
2
|
+
import { SingleValueProvider } from "./StorageSingleSelectProvider";
|
|
3
|
+
import { createLogger } from "../logger";
|
|
4
|
+
import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
|
|
5
|
+
import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
|
|
6
|
+
|
|
7
|
+
export const { log_debug, log_error } = createLogger({
|
|
8
|
+
category: "ScreenSingleValueProvider",
|
|
9
|
+
subsystem: "zapp-react-native-bridge",
|
|
10
|
+
parent: bridgeLogger,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export class ScreenSingleValueProvider implements SingleValueProvider {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
private valueSubject: BehaviorSubject<string | null>;
|
|
16
|
+
private screenStateStoreUnsubscribe: (() => void) | null = null;
|
|
17
|
+
|
|
18
|
+
private static providers: Record<
|
|
19
|
+
string,
|
|
20
|
+
Record<string, SingleValueProvider>
|
|
21
|
+
> = {};
|
|
22
|
+
|
|
23
|
+
public static getProvider(
|
|
24
|
+
key: string,
|
|
25
|
+
screenRoute: string,
|
|
26
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
27
|
+
): SingleValueProvider {
|
|
28
|
+
if (!key) {
|
|
29
|
+
throw new Error("ScreenSingleValueProvider: Key is required");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!screenRoute) {
|
|
33
|
+
throw new Error("ScreenSingleValueProvider: Screen route is required");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!screenStateStore) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"ScreenSingleValueProvider: screen state store is required"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!this.providers[screenRoute]) {
|
|
43
|
+
this.providers[screenRoute] = {};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
if (!this.providers[screenRoute][key]) {
|
|
48
|
+
this.providers[screenRoute][key] = new ScreenSingleValueProvider(
|
|
49
|
+
key,
|
|
50
|
+
screenRoute,
|
|
51
|
+
screenStateStore
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
(
|
|
55
|
+
this.providers[screenRoute][key] as ScreenSingleValueProvider
|
|
56
|
+
).updateStore(screenStateStore);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
log_error("Failed to create provider", { key, screenRoute, error });
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return this.providers[screenRoute][key];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
private constructor(
|
|
68
|
+
private key: string,
|
|
69
|
+
route: string,
|
|
70
|
+
private screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
71
|
+
) {
|
|
72
|
+
if (!key) {
|
|
73
|
+
throw new Error("ScreenSingleValueProvider: Key is required");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!screenStateStore) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"ScreenSingleValueProvider: screen state store is required"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.key = key;
|
|
83
|
+
this.valueSubject = new BehaviorSubject<string | null>(null);
|
|
84
|
+
|
|
85
|
+
this.setupScreenStateSubscription();
|
|
86
|
+
|
|
87
|
+
void this.getValueAsync();
|
|
88
|
+
|
|
89
|
+
log_debug("ScreenSingleValueProvider: Initializing", { key, route });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private updateStore(
|
|
93
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
94
|
+
): void {
|
|
95
|
+
this.cleanup();
|
|
96
|
+
this.screenStateStore = screenStateStore;
|
|
97
|
+
this.setupScreenStateSubscription();
|
|
98
|
+
void this.getValueAsync();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private setupScreenStateSubscription(): void {
|
|
102
|
+
this.screenStateStoreUnsubscribe = this.screenStateStore.subscribe(
|
|
103
|
+
(state) => ({
|
|
104
|
+
value: state.data[this.key],
|
|
105
|
+
exists: this.key in state.data,
|
|
106
|
+
})
|
|
107
|
+
// (current, previous) => {
|
|
108
|
+
// if (!current.exists && previous.exists) {
|
|
109
|
+
// log_debug(
|
|
110
|
+
// `ScreenSingleValueProvider: Key deleted from store: ${this.key}`
|
|
111
|
+
// );
|
|
112
|
+
|
|
113
|
+
// // TODO: If we need to handle deletion, we can do it here
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// if (current.value !== previous.value) {
|
|
117
|
+
// this.valueSubject.next(current.value || null);
|
|
118
|
+
|
|
119
|
+
// log_debug(`ScreenSingleValueProvider: Key updated: ${this.key}`, {
|
|
120
|
+
// previous: previous.value,
|
|
121
|
+
// current: current.value,
|
|
122
|
+
// });
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
log_debug(
|
|
128
|
+
`ScreenSingleValueProvider: screen state store subscription setup for key: ${this.key}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private cleanup(): void {
|
|
133
|
+
if (this.screenStateStoreUnsubscribe) {
|
|
134
|
+
this.screenStateStoreUnsubscribe();
|
|
135
|
+
this.screenStateStoreUnsubscribe = null;
|
|
136
|
+
|
|
137
|
+
log_debug(
|
|
138
|
+
`ScreenSingleValueProvider: Unsubscribed from screen state store for key: ${this.key}`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
clearValue(): Promise<void> {
|
|
144
|
+
this.screenStateStore.getState().removeValue(this.key);
|
|
145
|
+
this.valueSubject.next(null);
|
|
146
|
+
|
|
147
|
+
log_debug(`clearValue: value cleared for key: ${this.key}`);
|
|
148
|
+
|
|
149
|
+
return Promise.resolve();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getObservable(): BehaviorSubject<string | null> {
|
|
153
|
+
return this.valueSubject;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getValue(): string | null {
|
|
157
|
+
return this.valueSubject.value;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getValueAsync(): Promise<string | null> {
|
|
161
|
+
const currentValue = this.screenStateStore.getState().data[this.key];
|
|
162
|
+
const value = currentValue || null;
|
|
163
|
+
const selected = this.getValue();
|
|
164
|
+
const valuesAreEqual = value === selected;
|
|
165
|
+
|
|
166
|
+
const bothEmpty =
|
|
167
|
+
(value === null || value === "") &&
|
|
168
|
+
(selected === null || selected === "");
|
|
169
|
+
|
|
170
|
+
if (!this.valueSubject.closed && !valuesAreEqual && !bothEmpty) {
|
|
171
|
+
this.valueSubject.next(value);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return Promise.resolve(value);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
setValue(value: string): Promise<void> {
|
|
178
|
+
this.screenStateStore.getState().setValue(this.key, value);
|
|
179
|
+
this.valueSubject.next(value);
|
|
180
|
+
|
|
181
|
+
log_debug(`setValue: value set for key: ${this.key}`, { value });
|
|
182
|
+
|
|
183
|
+
return Promise.resolve();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// TODO: remove if not needed
|
|
187
|
+
|
|
188
|
+
public static cleanupRoute(screenRoute: string): void {
|
|
189
|
+
if (this.providers[screenRoute]) {
|
|
190
|
+
Object.values(this.providers[screenRoute]).forEach((provider) => {
|
|
191
|
+
(provider as ScreenSingleValueProvider).destroy();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
delete this.providers[screenRoute];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// TODO: remove if not needed
|
|
199
|
+
|
|
200
|
+
public destroy(): void {
|
|
201
|
+
this.valueSubject.complete();
|
|
202
|
+
this.cleanup();
|
|
203
|
+
}
|
|
204
|
+
}
|