cx 26.7.3 → 26.7.5
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/build/ui/Cx.d.ts +10 -4
- package/build/ui/Cx.d.ts.map +1 -1
- package/build/ui/Cx.js +121 -42
- package/build/ui/batchUpdates.d.ts +2 -2
- package/build/ui/batchUpdates.d.ts.map +1 -1
- package/build/ui/batchUpdates.js +11 -1
- package/dist/manifest.js +820 -814
- package/dist/ui.js +137 -55
- package/package.json +1 -1
- package/src/ui/Cx.spec.tsx +85 -0
- package/src/ui/Cx.tsx +126 -43
- package/src/ui/DataProxy.ts +55 -55
- package/src/ui/Rescope.ts +50 -50
- package/src/ui/Restate.tsx +217 -217
- package/src/ui/batchUpdates.ts +12 -2
- package/src/ui/exprHelpers.ts +96 -96
- package/src/widgets/Sandbox.ts +104 -104
- package/src/widgets/form/ColorField.scss +112 -112
- package/src/widgets/form/DateTimeField.scss +111 -111
- package/src/widgets/form/LookupField.maps.scss +26 -26
- package/src/widgets/form/MonthField.scss +113 -113
- package/src/widgets/form/Select.scss +104 -104
- package/src/widgets/form/TextField.scss +66 -66
- package/src/widgets/nav/MenuItem.tsx +525 -525
package/build/ui/Cx.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { Instance } from "./Instance";
|
|
|
4
4
|
import { ResolvedCultureInfo } from "./Culture";
|
|
5
5
|
import { View } from "../data/View";
|
|
6
6
|
import { Config } from "./Prop";
|
|
7
|
+
export declare function enableSyncUpdateCoalescing(limit?: number): void;
|
|
8
|
+
export declare function disableSyncUpdateCoalescing(): void;
|
|
7
9
|
export interface CxProps {
|
|
8
10
|
widget?: Config;
|
|
9
11
|
items?: Config;
|
|
@@ -25,6 +27,7 @@ export interface CxProps {
|
|
|
25
27
|
export interface CxState {
|
|
26
28
|
deferToken: number;
|
|
27
29
|
data?: any;
|
|
30
|
+
error?: boolean;
|
|
28
31
|
}
|
|
29
32
|
export declare class Cx extends VDOM.Component<CxProps, CxState> {
|
|
30
33
|
widget: Widget;
|
|
@@ -38,12 +41,13 @@ export declare class Cx extends VDOM.Component<CxProps, CxState> {
|
|
|
38
41
|
};
|
|
39
42
|
renderCount: number;
|
|
40
43
|
unsubscribe?: () => void;
|
|
41
|
-
componentDidCatch?: (error: Error, info: any) => void;
|
|
42
44
|
forceUpdateCallback: () => void;
|
|
43
45
|
deferCounter: number;
|
|
44
46
|
pendingUpdateTimer?: NodeJS.Timeout;
|
|
45
47
|
unsubscribeIdleRequest?: () => void;
|
|
46
|
-
|
|
48
|
+
owedNotifications: Set<number>;
|
|
49
|
+
mounted: boolean;
|
|
50
|
+
burstRoundCounted: boolean;
|
|
47
51
|
constructor(props: CxProps);
|
|
48
52
|
UNSAFE_componentWillReceiveProps(props: CxProps): void;
|
|
49
53
|
getInstance(): Instance;
|
|
@@ -51,11 +55,13 @@ export declare class Cx extends VDOM.Component<CxProps, CxState> {
|
|
|
51
55
|
componentDidMount(): void;
|
|
52
56
|
componentDidUpdate(): void;
|
|
53
57
|
update(): void;
|
|
58
|
+
issueStateUpdate(seq: number): void;
|
|
59
|
+
completeNotification(seq: number): void;
|
|
54
60
|
scheduleStateUpdate(): void;
|
|
55
|
-
onStateUpdateCompleted(): void;
|
|
56
61
|
waitForIdle(): void;
|
|
57
62
|
componentWillUnmount(): void;
|
|
58
63
|
shouldComponentUpdate(props: CxProps, state: CxState): boolean;
|
|
59
|
-
|
|
64
|
+
static getDerivedStateFromError(): Partial<CxState>;
|
|
65
|
+
componentDidCatch(error: Error, info: any): void;
|
|
60
66
|
}
|
|
61
67
|
//# sourceMappingURL=Cx.d.ts.map
|
package/build/ui/Cx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cx.d.ts","sourceRoot":"","sources":["../../src/ui/Cx.tsx"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAc,MAAM,UAAU,CAAC;AACpD,OAAO,EAA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,GAAG,IAAI;IAUvC,mBAAmB;IAanB,WAAW,IAAI,IAAI;IAgBnB,oBAAoB,IAAI,IAAI;IAU5B,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAkB9D,MAAM,CAAC,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC;IAInD,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;CAUlD"}
|
package/build/ui/Cx.js
CHANGED
|
@@ -10,6 +10,36 @@ import { shallowEquals } from "../util/shallowEquals";
|
|
|
10
10
|
import { PureContainer } from "./PureContainer";
|
|
11
11
|
import { onIdleCallback } from "../util/onIdleCallback";
|
|
12
12
|
import { getCurrentCulture, pushCulture, popCulture } from "./Culture";
|
|
13
|
+
// On by default. Once a synchronous update burst grows deep, Cx starts issuing updates from microtasks
|
|
14
|
+
// so React's global nested-update counter resets before continuing -- preventing "Maximum update depth
|
|
15
|
+
// exceeded" on large renders that write to the store while they render (e.g. a several-hundred-page
|
|
16
|
+
// report). For updates that settle in a single render -- virtually all of them -- this is equivalent to
|
|
17
|
+
// rendering synchronously; it only diverges under a deep re-entrant render burst. If you suspect it
|
|
18
|
+
// causes trouble, opt out at app startup with disableSyncUpdateCoalescing() -- and please report the
|
|
19
|
+
// issue so it can be fixed.
|
|
20
|
+
// Synchronous updates allowed within one burst before Cx switches to issuing updates from a microtask.
|
|
21
|
+
// Kept under React's ~50 nested-update limit (which is global to the root, not per component); the
|
|
22
|
+
// default trades a little initial-render time for a safety margin. Override via
|
|
23
|
+
// enableSyncUpdateCoalescing(limit) if needed.
|
|
24
|
+
const defaultSyncBurstLimit = 35;
|
|
25
|
+
let syncBurstLimit = defaultSyncBurstLimit;
|
|
26
|
+
// Microtask-issued updates allowed within one burst before Cx escalates to setTimeout. Deep enough that
|
|
27
|
+
// only a store that never converges reaches it; timeouts let the event loop turn, so the page stays
|
|
28
|
+
// responsive and batchUpdatesAndNotify fallback timers can fire instead of the tab hanging.
|
|
29
|
+
let microtaskBurstLimit = 1000;
|
|
30
|
+
export function enableSyncUpdateCoalescing(limit) {
|
|
31
|
+
syncBurstLimit = limit ?? defaultSyncBurstLimit;
|
|
32
|
+
}
|
|
33
|
+
export function disableSyncUpdateCoalescing() {
|
|
34
|
+
syncBurstLimit = Infinity;
|
|
35
|
+
}
|
|
36
|
+
// Module-global because React's nested-update limit is global to the root, not per component. The burst
|
|
37
|
+
// counter resets only when all notifications settle (see completeNotification) -- tying the burst
|
|
38
|
+
// window to unsettled work makes it immune to how React schedules the flushes. Legacy React chains
|
|
39
|
+
// re-entrant updates synchronously within one task, but React 19 may run each round from its own
|
|
40
|
+
// microtask, so no task/microtask boundary is a reliable reset point.
|
|
41
|
+
let syncBurstRounds = 0; // updates issued in the current burst
|
|
42
|
+
let outstandingNotifications = 0; // reported notifications not yet rendered, across all Cx instances
|
|
13
43
|
export class Cx extends VDOM.Component {
|
|
14
44
|
widget;
|
|
15
45
|
store;
|
|
@@ -18,13 +48,18 @@ export class Cx extends VDOM.Component {
|
|
|
18
48
|
flags;
|
|
19
49
|
renderCount;
|
|
20
50
|
unsubscribe;
|
|
21
|
-
componentDidCatch;
|
|
22
51
|
forceUpdateCallback;
|
|
23
52
|
deferCounter;
|
|
24
53
|
pendingUpdateTimer;
|
|
25
54
|
unsubscribeIdleRequest;
|
|
26
|
-
//
|
|
27
|
-
|
|
55
|
+
// store notifications reported to batchUpdatesAndNotify subscribers but not yet rendered and completed
|
|
56
|
+
owedNotifications = new Set();
|
|
57
|
+
// setState is not allowed before the component mounts; pre-mount notifications set flags.dirty instead
|
|
58
|
+
// and componentDidMount picks them up (see update())
|
|
59
|
+
mounted = false;
|
|
60
|
+
// true once this instance has contributed to syncBurstRounds for the current render round; cleared on
|
|
61
|
+
// render, so bursts are counted per round rather than per notification (see update())
|
|
62
|
+
burstRoundCounted = false;
|
|
28
63
|
constructor(props) {
|
|
29
64
|
super(props);
|
|
30
65
|
if (props.instance) {
|
|
@@ -51,14 +86,11 @@ export class Cx extends VDOM.Component {
|
|
|
51
86
|
if (props.subscribe) {
|
|
52
87
|
this.unsubscribe = this.store.subscribe(this.update.bind(this));
|
|
53
88
|
}
|
|
54
|
-
this.onStateUpdateCompleted = this.onStateUpdateCompleted.bind(this);
|
|
55
89
|
this.flags = {};
|
|
56
90
|
this.renderCount = 0;
|
|
57
|
-
if (props.onError)
|
|
58
|
-
this.componentDidCatch = this.componentDidCatchHandler.bind(this);
|
|
59
91
|
this.forceUpdateCallback = this.forceUpdate.bind(this);
|
|
60
|
-
|
|
61
|
-
this.
|
|
92
|
+
// deferredUntilIdle content stays hidden until the idle callback scheduled on mount bumps the token
|
|
93
|
+
this.deferCounter = props.deferredUntilIdle ? 1 : 0;
|
|
62
94
|
}
|
|
63
95
|
UNSAFE_componentWillReceiveProps(props) {
|
|
64
96
|
let newStore = props.instance
|
|
@@ -94,12 +126,21 @@ export class Cx extends VDOM.Component {
|
|
|
94
126
|
throw new Error("Could not resolve a widget instance in the Cx component.");
|
|
95
127
|
}
|
|
96
128
|
render() {
|
|
129
|
+
this.burstRoundCounted = false;
|
|
130
|
+
// an error was captured and is being dispatched to the onError callback (see componentDidCatch);
|
|
131
|
+
// render nothing until the callback repairs the state
|
|
132
|
+
if (this.state.error)
|
|
133
|
+
return null;
|
|
97
134
|
if (this.props.deferredUntilIdle && this.state.deferToken < this.deferCounter)
|
|
98
135
|
return null;
|
|
99
136
|
let cultureInfo = this.props.cultureInfo ?? getCurrentCulture();
|
|
100
137
|
return (_jsx(CxContext, { instance: this.getInstance(), flags: this.flags, options: this.props.options, buster: ++this.renderCount, contentFactory: this.props.contentFactory, forceUpdate: this.forceUpdateCallback, cultureInfo: cultureInfo }));
|
|
101
138
|
}
|
|
102
139
|
componentDidMount() {
|
|
140
|
+
this.mounted = true;
|
|
141
|
+
// schedule the deferredUntilIdle reveal here rather than in the constructor -- the idle callback
|
|
142
|
+
// could otherwise fire before the component mounts and issue a setState React does not allow yet
|
|
143
|
+
this.waitForIdle();
|
|
103
144
|
this.componentDidUpdate();
|
|
104
145
|
if (this.props.options && this.props.options.onPipeUpdate)
|
|
105
146
|
this.props.options.onPipeUpdate(this.update.bind(this));
|
|
@@ -112,55 +153,76 @@ export class Cx extends VDOM.Component {
|
|
|
112
153
|
update() {
|
|
113
154
|
let data = this.store.getData();
|
|
114
155
|
debug(appDataFlag, data);
|
|
115
|
-
if (this.flags.preparing)
|
|
156
|
+
if (this.flags.preparing || !this.mounted)
|
|
116
157
|
this.flags.dirty = true;
|
|
117
|
-
// Synchronous path
|
|
118
|
-
//
|
|
119
|
-
// nested deep -- e.g. a large initial render that writes to the store while it renders -- are what trip
|
|
120
|
-
// React's "Maximum update depth exceeded"; coalescing them into a single in-flight update avoids that.
|
|
121
|
-
// The pending update's completion callback re-reads the store and renders again if it changed
|
|
122
|
-
// (see onStateUpdateCompleted), so no change is dropped.
|
|
158
|
+
// Synchronous path: while batching (incl. batchUpdatesAndNotify, which page-breaking relies on) or for
|
|
159
|
+
// `immediate` instances.
|
|
123
160
|
else if (this.props.immediate || isBatchingUpdates()) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
161
|
+
// Every notification is reported to batchUpdatesAndNotify subscribers up front and completed only
|
|
162
|
+
// once the setState that renders it commits, so notify callbacks never fire before the DOM reflects
|
|
163
|
+
// the change. Each notification always gets its own setState; only its timing escalates as the
|
|
164
|
+
// burst grows: synchronous at first, then from a microtask (lets React's commit finish so its
|
|
165
|
+
// global nested-update counter resets instead of tripping "Maximum update depth exceeded"), and
|
|
166
|
+
// finally from a timeout (lets the event loop turn, so a store that never converges degrades to a
|
|
167
|
+
// responsive page instead of a frozen tab).
|
|
168
|
+
let seq = notifyBatchedUpdateStarting();
|
|
169
|
+
this.owedNotifications.add(seq);
|
|
170
|
+
outstandingNotifications++;
|
|
171
|
+
// Count render rounds rather than notifications: only the first notification an instance
|
|
172
|
+
// receives per render round bumps the shared depth (the flag clears on render). This tracks
|
|
173
|
+
// React's nested-commit count -- the thing the escalation must stay under -- so a round that
|
|
174
|
+
// writes many values doesn't burn through the budget in one go.
|
|
175
|
+
if (!this.burstRoundCounted) {
|
|
176
|
+
this.burstRoundCounted = true;
|
|
177
|
+
++syncBurstRounds;
|
|
178
|
+
if (process.env.NODE_ENV !== "production" && syncBurstRounds === microtaskBurstLimit + 1)
|
|
179
|
+
console.error("Cx: store updates are not converging after " +
|
|
180
|
+
microtaskBurstLimit +
|
|
181
|
+
" render rounds -- possible update loop. Updates are now issued from timeouts to keep the page responsive. Look for code that writes a new value to the store on every render.");
|
|
128
182
|
}
|
|
183
|
+
if (syncBurstRounds <= syncBurstLimit)
|
|
184
|
+
this.issueStateUpdate(seq);
|
|
185
|
+
else if (syncBurstRounds <= microtaskBurstLimit)
|
|
186
|
+
queueMicrotask(() => this.issueStateUpdate(seq));
|
|
187
|
+
else
|
|
188
|
+
setTimeout(() => this.issueStateUpdate(seq), 0);
|
|
129
189
|
}
|
|
130
190
|
else {
|
|
131
191
|
// standard mode: coalesce sequential store commands into a single deferred update
|
|
132
192
|
this.scheduleStateUpdate();
|
|
133
193
|
}
|
|
134
194
|
}
|
|
195
|
+
// Render the latest store data and report the notification completed once the commit is done, so
|
|
196
|
+
// batchUpdatesAndNotify resolves only when the DOM reflects the store.
|
|
197
|
+
issueStateUpdate(seq) {
|
|
198
|
+
// skip notifications no longer owed -- unmount may have already released them
|
|
199
|
+
if (!this.owedNotifications.has(seq))
|
|
200
|
+
return;
|
|
201
|
+
this.setState({ data: this.store.getData() }, () => this.completeNotification(seq));
|
|
202
|
+
}
|
|
203
|
+
completeNotification(seq) {
|
|
204
|
+
// skip notifications no longer owed -- unmount may have already released them
|
|
205
|
+
if (!this.owedNotifications.delete(seq))
|
|
206
|
+
return;
|
|
207
|
+
outstandingNotifications--;
|
|
208
|
+
notifyBatchedUpdateCompleted(seq);
|
|
209
|
+
// everything settled -- the next burst starts fresh, and so does React's nested-update counter
|
|
210
|
+
// (the commit that settled the last notification ends without scheduling further synchronous work)
|
|
211
|
+
if (outstandingNotifications === 0)
|
|
212
|
+
syncBurstRounds = 0;
|
|
213
|
+
}
|
|
135
214
|
scheduleStateUpdate() {
|
|
136
215
|
if (!this.pendingUpdateTimer) {
|
|
137
|
-
notifyBatchedUpdateStarting();
|
|
216
|
+
let seq = notifyBatchedUpdateStarting();
|
|
217
|
+
this.owedNotifications.add(seq);
|
|
218
|
+
outstandingNotifications++;
|
|
138
219
|
this.pendingUpdateTimer = setTimeout(() => {
|
|
139
220
|
delete this.pendingUpdateTimer;
|
|
140
221
|
// read fresh data at fire time so the coalesced update renders the latest store state
|
|
141
|
-
this.setState({ data: this.store.getData() },
|
|
222
|
+
this.setState({ data: this.store.getData() }, () => this.completeNotification(seq));
|
|
142
223
|
}, 0);
|
|
143
224
|
}
|
|
144
225
|
}
|
|
145
|
-
// Completion callback for the synchronous setState above. If the store changed while that update was
|
|
146
|
-
// rendering -- i.e. the render itself wrote to the store, as happens throughout a large initial render --
|
|
147
|
-
// render once more with the latest data, keeping this callback armed; otherwise the burst has settled, so
|
|
148
|
-
// clear the in-flight flag and report completion. Re-arming coalesces until the store reaches a fixpoint;
|
|
149
|
-
// a genuinely non-converging update loop is still caught by React's own max-update-depth guard.
|
|
150
|
-
onStateUpdateCompleted() {
|
|
151
|
-
let latestData = this.store.getData();
|
|
152
|
-
notifyBatchedUpdateCompleted();
|
|
153
|
-
if (this.state.data === latestData) {
|
|
154
|
-
this.stateUpdateDepth = 0;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
this.stateUpdateDepth++;
|
|
158
|
-
if (this.stateUpdateDepth < 20 && isBatchingUpdates())
|
|
159
|
-
this.setState({ data: latestData }, this.onStateUpdateCompleted);
|
|
160
|
-
else
|
|
161
|
-
this.scheduleStateUpdate();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
226
|
waitForIdle() {
|
|
165
227
|
if (!this.props.deferredUntilIdle)
|
|
166
228
|
return;
|
|
@@ -168,12 +230,16 @@ export class Cx extends VDOM.Component {
|
|
|
168
230
|
this.unsubscribeIdleRequest();
|
|
169
231
|
let token = ++this.deferCounter;
|
|
170
232
|
this.unsubscribeIdleRequest = onIdleCallback(() => {
|
|
171
|
-
this.setState({ deferToken: token }
|
|
233
|
+
this.setState({ deferToken: token });
|
|
172
234
|
}, {
|
|
173
235
|
timeout: this.props.idleTimeout || 30000,
|
|
174
236
|
});
|
|
175
237
|
}
|
|
176
238
|
componentWillUnmount() {
|
|
239
|
+
// Release notifications that will never render so a waiting batchUpdatesAndNotify can settle instead
|
|
240
|
+
// of waiting out its fallback timeout.
|
|
241
|
+
for (let seq of this.owedNotifications)
|
|
242
|
+
this.completeNotification(seq);
|
|
177
243
|
if (this.pendingUpdateTimer)
|
|
178
244
|
clearTimeout(this.pendingUpdateTimer);
|
|
179
245
|
if (this.unsubscribeIdleRequest)
|
|
@@ -195,9 +261,22 @@ export class Cx extends VDOM.Component {
|
|
|
195
261
|
props.parentInstance !== this.props.parentInstance ||
|
|
196
262
|
props.cultureInfo !== this.props.cultureInfo);
|
|
197
263
|
}
|
|
198
|
-
|
|
264
|
+
// Render null for the failed subtree while the error is dispatched to componentDidCatch below --
|
|
265
|
+
// returning a state update here is what React expects of an error boundary (rendering the broken
|
|
266
|
+
// children again would just rethrow).
|
|
267
|
+
static getDerivedStateFromError() {
|
|
268
|
+
return { error: true };
|
|
269
|
+
}
|
|
270
|
+
componentDidCatch(error, info) {
|
|
199
271
|
this.flags.preparing = false;
|
|
272
|
+
// without an onError callback this instance is not an error boundary -- rethrow so the error
|
|
273
|
+
// reaches the nearest ancestor boundary, matching the behavior before getDerivedStateFromError
|
|
274
|
+
// was introduced
|
|
275
|
+
if (!this.props.onError)
|
|
276
|
+
throw error;
|
|
200
277
|
this.props.onError(error, this.getInstance(), info);
|
|
278
|
+
// the callback had a chance to repair the state (e.g. replace the failing content) -- resume rendering
|
|
279
|
+
this.setState({ error: false });
|
|
201
280
|
}
|
|
202
281
|
}
|
|
203
282
|
class CxContext extends VDOM.Component {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function batchUpdates(callback: () => void): void;
|
|
2
2
|
export declare function isBatchingUpdates(): boolean;
|
|
3
|
-
export declare function notifyBatchedUpdateStarting():
|
|
4
|
-
export declare function notifyBatchedUpdateCompleted(): void;
|
|
3
|
+
export declare function notifyBatchedUpdateStarting(): number;
|
|
4
|
+
export declare function notifyBatchedUpdateCompleted(seq: number): void;
|
|
5
5
|
export declare function batchUpdatesAndNotify(callback: () => void, notifyCallback: (success: boolean) => void, timeout?: number): void;
|
|
6
6
|
//# sourceMappingURL=batchUpdates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchUpdates.d.ts","sourceRoot":"","sources":["../../src/ui/batchUpdates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batchUpdates.d.ts","sourceRoot":"","sources":["../../src/ui/batchUpdates.ts"],"names":[],"mappings":"AAcA,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAWvD;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAID,wBAAgB,2BAA2B,IAAI,MAAM,CAMpD;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAS9D;AAED,wBAAgB,qBAAqB,CAClC,QAAQ,EAAE,MAAM,IAAI,EACpB,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,EAC1C,OAAO,GAAE,MAAa,GACtB,IAAI,CAyBN"}
|
package/build/ui/batchUpdates.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VDOM } from "./VDOM";
|
|
2
2
|
import { SubscriberList } from "../util/SubscriberList";
|
|
3
3
|
let isBatching = 0;
|
|
4
|
+
let updateSequence = 0;
|
|
4
5
|
let promiseSubscribers = new SubscriberList();
|
|
5
6
|
export function batchUpdates(callback) {
|
|
6
7
|
if (VDOM.DOM.unstable_batchedUpdates)
|
|
@@ -19,14 +20,22 @@ export function batchUpdates(callback) {
|
|
|
19
20
|
export function isBatchingUpdates() {
|
|
20
21
|
return isBatching > 0;
|
|
21
22
|
}
|
|
23
|
+
// Returns a sequence number identifying the update; pass it to notifyBatchedUpdateCompleted once the
|
|
24
|
+
// update is rendered.
|
|
22
25
|
export function notifyBatchedUpdateStarting() {
|
|
26
|
+
let seq = ++updateSequence;
|
|
23
27
|
promiseSubscribers.execute((x) => {
|
|
24
28
|
x.pending++;
|
|
25
29
|
});
|
|
30
|
+
return seq;
|
|
26
31
|
}
|
|
27
|
-
export function notifyBatchedUpdateCompleted() {
|
|
32
|
+
export function notifyBatchedUpdateCompleted(seq) {
|
|
28
33
|
promiseSubscribers.execute((x) => {
|
|
29
34
|
let cb = x;
|
|
35
|
+
// ignore updates that started before this subscriber attached -- counting them would let the notify
|
|
36
|
+
// callback fire before the updates the subscriber is actually waiting on are rendered
|
|
37
|
+
if (seq <= cb.watermark)
|
|
38
|
+
return;
|
|
30
39
|
cb.finished++;
|
|
31
40
|
if (cb.finished >= cb.pending)
|
|
32
41
|
cb.complete(true);
|
|
@@ -39,6 +48,7 @@ export function batchUpdatesAndNotify(callback, notifyCallback, timeout = 1000)
|
|
|
39
48
|
const update = {
|
|
40
49
|
pending: 0,
|
|
41
50
|
finished: 0,
|
|
51
|
+
watermark: updateSequence,
|
|
42
52
|
complete: (success) => {
|
|
43
53
|
if (!done) {
|
|
44
54
|
done = true;
|