@applicaster/zapp-react-native-utils 14.0.0-rc.8 → 15.0.0-rc.1

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.
Files changed (135) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +60 -84
  2. package/actionsExecutor/ScreenActions.ts +164 -0
  3. package/actionsExecutor/StorageActions.ts +110 -0
  4. package/actionsExecutor/feedDecorator.ts +171 -0
  5. package/actionsExecutor/screenResolver.ts +11 -0
  6. package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
  7. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  8. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  9. package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
  10. package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
  11. package/analyticsUtils/events.ts +8 -0
  12. package/analyticsUtils/index.tsx +3 -4
  13. package/analyticsUtils/manager.ts +1 -1
  14. package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
  15. package/appUtils/HooksManager/Hook.ts +4 -4
  16. package/appUtils/HooksManager/index.ts +11 -1
  17. package/appUtils/accessibilityManager/const.ts +13 -0
  18. package/appUtils/accessibilityManager/hooks.ts +35 -1
  19. package/appUtils/accessibilityManager/index.ts +154 -30
  20. package/appUtils/accessibilityManager/utils.ts +24 -0
  21. package/appUtils/contextKeysManager/contextResolver.ts +42 -1
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -0
  23. package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
  24. package/appUtils/focusManager/events.ts +2 -0
  25. package/appUtils/focusManager/index.ios.ts +10 -0
  26. package/appUtils/focusManager/index.ts +86 -11
  27. package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
  28. package/appUtils/focusManagerAux/utils/index.ts +94 -3
  29. package/appUtils/platform/platformUtils.ts +31 -1
  30. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
  31. package/appUtils/playerManager/useChapterMarker.tsx +0 -1
  32. package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
  33. package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
  34. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  35. package/arrayUtils/index.ts +8 -3
  36. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
  37. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
  38. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
  39. package/audioPlayerUtils/assets/index.ts +2 -0
  40. package/audioPlayerUtils/index.ts +242 -0
  41. package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
  42. package/componentsUtils/index.ts +4 -1
  43. package/conf/player/__tests__/selectors.test.ts +34 -0
  44. package/conf/player/selectors.ts +10 -0
  45. package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
  46. package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
  47. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
  48. package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
  49. package/configurationUtils/index.ts +64 -35
  50. package/configurationUtils/manifestKeyParser.ts +57 -32
  51. package/focusManager/FocusManager.ts +104 -20
  52. package/focusManager/Tree.ts +25 -21
  53. package/focusManager/__tests__/FocusManager.test.ts +50 -8
  54. package/focusManager/aux/index.ts +98 -0
  55. package/focusManager/utils.ts +12 -6
  56. package/index.d.ts +1 -10
  57. package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
  58. package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
  59. package/manifestUtils/createConfig.js +4 -1
  60. package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
  61. package/manifestUtils/index.js +4 -0
  62. package/manifestUtils/keys.js +12 -0
  63. package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
  64. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
  65. package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
  66. package/navigationUtils/index.ts +7 -5
  67. package/package.json +2 -3
  68. package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
  69. package/playerUtils/PlayerTTS/index.ts +1 -0
  70. package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
  71. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
  72. package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
  73. package/playerUtils/_internals/index.ts +1 -0
  74. package/playerUtils/_internals/utils.ts +31 -0
  75. package/playerUtils/configurationUtils.ts +0 -44
  76. package/playerUtils/getPlayerActionButtons.ts +17 -0
  77. package/playerUtils/index.ts +53 -0
  78. package/playerUtils/usePlayerTTS.ts +21 -0
  79. package/playerUtils/useValidatePlayerConfig.tsx +22 -19
  80. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
  81. package/reactHooks/cell-click/__tests__/index.test.js +3 -0
  82. package/reactHooks/cell-click/index.ts +8 -1
  83. package/reactHooks/debugging/__tests__/index.test.js +0 -1
  84. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
  85. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
  86. package/reactHooks/feed/index.ts +2 -0
  87. package/reactHooks/feed/useBatchLoading.ts +17 -10
  88. package/reactHooks/feed/useFeedLoader.tsx +36 -34
  89. package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
  90. package/reactHooks/feed/usePipesCacheReset.ts +3 -3
  91. package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
  92. package/reactHooks/layout/__tests__/index.test.tsx +3 -1
  93. package/reactHooks/layout/isTablet/index.ts +12 -5
  94. package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
  95. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
  96. package/reactHooks/layout/useLayoutVersion.ts +5 -5
  97. package/reactHooks/navigation/index.ts +7 -5
  98. package/reactHooks/navigation/useIsScreenActive.ts +9 -5
  99. package/reactHooks/navigation/useRoute.ts +7 -2
  100. package/reactHooks/navigation/useScreenStateStore.ts +8 -0
  101. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
  102. package/reactHooks/screen/useScreenContext.ts +1 -1
  103. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
  104. package/reactHooks/state/index.ts +1 -1
  105. package/reactHooks/state/useHomeRiver.ts +4 -2
  106. package/reactHooks/state/useRivers.ts +7 -8
  107. package/riverComponetsMeasurementProvider/index.tsx +1 -1
  108. package/screenPickerUtils/index.ts +13 -0
  109. package/services/js2native.ts +1 -0
  110. package/storage/ScreenSingleValueProvider.ts +204 -0
  111. package/storage/ScreenStateMultiSelectProvider.ts +293 -0
  112. package/storage/StorageMultiSelectProvider.ts +192 -0
  113. package/storage/StorageSingleSelectProvider.ts +108 -0
  114. package/testUtils/index.tsx +7 -8
  115. package/time/BackgroundTimer.ts +6 -4
  116. package/utils/__tests__/endsWith.test.ts +30 -0
  117. package/utils/__tests__/find.test.ts +36 -0
  118. package/utils/__tests__/omit.test.ts +19 -0
  119. package/utils/__tests__/path.test.ts +33 -0
  120. package/utils/__tests__/pathOr.test.ts +37 -0
  121. package/utils/__tests__/startsWith.test.ts +30 -0
  122. package/utils/__tests__/take.test.ts +40 -0
  123. package/utils/endsWith.ts +9 -0
  124. package/utils/find.ts +3 -0
  125. package/utils/index.ts +33 -1
  126. package/utils/omit.ts +5 -0
  127. package/utils/path.ts +5 -0
  128. package/utils/pathOr.ts +5 -0
  129. package/utils/startsWith.ts +9 -0
  130. package/utils/take.ts +5 -0
  131. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +164 -0
  132. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +60 -0
  133. package/zappFrameworkUtils/HookCallback/useCallbackActions.ts +22 -0
  134. package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
  135. package/playerUtils/configurationGenerator.ts +0 -2572
