@applicaster/zapp-react-native-utils 15.0.0-rc.136 → 15.0.0-rc.137

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "15.0.0-rc.136",
3
+ "version": "15.0.0-rc.137",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "15.0.0-rc.136",
30
+ "@applicaster/applicaster-types": "15.0.0-rc.137",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -130,6 +130,51 @@ describe("RefreshCoordinator", () => {
130
130
  sub2.unsubscribe();
131
131
  });
132
132
 
133
+ // ----------------------------------------
134
+ // triggerRefresh
135
+ // ----------------------------------------
136
+ it("triggerRefresh emits refresh events for each component", () => {
137
+ const component1 = { id: "c1" } as ZappUIComponent;
138
+ const component2 = { id: "c2" } as ZappUIComponent;
139
+ const listener = jest.fn();
140
+
141
+ // Subscribe to all events
142
+ (refreshCoordinator as any).refresh$.subscribe(listener);
143
+
144
+ refreshCoordinator.triggerRefresh([component1, component2], screenId);
145
+
146
+ expect(listener).toHaveBeenCalledTimes(2);
147
+
148
+ expect(listener).toHaveBeenCalledWith({
149
+ component: component1,
150
+ screenId,
151
+ });
152
+
153
+ expect(listener).toHaveBeenCalledWith({
154
+ component: component2,
155
+ screenId,
156
+ });
157
+ });
158
+
159
+ it("triggerRefresh with empty components does nothing", () => {
160
+ const listener = jest.fn();
161
+
162
+ (refreshCoordinator as any).refresh$.subscribe(listener);
163
+
164
+ refreshCoordinator.triggerRefresh([], screenId);
165
+
166
+ expect(listener).not.toHaveBeenCalled();
167
+ });
168
+
169
+ it("triggerRefresh events are picked up by subscribeTo", () => {
170
+ const listener = jest.fn();
171
+
172
+ refreshCoordinator.subscribeTo(component, screenId, listener);
173
+ refreshCoordinator.triggerRefresh([component], screenId);
174
+
175
+ expect(listener).toHaveBeenCalledTimes(1);
176
+ });
177
+
133
178
  // ----------------------------------------
134
179
  // clear
135
180
  // ----------------------------------------
@@ -16,12 +16,26 @@ type ComponentToRefresh = {
16
16
  /**
17
17
  * Public contract for refresh coordination.
18
18
  *
19
- * register() starts refresh timer for a component with screen context
20
- * subscribeTo() listen to refresh events for a specific component and screen
21
- * subscribeToAny() → listen to all refresh events with throttling
19
+ * The coordinator serves as an event bus for component refresh events.
20
+ * It supports two types of producers and any number of consumers:
21
+ *
22
+ * Producers (push events into refresh$):
23
+ * register() → starts a periodic timer that emits refresh events
24
+ * triggerRefresh() → imperatively emits refresh events (e.g. pull-to-refresh)
25
+ *
26
+ * Consumers (react to refresh events):
27
+ * subscribeTo() → listen to refresh events for a specific component/screen
28
+ * subscribeToAny() → listen to all refresh events with throttling
29
+ *
30
+ * Note: subscribeTo() works independently of register(). A component can
31
+ * subscribe to refresh events without having auto-refresh enabled.
32
+ * This is how pull-to-refresh works — triggerRefresh() pushes events that
33
+ * are picked up by existing subscribeTo() listeners in UrlFeedResolver,
34
+ * even for components that don't have periodic auto-refresh timers.
22
35
  */
23
36
  interface IRefreshCoordinator {
24
37
  register(component: ZappUIComponent, screenId: string): () => void;
38
+ triggerRefresh(components: ZappUIComponent[], screenId: string): void;
25
39
  subscribeTo(
26
40
  component: ZappUIComponent,
27
41
  screenId: string,
@@ -37,8 +51,10 @@ interface IRefreshCoordinator {
37
51
  *
38
52
  * Design goals:
39
53
  * - One shared coordinator across the app
40
- * - Multiple components can register refresh timers with screen context
41
- * - Multiple listeners can subscribe to refresh events
54
+ * - Central refresh$ event bus for all refresh events
55
+ * - Multiple producers: periodic timers (register) and imperative triggers (triggerRefresh)
56
+ * - Multiple consumers: per-component (subscribeTo) and global (subscribeToAny)
57
+ * - Producers and consumers are independent — subscribeTo works without register
42
58
  * - Safe cleanup of timers and subscriptions
43
59
  */
44
60
  class RefreshCoordinator implements IRefreshCoordinator {
@@ -114,6 +130,19 @@ class RefreshCoordinator implements IRefreshCoordinator {
114
130
  return (): void => this.unregister(componentId, screenId);
115
131
  }
116
132
 
133
+ /**
134
+ * Imperatively triggers refresh for the given components on a screen.
135
+ *
136
+ * Pushes each component into the central refresh$ stream so that
137
+ * existing subscribers (e.g. UrlFeedResolver's reloadData) react
138
+ * to the event. Used by pull-to-refresh and programmatic refresh.
139
+ */
140
+ public triggerRefresh(components: ZappUIComponent[], screenId: string): void {
141
+ components.forEach((component) => {
142
+ this.refresh$.next({ component, screenId });
143
+ });
144
+ }
145
+
117
146
  /**
118
147
  * Stops and removes timer for a specific component.
119
148
  * Cleans up the RxJS subscription for that component's interval stream.