@applicaster/quick-brick-core 15.1.5-alpha.2962273477 → 15.1.5-alpha.4641051656

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.
@@ -20,10 +20,6 @@ const warnUndefinedContext = (context) =>
20
20
  data: { context },
21
21
  });
22
22
 
23
- type Subscription = {
24
- [x: string]: () => any;
25
- };
26
-
27
23
  const getModuleContext = R.path(["module", "context"]);
28
24
 
29
25
  const getContexts = R.compose(
@@ -63,24 +59,40 @@ const useSubscribeToActionProviders = () => {
63
59
  export const useRiverInitialState = () => {
64
60
  const key = "getRiverInitialState";
65
61
  const actionProvidersSubscriptions = useSubscribeToActionProviders();
62
+ // Capture river-init promises once. Re-calling getRiverInitialState() on every
63
+ // context re-render causes thrash and can drop already-completed observables.
64
+ // Plugins should return Promise.resolve() when already initialized (not undefined).
65
+ const capturedPromisesRef = React.useRef<Promise<unknown>[] | null>(null);
66
+
67
+ if (
68
+ capturedPromisesRef.current === null &&
69
+ actionProvidersSubscriptions.length > 0
70
+ ) {
71
+ const providersWithMethod = actionProvidersSubscriptions.filter(
72
+ (item) => item?.[key]
73
+ );
74
+
75
+ const promises = providersWithMethod
76
+ .map((item) => item[key]())
77
+ .filter(Boolean) as Promise<unknown>[];
78
+
79
+ // Lock when every river-init provider returned a promise, or none expose it.
80
+ // Retry while a provider still returns undefined (getInitialState not started).
81
+ if (
82
+ providersWithMethod.length === 0 ||
83
+ promises.length === providersWithMethod.length
84
+ ) {
85
+ capturedPromisesRef.current = promises;
86
+ }
87
+ }
66
88
 
67
- const subscriptions = React.useMemo(() => {
68
- if (!actionProvidersSubscriptions.length) return undefined;
69
-
70
- return actionProvidersSubscriptions.reduce((acc, item) => {
71
- const riverInitialStatePromise = item[key]?.();
72
-
73
- if (riverInitialStatePromise) {
74
- acc.push(riverInitialStatePromise);
75
- }
76
-
77
- return acc;
78
- }, [] as Subscription[]);
79
- }, [actionProvidersSubscriptions]);
89
+ if (!actionProvidersSubscriptions.length) {
90
+ return undefined;
91
+ }
80
92
 
81
- if (!actionProvidersSubscriptions.length) return undefined;
82
-
83
- return subscriptions;
93
+ return capturedPromisesRef.current === null
94
+ ? undefined
95
+ : capturedPromisesRef.current;
84
96
  };
85
97
 
86
98
  const getActionInitialStateSetters = (key) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "15.1.5-alpha.2962273477",
3
+ "version": "15.1.5-alpha.4641051656",
4
4
  "description": "Core package for Applicaster's Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,13 +28,13 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "15.1.5-alpha.2962273477",
32
- "@applicaster/quick-brick-core-plugins": "15.1.5-alpha.2962273477",
33
- "@applicaster/zapp-pipes-v2-client": "15.1.5-alpha.2962273477",
34
- "@applicaster/zapp-react-native-bridge": "15.1.5-alpha.2962273477",
35
- "@applicaster/zapp-react-native-redux": "15.1.5-alpha.2962273477",
36
- "@applicaster/zapp-react-native-ui-components": "15.1.5-alpha.2962273477",
37
- "@applicaster/zapp-react-native-utils": "15.1.5-alpha.2962273477",
31
+ "@applicaster/applicaster-types": "15.1.5-alpha.4641051656",
32
+ "@applicaster/quick-brick-core-plugins": "15.1.5-alpha.4641051656",
33
+ "@applicaster/zapp-pipes-v2-client": "15.1.5-alpha.4641051656",
34
+ "@applicaster/zapp-react-native-bridge": "15.1.5-alpha.4641051656",
35
+ "@applicaster/zapp-react-native-redux": "15.1.5-alpha.4641051656",
36
+ "@applicaster/zapp-react-native-ui-components": "15.1.5-alpha.4641051656",
37
+ "@applicaster/zapp-react-native-utils": "15.1.5-alpha.4641051656",
38
38
  "atob": "^2.1.2",
39
39
  "axios": "^0.28.0",
40
40
  "btoa": "^1.2.1",