@@ -1,29 +1,33 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
- import * as reduxMockStore from "redux-mock-store";
3
- import thunk from "redux-thunk";
4
- import React from "react";
5
- import * as ReactRedux from "react-redux";
2
+ import { allFeedsIsReady, useBatchLoading } from "../useBatchLoading";
3
+ import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
4
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
5
+ import { waitFor } from "@testing-library/react-native";
6
6
 
7
7
  jest.mock("../../navigation");
8
8
 
9
9
  jest.mock(
10
10
  "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext",
11
11
  () => ({
12
+ ...jest.requireActual(
13
+ "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext"
14
+ ),
12
15
  useScreenContext: jest.fn().mockReturnValue({ screen: {}, entry: {} }),
13
16
  })
14
17
  );
15
18
 
16
- const useBatchLoading = require("../useBatchLoading").useBatchLoading;
17
- const allFeedsIsReady = require("../useBatchLoading").allFeedsIsReady;
18
-
19
- const mockStore = reduxMockStore.default([thunk]);
20
-
21
- const wrapper: React.FC<any> = ({ children, store }) => (
22
- <ReactRedux.Provider store={store}>{children}</ReactRedux.Provider>
23
- );
19
+ const wrapper = WrappedWithProviders;
24
20
 
25
21
  describe("useBatchLoading", () => {
26
- const useDispatchSpy = jest.spyOn(ReactRedux, "useDispatch");
22
+ const data = [
23
+ { data: { source: "url1" }, component_type: "any" },
24
+ { data: { source: "url2" }, component_type: "any" },
25
+ { data: { source: "url3" }, component_type: "any" },
26
+ { data: { source: "url4" }, component_type: "any" },
27
+ { data: { source: "url5" }, component_type: "any" },
28
+ { data: { source: "url6" }, component_type: "any" },
29
+ // ... more items
30
+ ];
27
31
 
28
32
  beforeAll(() => {
29
33
  jest.useFakeTimers();
@@ -33,8 +37,8 @@ describe("useBatchLoading", () => {
33
37
  jest.clearAllMocks();
34
38
  });
35
39
 
36
- it("loadPipesData start loading not started requests", () => {
37
- const store = mockStore({
40
+ it("loadPipesData start loading not started requests", async () => {
41
+ const store = {
38
42
  zappPipes: {
39
43
  url1: {
40
44
  loading: true,
@@ -53,31 +57,21 @@ describe("useBatchLoading", () => {
53
57
  },
54
58
  },
55
59
  test: "true",
56
- });
57
-
58
- useDispatchSpy.mockReturnValue(store.dispatch);
60
+ };
59
61
 
60
62
  const initialBatchSize = 3;
61
63
  const riverId = "123";
62
64
 
63
- const data = [
64
- { data: { source: "url1" } },
65
- { data: { source: "url2" } },
66
- { data: { source: "url3" } },
67
- { data: { source: "url4" } },
68
- { data: { source: "url5" } },
69
- { data: { source: "url6" } },
70
- // ... more items
71
- ];
72
-
73
65
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
74
66
  wrapper,
75
67
  initialProps: { store },
76
68
  });
77
69
 
78
- const actions = store.getActions();
70
+ const actions = (appStore.getStore() as any).getActions();
79
71
 
80
- expect(actions).toHaveLength(2);
72
+ await waitFor(() => {
73
+ expect(actions).toHaveLength(2);
74
+ });
81
75
 
82
76
  expect(actions[0]).toMatchObject({
83
77
  type: "ZAPP_PIPES_REQUEST_START",
@@ -91,7 +85,7 @@ describe("useBatchLoading", () => {
91
85
  });
92
86
 
93
87
  it("loadPipesData start loading new feed when 1 feed is done loading and 1 is in loading state", () => {
94
- const store = mockStore({
88
+ const store = {
95
89
  zappPipes: {
96
90
  url1: {
97
91
  loading: false,
@@ -110,31 +104,17 @@ describe("useBatchLoading", () => {
110
104
  },
111
105
  },
112
106
  test: "true",
113
- });
114
-
115
- useDispatchSpy.mockReturnValue(store.dispatch);
107
+ };
116
108
 
117
109
  const initialBatchSize = 3;
118
110
  const riverId = "123";
119
111
 
120
- const data = [
121
- { data: { source: "url1" } },
122
- { data: { source: "url2" } },
123
- { data: { source: "url3" } },
124
- { data: { source: "url4" } },
125
- { data: { source: "url5" } },
126
- { data: { source: "url6" } },
127
- // ... more items
128
- ];
129
-
130
- expect(useDispatchSpy).toBeCalledTimes(0);
131
-
132
112
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
133
113
  wrapper,
134
114
  initialProps: { store },
135
115
  });
136
116
 
137
- const actions = store.getActions();
117
+ const actions = (appStore.getStore() as any).getActions();
138
118
 
139
119
  expect(actions).toHaveLength(1);
140
120
 
@@ -145,38 +125,26 @@ describe("useBatchLoading", () => {
145
125
  });
146
126
 
147
127
  it("loadPipesData has been called when no data cached", () => {
148
- const store = mockStore({
128
+ const store = {
149
129
  zappPipes: {},
150
130
  test: "true",
151
- });
152
-
153
- useDispatchSpy.mockReturnValue(store.dispatch);
131
+ };
154
132
 
155
133
  const initialBatchSize = 3;
156
134
  const riverId = "123";
157
135
 
158
- const data = [
159
- { data: { source: "url1" } },
160
- { data: { source: "url2" } },
161
- { data: { source: "url3" } },
162
- { data: { source: "url4" } },
163
- { data: { source: "url5" } },
164
- { data: { source: "url6" } },
165
- // ... more items
166
- ];
167
-
168
136
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
169
137
  wrapper,
170
138
  initialProps: { store },
171
139
  });
172
140
 
173
- const actions = store.getActions();
141
+ const actions = (appStore.getStore() as any).getActions();
174
142
 
175
143
  expect(actions).toHaveLength(3);
176
144
  });
177
145
 
178
146
  it("initial batch ready when all initial items loaded", () => {
179
- const store = mockStore({
147
+ const store = {
180
148
  zappPipes: {
181
149
  url1: {
182
150
  loading: false,
@@ -194,19 +162,11 @@ describe("useBatchLoading", () => {
194
162
  data: {},
195
163
  },
196
164
  },
197
- });
198
-
199
- useDispatchSpy.mockReturnValue(store.dispatch);
165
+ };
200
166
 
201
167
  const initialBatchSize = 3;
202
168
  const riverId = "123";
203
169
 
204
- const data: Partial<ZappUIComponent>[] = [
205
- { data: { source: "url1" } },
206
- { data: { source: "url2" } },
207
- { data: { source: "url3" } },
208
- ];
209
-
210
170
  const { result } = renderHook(
211
171
  () => useBatchLoading(data, { initialBatchSize, riverId }),
212
172
  { wrapper, initialProps: { store } }
@@ -216,12 +176,10 @@ describe("useBatchLoading", () => {
216
176
  });
217
177
 
218
178
  it("gallery-qb: loadPipesData should be called only once for first component in the gallery", () => {
219
- const store = mockStore({
179
+ const store = {
220
180
  zappPipes: {},
221
181
  test: "true",
222
- });
223
-
224
- useDispatchSpy.mockReturnValue(store.dispatch);
182
+ };
225
183
 
226
184
  const initialBatchSize = 3;
227
185
  const riverId = "123";
@@ -231,11 +189,11 @@ describe("useBatchLoading", () => {
231
189
  component_type: "gallery-qb",
232
190
  ui_components: [{ data: { source: "url1" } }],
233
191
  },
234
- { data: { source: "url2" } },
235
- { data: { source: "url3" } },
236
- { data: { source: "url4" } },
237
- { data: { source: "url5" } },
238
- { data: { source: "url6" } },
192
+ { data: { source: "url2" }, component_type: "any" },
193
+ { data: { source: "url3" }, component_type: "any" },
194
+ { data: { source: "url4" }, component_type: "any" },
195
+ { data: { source: "url5" }, component_type: "any" },
196
+ { data: { source: "url6" }, component_type: "any" },
239
197
  // ... more items
240
198
  ];
241
199
 
@@ -244,13 +202,13 @@ describe("useBatchLoading", () => {
244
202
  initialProps: { store },
245
203
  });
246
204
 
247
- const actions = store.getActions();
205
+ const actions = (appStore.getStore() as any).getActions();
248
206
 
249
207
  expect(actions).toHaveLength(1);
250
208
  });
251
209
 
252
210
  it("gallery-qb: initial batch ready when all initial items loaded", () => {
253
- const store = mockStore({
211
+ const store = {
254
212
  zappPipes: {
255
213
  url1: {
256
214
  loading: false,
@@ -258,20 +216,19 @@ describe("useBatchLoading", () => {
258
216
  data: {},
259
217
  },
260
218
  },
261
- });
262
-
263
- useDispatchSpy.mockReturnValue(store.dispatch);
219
+ };
264
220
 
265
221
  const initialBatchSize = 3;
266
222
  const riverId = "123";
267
223
 
268
- const data: Partial<ZappUIComponent>[] = [
224
+ const data = [
269
225
  {
270
226
  component_type: "gallery-qb",
271
- ui_components: [{ data: { source: "url1" } }],
227
+ data: {},
228
+ ui_components: [{ data: { source: "url1" } }] as any,
272
229
  },
273
- { data: { source: "url2" } },
274
- { data: { source: "url3" } },
230
+ { data: { source: "url2" }, component_type: "any" },
231
+ { data: { source: "url3" }, component_type: "any" },
275
232
  ];
276
233
 
277
234
  const { result } = renderHook(
@@ -2,15 +2,12 @@ import { renderHook } from "@testing-library/react-hooks";
2
2
  import * as R from "ramda";
3
3
  import * as zappPipesModule from "@applicaster/zapp-react-native-redux/ZappPipes";
4
4
  import * as reactReduxModules from "react-redux";
5
- import { Provider } from "react-redux";
6
5
  import * as React from "react";
7
- import configureStore from "redux-mock-store";
8
- import thunk from "redux-thunk";
9
6
  import * as useRouteHook from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
10
7
  import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
11
8
  import { useFeedLoader } from "../useFeedLoader";
12
-
13
- const mockStore = configureStore([thunk]);
9
+ import { WrappedWithProviders } from "../../../testUtils";
10
+ import { ScreenStateResolver } from "../../../appUtils/contextKeysManager/contextResolver";
14
11
 
15
12
  jest.useFakeTimers({ legacyFakeTimers: true });
16
13
 
@@ -55,13 +52,15 @@ const mockZappPipesData = {
55
52
 
56
53
  describe("useFeedLoader", () => {
57
54
  describe("with cached feed url", () => {
58
- const store = mockStore({
55
+ const store = {
59
56
  plugins: [],
60
57
  zappPipes: { "test://testfakeurl": mockZappPipesData },
61
- });
58
+ };
62
59
 
63
- const wrapper: React.FC<any> = ({ children }) => (
64
- <Provider store={store}>{children}</Provider>
60
+ const wrapper: React.FC<any> = ({ children, ...props }) => (
61
+ <WrappedWithProviders store={props.store || store}>
62
+ {children}
63
+ </WrappedWithProviders>
65
64
  );
66
65
 
67
66
  it("returns cached feed", () => {
@@ -110,8 +109,10 @@ describe("useFeedLoader", () => {
110
109
  describe("without cached feeds", () => {
111
110
  const feedUrl = "test://testfakeurl2";
112
111
 
113
- const wrapper: React.FC<any> = ({ children, store }) => (
114
- <Provider store={store}>{children}</Provider>
112
+ const wrapper: React.FC<any> = ({ children, ...props }) => (
113
+ <WrappedWithProviders store={props.store}>
114
+ {children}
115
+ </WrappedWithProviders>
115
116
  );
116
117
 
117
118
  it("It loads data for new url and returns it", () => {
@@ -123,10 +124,10 @@ describe("useFeedLoader", () => {
123
124
  .spyOn(zappPipesModule, "loadPipesData")
124
125
  .mockImplementation(jest.fn());
125
126
 
126
- const initialStore = mockStore({
127
+ const initialStore = {
127
128
  plugins: [],
128
129
  zappPipes: { "test://testfakeurl": "foobar" },
129
- });
130
+ };
130
131
 
131
132
  const { result, rerender } = renderHook(
132
133
  () => useFeedLoader({ feedUrl: "test://testfakeurl2" }),
@@ -135,15 +136,19 @@ describe("useFeedLoader", () => {
135
136
 
136
137
  expect(result.current.data).toBeNull();
137
138
 
138
- expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
139
+ expect(loadPipesDataSpy).toHaveBeenCalledWith(feedUrl, {
139
140
  clearCache: true,
140
141
  riverId: undefined,
142
+ callback: expect.any(Function),
143
+ resolvers: {
144
+ screen: expect.any(ScreenStateResolver),
145
+ },
141
146
  });
142
147
 
143
- const store2 = mockStore({
148
+ const store2 = {
144
149
  plugins: [],
145
150
  zappPipes: { "test://testfakeurl2": mockZappPipesData },
146
- });
151
+ };
147
152
 
148
153
  rerender({ store: store2 });
149
154
 
@@ -164,10 +169,10 @@ describe("useFeedLoader", () => {
164
169
  .spyOn(reactReduxModules, "useDispatch")
165
170
  .mockImplementation(() => jest.fn());
166
171
 
167
- const initialStore = mockStore({
172
+ const initialStore = {
168
173
  plugins: [],
169
174
  zappPipes: { "test://testfakeurl": "foobar" },
170
- });
175
+ };
171
176
 
172
177
  const { result, rerender } = renderHook(
173
178
  () => useFeedLoader({ feedUrl: "test://testfakeurl2" }),
@@ -176,15 +181,22 @@ describe("useFeedLoader", () => {
176
181
 
177
182
  expect(result.current.data).toBeNull();
178
183
 
179
- expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
184
+ expect(loadPipesDataSpy.mock.calls[0][0]).toBe(feedUrl);
185
+
186
+ expect(loadPipesDataSpy.mock.calls[0][1]).toMatchObject({
180
187
  clearCache: true,
181
188
  riverId: undefined,
189
+ resolvers: {
190
+ screen: {
191
+ screenStateStore: expect.any(Function),
192
+ },
193
+ },
182
194
  });
183
195
 
184
- const store2 = mockStore({
196
+ const store2 = {
185
197
  plugins: [],
186
198
  zappPipes: { "test://testfakeurl2": mockZappPipesData },
187
- });
199
+ };
188
200
 
189
201
  rerender({ store: store2 });
190
202
 
@@ -197,8 +209,10 @@ describe("useFeedLoader", () => {
197
209
  const feedUrl = "test://testfakeurl";
198
210
  const feedUrlWithNext = "test://withnexttestfakeurl";
199
211
 
200
- const wrapper: React.FC<any> = ({ children, store }) => (
201
- <Provider store={store}>{children}</Provider>
212
+ const wrapper: React.FC<any> = ({ children, ...props }) => (
213
+ <WrappedWithProviders store={props.store || {}}>
214
+ {children}
215
+ </WrappedWithProviders>
202
216
  );
203
217
 
204
218
  describe("reloadData", () => {
@@ -211,10 +225,10 @@ describe("useFeedLoader", () => {
211
225
  .spyOn(reactReduxModules, "useDispatch")
212
226
  .mockImplementation(() => jest.fn());
213
227
 
214
- const initialStore = mockStore({
228
+ const initialStore = {
215
229
  plugins: [],
216
230
  zappPipes: { [feedUrl]: "foobar" },
217
- });
231
+ };
218
232
 
219
233
  const { result } = renderHook(() => useFeedLoader({ feedUrl }), {
220
234
  wrapper,
@@ -223,11 +237,24 @@ describe("useFeedLoader", () => {
223
237
 
224
238
  const { reloadData } = result.current;
225
239
 
226
- reloadData();
240
+ reloadData?.();
241
+
242
+ expect(loadPipesDataSpy).toHaveBeenCalled();
243
+
244
+ expect(
245
+ loadPipesDataSpy.mock.calls[loadPipesDataSpy.mock.calls.length - 1][0]
246
+ ).toBe(feedUrl);
227
247
 
228
- expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
248
+ expect(
249
+ loadPipesDataSpy.mock.calls[loadPipesDataSpy.mock.calls.length - 1][1]
250
+ ).toMatchObject({
229
251
  clearCache: true,
230
252
  silentRefresh: true,
253
+ resolvers: {
254
+ screen: {
255
+ screenStateStore: expect.any(Function),
256
+ },
257
+ },
231
258
  });
232
259
 
233
260
  loadPipesDataSpy.mockRestore();
@@ -247,10 +274,10 @@ describe("useFeedLoader", () => {
247
274
  .spyOn(reactReduxModules, "useDispatch")
248
275
  .mockImplementation(() => jest.fn());
249
276
 
250
- const initialStore = mockStore({
277
+ const initialStore = {
251
278
  plugins: [],
252
279
  zappPipes: { [feedUrlWithNext]: { data: { next: nextUrl } } },
253
- });
280
+ };
254
281
 
255
282
  const { result } = renderHook(
256
283
  () => useFeedLoader({ feedUrl: feedUrlWithNext }),
@@ -262,11 +289,24 @@ describe("useFeedLoader", () => {
262
289
 
263
290
  const { loadNext } = result.current;
264
291
 
265
- loadNext();
292
+ loadNext?.();
293
+
294
+ expect(loadPipesDataSpy).toHaveBeenCalled();
295
+
296
+ expect(
297
+ loadPipesDataSpy.mock.calls[loadPipesDataSpy.mock.calls.length - 1][0]
298
+ ).toBe(nextUrl);
266
299
 
267
- expect(loadPipesDataSpy).toBeCalledWith(nextUrl, {
300
+ expect(
301
+ loadPipesDataSpy.mock.calls[loadPipesDataSpy.mock.calls.length - 1][1]
302
+ ).toMatchObject({
268
303
  parentFeed: feedUrlWithNext,
269
304
  silentRefresh: true,
305
+ resolvers: {
306
+ screen: {
307
+ screenStateStore: expect.any(Function),
308
+ },
309
+ },
270
310
  });
271
311
 
272
312
  loadPipesDataSpy.mockRestore();
@@ -11,3 +11,5 @@ export { useBuildPipesUrl } from "./useBuildPipesUrl";
11
11
  export { usePipesCacheReset } from "./usePipesCacheReset";
12
12
 
13
13
  export { useBatchLoading } from "./useBatchLoading";
14
+
15
+ export { useLoadPipesDataDispatch } from "./useLoadPipesDataDispatch";
@@ -1,16 +1,15 @@
1
1
  import { complement, compose, isNil, map, min, prop, take, uniq } from "ramda";
2
- import { useDispatch } from "react-redux";
3
2
  import * as React from "react";
4
- import { useZappPipesFeeds } from "@applicaster/zapp-react-native-redux/hooks";
5
- import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
3
+ import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux";
6
4
  import { isNilOrEmpty } from "../../reactUtils/helpers";
7
5
  import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
8
6
  import {
9
7
  getInflatedDataSourceUrl,
10
8
  getSearchContext,
9
+ useLoadPipesDataDispatch,
11
10
  } from "@applicaster/zapp-react-native-utils/reactHooks";
12
11
  import { isGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
13
- import { useScreenContext } from "../screen/useScreenContext";
12
+ import { useScreenContext } from "../screen";
14
13
 
15
14
  type Options = {
16
15
  initialBatchSize?: number;
@@ -63,7 +62,6 @@ export const useBatchLoading = (
63
62
  componentsToRender: { data?: ZappDataSource; component_type: string }[],
64
63
  options: Options
65
64
  ) => {
66
- const dispatch = useDispatch();
67
65
  const { screen: screenContext, entry: entryContext } = useScreenContext();
68
66
  const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
69
67
  const [hasEverBeenReady, setHasEverBeenReady] = React.useState(false);
@@ -118,7 +116,9 @@ export const useBatchLoading = (
118
116
  []
119
117
  );
120
118
 
121
- const feeds = useZappPipesFeeds(feedUrls);
119
+ const feeds = useZappPipesFeed(feedUrls);
120
+
121
+ const loadPipesDataDispatcher = useLoadPipesDataDispatch();
122
122
 
123
123
  // dispatch loadPipesData for each feed that is not loaded
124
124
  const runBatchLoading = React.useCallback(() => {
@@ -138,17 +138,24 @@ export const useBatchLoading = (
138
138
 
139
139
  if (mappedFeedUrl) {
140
140
  // 4. load data
141
- return dispatch(
142
- loadPipesData(mappedFeedUrl, { riverId: options.riverId })
141
+ return loadPipesDataDispatcher(
142
+ mappedFeedUrl,
143
+ {
144
+ riverId: options.riverId,
145
+ },
146
+ {
147
+ withResolvers: true,
148
+ withScreenRouteMapping: true,
149
+ }
143
150
  );
144
151
  }
145
152
  }
146
153
  });
147
- }, [feedUrls]);
154
+ }, [feedUrls, feeds, loadPipesDataDispatcher]);
148
155
 
149
156
  React.useEffect(() => {
150
157
  runBatchLoading();
151
- }, []);
158
+ }, [runBatchLoading]); // Adding runBatchLoading as a dependency to ensure that it reloads feeds when clearPipesData is called
152
159
 
153
160
  React.useEffect(() => {
154
161
  // check if all feeds are ready and set hasEverBeenReady to true
@@ -1,13 +1,11 @@
1
1
  import React, { useEffect } from "react";
2
- import { useDispatch } from "react-redux";
3
2
 
4
- import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
5
- import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux/hooks";
3
+ import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux";
6
4
 
7
5
  import { reactHooksLogger } from "../logger";
8
6
  import { shouldDispatchData, useIsInitialRender } from "../utils";
9
7
  import { useInflatedUrl } from "./useInflatedUrl";
10
- import { useRoute } from "../navigation";
8
+ import { useLoadPipesDataDispatch } from "./useLoadPipesDataDispatch";
11
9
 
12
10
  const logger = reactHooksLogger.addSubsystem("useFeedLoader");
13
11
 
@@ -49,29 +47,26 @@ export const useFeedLoader = ({
49
47
  }, []);
50
48
 
51
49
  const isInitialRender = useIsInitialRender();
52
- const dispatch = useDispatch();
53
- const { screenData } = useRoute();
54
50
 
55
51
  const callableFeedUrl = useInflatedUrl({ feedUrl, mapping });
56
52
 
57
53
  const currentFeed = useZappPipesFeed(callableFeedUrl);
58
54
 
59
- const riverId =
60
- (screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
61
- screenData?.id;
55
+ const loadPipesDataDispatcher = useLoadPipesDataDispatch();
62
56
 
63
57
  const reloadData = React.useCallback<ReloadDataFunction>(
64
58
  (silentRefresh = true, callback) => {
65
- if (callableFeedUrl) {
66
- dispatch(
67
- loadPipesData(callableFeedUrl, {
68
- clearCache: true,
69
- silentRefresh,
70
- callback,
71
- riverId,
72
- })
73
- );
74
- }
59
+ loadPipesDataDispatcher(
60
+ callableFeedUrl,
61
+ {
62
+ clearCache: true,
63
+ silentRefresh,
64
+ callback,
65
+ },
66
+ {
67
+ withResolvers: true,
68
+ }
69
+ );
75
70
  },
76
71
  [callableFeedUrl]
77
72
  );
@@ -80,15 +75,16 @@ export const useFeedLoader = ({
80
75
  if (callableFeedUrl) {
81
76
  const nextFeed = currentFeed?.data?.next;
82
77
 
83
- if (nextFeed) {
84
- dispatch(
85
- loadPipesData(nextFeed, {
86
- silentRefresh: true,
87
- parentFeed: callableFeedUrl,
88
- riverId,
89
- })
90
- );
91
- }
78
+ loadPipesDataDispatcher(
79
+ nextFeed,
80
+ {
81
+ silentRefresh: true,
82
+ parentFeed: callableFeedUrl,
83
+ },
84
+ {
85
+ withResolvers: true,
86
+ }
87
+ );
92
88
  }
93
89
  }, [callableFeedUrl, currentFeed?.data?.next]);
94
90
 
@@ -97,12 +93,16 @@ export const useFeedLoader = ({
97
93
  shouldDispatchData(callableFeedUrl, currentFeed, pipesOptions.clearCache)
98
94
  ) {
99
95
  if (callableFeedUrl && !pipesOptions.skipLoading) {
100
- dispatch(
101
- loadPipesData(callableFeedUrl, {
96
+ loadPipesDataDispatcher(
97
+ callableFeedUrl,
98
+ {
102
99
  ...pipesOptions,
103
100
  clearCache: true,
104
- riverId,
105
- })
101
+ },
102
+ {
103
+ withResolvers: true,
104
+ withScreenRouteMapping: true,
105
+ }
106
106
  );
107
107
  } else if (!callableFeedUrl) {
108
108
  logger.info({
@@ -131,9 +131,11 @@ export const useFeedLoader = ({
131
131
  // Reload feed when feedUrl changes, unless skipLoading is true
132
132
  useEffect(() => {
133
133
  if (!isInitialRender && callableFeedUrl && !pipesOptions.skipLoading) {
134
- dispatch(loadPipesData(callableFeedUrl, { ...pipesOptions, riverId }));
134
+ loadPipesDataDispatcher(callableFeedUrl, pipesOptions, {
135
+ withResolvers: true,
136
+ });
135
137
  }
136
- }, [callableFeedUrl]);
138
+ }, [callableFeedUrl, isInitialRender, pipesOptions.skipLoading]);
137
139
 
138
140
  return React.useMemo(() => {
139
141
  if (!callableFeedUrl || !feedUrl) {