@applicaster/quick-brick-core 15.1.4-alpha.3111505113 → 15.1.4-alpha.5560334611

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,39 @@ 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
+ const promises = providersWithMethod
75
+ .map((item) => item[key]())
76
+ .filter(Boolean) as Promise<unknown>[];
77
+
78
+ // Lock when every river-init provider returned a promise, or none expose it.
79
+ // Retry while a provider still returns undefined (getInitialState not started).
80
+ if (
81
+ providersWithMethod.length === 0 ||
82
+ promises.length === providersWithMethod.length
83
+ ) {
84
+ capturedPromisesRef.current = promises;
85
+ }
86
+ }
66
87
 
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]);
88
+ if (!actionProvidersSubscriptions.length) {
89
+ return undefined;
90
+ }
80
91
 
81
- if (!actionProvidersSubscriptions.length) return undefined;
82
-
83
- return subscriptions;
92
+ return capturedPromisesRef.current === null
93
+ ? undefined
94
+ : capturedPromisesRef.current;
84
95
  };
85
96
 
86
97
  const getActionInitialStateSetters = (key) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "15.1.4-alpha.3111505113",
3
+ "version": "15.1.4-alpha.5560334611",
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.4-alpha.3111505113",
32
- "@applicaster/quick-brick-core-plugins": "15.1.4-alpha.3111505113",
33
- "@applicaster/zapp-pipes-v2-client": "15.1.4-alpha.3111505113",
34
- "@applicaster/zapp-react-native-bridge": "15.1.4-alpha.3111505113",
35
- "@applicaster/zapp-react-native-redux": "15.1.4-alpha.3111505113",
36
- "@applicaster/zapp-react-native-ui-components": "15.1.4-alpha.3111505113",
37
- "@applicaster/zapp-react-native-utils": "15.1.4-alpha.3111505113",
31
+ "@applicaster/applicaster-types": "15.1.4-alpha.5560334611",
32
+ "@applicaster/quick-brick-core-plugins": "15.1.4-alpha.5560334611",
33
+ "@applicaster/zapp-pipes-v2-client": "15.1.4-alpha.5560334611",
34
+ "@applicaster/zapp-react-native-bridge": "15.1.4-alpha.5560334611",
35
+ "@applicaster/zapp-react-native-redux": "15.1.4-alpha.5560334611",
36
+ "@applicaster/zapp-react-native-ui-components": "15.1.4-alpha.5560334611",
37
+ "@applicaster/zapp-react-native-utils": "15.1.4-alpha.5560334611",
38
38
  "atob": "^2.1.2",
39
39
  "axios": "^0.28.0",
40
40
  "btoa": "^1.2.1",