1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 |
|
13 |
|
14 | if (process.env.NODE_ENV !== "production") {
|
15 | (function() {
|
16 | 'use strict';
|
17 |
|
18 | Object.defineProperty(exports, '__esModule', { value: true });
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var enableSchedulerTracing = true;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | var DEFAULT_THREAD_ID = 0;
|
79 |
|
80 | var interactionIDCounter = 0;
|
81 | var threadIDCounter = 0;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | exports.__interactionsRef = null;
|
87 |
|
88 | exports.__subscriberRef = null;
|
89 |
|
90 | if (enableSchedulerTracing) {
|
91 | exports.__interactionsRef = {
|
92 | current: new Set()
|
93 | };
|
94 | exports.__subscriberRef = {
|
95 | current: null
|
96 | };
|
97 | }
|
98 |
|
99 | function unstable_clear(callback) {
|
100 | if (!enableSchedulerTracing) {
|
101 | return callback();
|
102 | }
|
103 |
|
104 | var prevInteractions = exports.__interactionsRef.current;
|
105 | exports.__interactionsRef.current = new Set();
|
106 |
|
107 | try {
|
108 | return callback();
|
109 | } finally {
|
110 | exports.__interactionsRef.current = prevInteractions;
|
111 | }
|
112 | }
|
113 | function unstable_getCurrent() {
|
114 | if (!enableSchedulerTracing) {
|
115 | return null;
|
116 | } else {
|
117 | return exports.__interactionsRef.current;
|
118 | }
|
119 | }
|
120 | function unstable_getThreadID() {
|
121 | return ++threadIDCounter;
|
122 | }
|
123 | function unstable_trace(name, timestamp, callback) {
|
124 | var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID;
|
125 |
|
126 | if (!enableSchedulerTracing) {
|
127 | return callback();
|
128 | }
|
129 |
|
130 | var interaction = {
|
131 | __count: 1,
|
132 | id: interactionIDCounter++,
|
133 | name: name,
|
134 | timestamp: timestamp
|
135 | };
|
136 | var prevInteractions = exports.__interactionsRef.current;
|
137 |
|
138 |
|
139 |
|
140 | var interactions = new Set(prevInteractions);
|
141 | interactions.add(interaction);
|
142 | exports.__interactionsRef.current = interactions;
|
143 | var subscriber = exports.__subscriberRef.current;
|
144 | var returnValue;
|
145 |
|
146 | try {
|
147 | if (subscriber !== null) {
|
148 | subscriber.onInteractionTraced(interaction);
|
149 | }
|
150 | } finally {
|
151 | try {
|
152 | if (subscriber !== null) {
|
153 | subscriber.onWorkStarted(interactions, threadID);
|
154 | }
|
155 | } finally {
|
156 | try {
|
157 | returnValue = callback();
|
158 | } finally {
|
159 | exports.__interactionsRef.current = prevInteractions;
|
160 |
|
161 | try {
|
162 | if (subscriber !== null) {
|
163 | subscriber.onWorkStopped(interactions, threadID);
|
164 | }
|
165 | } finally {
|
166 | interaction.__count--;
|
167 |
|
168 |
|
169 | if (subscriber !== null && interaction.__count === 0) {
|
170 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
171 | }
|
172 | }
|
173 | }
|
174 | }
|
175 | }
|
176 |
|
177 | return returnValue;
|
178 | }
|
179 | function unstable_wrap(callback) {
|
180 | var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
|
181 |
|
182 | if (!enableSchedulerTracing) {
|
183 | return callback;
|
184 | }
|
185 |
|
186 | var wrappedInteractions = exports.__interactionsRef.current;
|
187 | var subscriber = exports.__subscriberRef.current;
|
188 |
|
189 | if (subscriber !== null) {
|
190 | subscriber.onWorkScheduled(wrappedInteractions, threadID);
|
191 | }
|
192 |
|
193 |
|
194 |
|
195 | wrappedInteractions.forEach(function (interaction) {
|
196 | interaction.__count++;
|
197 | });
|
198 | var hasRun = false;
|
199 |
|
200 | function wrapped() {
|
201 | var prevInteractions = exports.__interactionsRef.current;
|
202 | exports.__interactionsRef.current = wrappedInteractions;
|
203 | subscriber = exports.__subscriberRef.current;
|
204 |
|
205 | try {
|
206 | var returnValue;
|
207 |
|
208 | try {
|
209 | if (subscriber !== null) {
|
210 | subscriber.onWorkStarted(wrappedInteractions, threadID);
|
211 | }
|
212 | } finally {
|
213 | try {
|
214 | returnValue = callback.apply(undefined, arguments);
|
215 | } finally {
|
216 | exports.__interactionsRef.current = prevInteractions;
|
217 |
|
218 | if (subscriber !== null) {
|
219 | subscriber.onWorkStopped(wrappedInteractions, threadID);
|
220 | }
|
221 | }
|
222 | }
|
223 |
|
224 | return returnValue;
|
225 | } finally {
|
226 | if (!hasRun) {
|
227 |
|
228 |
|
229 |
|
230 | hasRun = true;
|
231 |
|
232 |
|
233 |
|
234 | wrappedInteractions.forEach(function (interaction) {
|
235 | interaction.__count--;
|
236 |
|
237 | if (subscriber !== null && interaction.__count === 0) {
|
238 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
239 | }
|
240 | });
|
241 | }
|
242 | }
|
243 | }
|
244 |
|
245 | wrapped.cancel = function cancel() {
|
246 | subscriber = exports.__subscriberRef.current;
|
247 |
|
248 | try {
|
249 | if (subscriber !== null) {
|
250 | subscriber.onWorkCanceled(wrappedInteractions, threadID);
|
251 | }
|
252 | } finally {
|
253 |
|
254 |
|
255 |
|
256 | wrappedInteractions.forEach(function (interaction) {
|
257 | interaction.__count--;
|
258 |
|
259 | if (subscriber && interaction.__count === 0) {
|
260 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
261 | }
|
262 | });
|
263 | }
|
264 | };
|
265 |
|
266 | return wrapped;
|
267 | }
|
268 |
|
269 | var subscribers = null;
|
270 |
|
271 | if (enableSchedulerTracing) {
|
272 | subscribers = new Set();
|
273 | }
|
274 |
|
275 | function unstable_subscribe(subscriber) {
|
276 | if (enableSchedulerTracing) {
|
277 | subscribers.add(subscriber);
|
278 |
|
279 | if (subscribers.size === 1) {
|
280 | exports.__subscriberRef.current = {
|
281 | onInteractionScheduledWorkCompleted: onInteractionScheduledWorkCompleted,
|
282 | onInteractionTraced: onInteractionTraced,
|
283 | onWorkCanceled: onWorkCanceled,
|
284 | onWorkScheduled: onWorkScheduled,
|
285 | onWorkStarted: onWorkStarted,
|
286 | onWorkStopped: onWorkStopped
|
287 | };
|
288 | }
|
289 | }
|
290 | }
|
291 | function unstable_unsubscribe(subscriber) {
|
292 | if (enableSchedulerTracing) {
|
293 | subscribers.delete(subscriber);
|
294 |
|
295 | if (subscribers.size === 0) {
|
296 | exports.__subscriberRef.current = null;
|
297 | }
|
298 | }
|
299 | }
|
300 |
|
301 | function onInteractionTraced(interaction) {
|
302 | var didCatchError = false;
|
303 | var caughtError = null;
|
304 | subscribers.forEach(function (subscriber) {
|
305 | try {
|
306 | subscriber.onInteractionTraced(interaction);
|
307 | } catch (error) {
|
308 | if (!didCatchError) {
|
309 | didCatchError = true;
|
310 | caughtError = error;
|
311 | }
|
312 | }
|
313 | });
|
314 |
|
315 | if (didCatchError) {
|
316 | throw caughtError;
|
317 | }
|
318 | }
|
319 |
|
320 | function onInteractionScheduledWorkCompleted(interaction) {
|
321 | var didCatchError = false;
|
322 | var caughtError = null;
|
323 | subscribers.forEach(function (subscriber) {
|
324 | try {
|
325 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
326 | } catch (error) {
|
327 | if (!didCatchError) {
|
328 | didCatchError = true;
|
329 | caughtError = error;
|
330 | }
|
331 | }
|
332 | });
|
333 |
|
334 | if (didCatchError) {
|
335 | throw caughtError;
|
336 | }
|
337 | }
|
338 |
|
339 | function onWorkScheduled(interactions, threadID) {
|
340 | var didCatchError = false;
|
341 | var caughtError = null;
|
342 | subscribers.forEach(function (subscriber) {
|
343 | try {
|
344 | subscriber.onWorkScheduled(interactions, threadID);
|
345 | } catch (error) {
|
346 | if (!didCatchError) {
|
347 | didCatchError = true;
|
348 | caughtError = error;
|
349 | }
|
350 | }
|
351 | });
|
352 |
|
353 | if (didCatchError) {
|
354 | throw caughtError;
|
355 | }
|
356 | }
|
357 |
|
358 | function onWorkStarted(interactions, threadID) {
|
359 | var didCatchError = false;
|
360 | var caughtError = null;
|
361 | subscribers.forEach(function (subscriber) {
|
362 | try {
|
363 | subscriber.onWorkStarted(interactions, threadID);
|
364 | } catch (error) {
|
365 | if (!didCatchError) {
|
366 | didCatchError = true;
|
367 | caughtError = error;
|
368 | }
|
369 | }
|
370 | });
|
371 |
|
372 | if (didCatchError) {
|
373 | throw caughtError;
|
374 | }
|
375 | }
|
376 |
|
377 | function onWorkStopped(interactions, threadID) {
|
378 | var didCatchError = false;
|
379 | var caughtError = null;
|
380 | subscribers.forEach(function (subscriber) {
|
381 | try {
|
382 | subscriber.onWorkStopped(interactions, threadID);
|
383 | } catch (error) {
|
384 | if (!didCatchError) {
|
385 | didCatchError = true;
|
386 | caughtError = error;
|
387 | }
|
388 | }
|
389 | });
|
390 |
|
391 | if (didCatchError) {
|
392 | throw caughtError;
|
393 | }
|
394 | }
|
395 |
|
396 | function onWorkCanceled(interactions, threadID) {
|
397 | var didCatchError = false;
|
398 | var caughtError = null;
|
399 | subscribers.forEach(function (subscriber) {
|
400 | try {
|
401 | subscriber.onWorkCanceled(interactions, threadID);
|
402 | } catch (error) {
|
403 | if (!didCatchError) {
|
404 | didCatchError = true;
|
405 | caughtError = error;
|
406 | }
|
407 | }
|
408 | });
|
409 |
|
410 | if (didCatchError) {
|
411 | throw caughtError;
|
412 | }
|
413 | }
|
414 |
|
415 | exports.unstable_clear = unstable_clear;
|
416 | exports.unstable_getCurrent = unstable_getCurrent;
|
417 | exports.unstable_getThreadID = unstable_getThreadID;
|
418 | exports.unstable_trace = unstable_trace;
|
419 | exports.unstable_wrap = unstable_wrap;
|
420 | exports.unstable_subscribe = unstable_subscribe;
|
421 | exports.unstable_unsubscribe = unstable_unsubscribe;
|
422 | })();
|
423 | }
|