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 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | var enableSchedulerTracing = true;
|
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 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | var DEFAULT_THREAD_ID = 0;
|
102 |
|
103 |
|
104 | var interactionIDCounter = 0;
|
105 | var threadIDCounter = 0;
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | exports.__interactionsRef = null;
|
112 |
|
113 |
|
114 | exports.__subscriberRef = null;
|
115 |
|
116 | if (enableSchedulerTracing) {
|
117 | exports.__interactionsRef = {
|
118 | current: new Set()
|
119 | };
|
120 | exports.__subscriberRef = {
|
121 | current: null
|
122 | };
|
123 | }
|
124 |
|
125 | function unstable_clear(callback) {
|
126 | if (!enableSchedulerTracing) {
|
127 | return callback();
|
128 | }
|
129 |
|
130 | var prevInteractions = exports.__interactionsRef.current;
|
131 | exports.__interactionsRef.current = new Set();
|
132 |
|
133 | try {
|
134 | return callback();
|
135 | } finally {
|
136 | exports.__interactionsRef.current = prevInteractions;
|
137 | }
|
138 | }
|
139 |
|
140 | function unstable_getCurrent() {
|
141 | if (!enableSchedulerTracing) {
|
142 | return null;
|
143 | } else {
|
144 | return exports.__interactionsRef.current;
|
145 | }
|
146 | }
|
147 |
|
148 | function unstable_getThreadID() {
|
149 | return ++threadIDCounter;
|
150 | }
|
151 |
|
152 | function unstable_trace(name, timestamp, callback) {
|
153 | var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID;
|
154 |
|
155 | if (!enableSchedulerTracing) {
|
156 | return callback();
|
157 | }
|
158 |
|
159 | var interaction = {
|
160 | __count: 1,
|
161 | id: interactionIDCounter++,
|
162 | name: name,
|
163 | timestamp: timestamp
|
164 | };
|
165 |
|
166 | var prevInteractions = exports.__interactionsRef.current;
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | var interactions = new Set(prevInteractions);
|
172 | interactions.add(interaction);
|
173 | exports.__interactionsRef.current = interactions;
|
174 |
|
175 | var subscriber = exports.__subscriberRef.current;
|
176 | var returnValue = void 0;
|
177 |
|
178 | try {
|
179 | if (subscriber !== null) {
|
180 | subscriber.onInteractionTraced(interaction);
|
181 | }
|
182 | } finally {
|
183 | try {
|
184 | if (subscriber !== null) {
|
185 | subscriber.onWorkStarted(interactions, threadID);
|
186 | }
|
187 | } finally {
|
188 | try {
|
189 | returnValue = callback();
|
190 | } finally {
|
191 | exports.__interactionsRef.current = prevInteractions;
|
192 |
|
193 | try {
|
194 | if (subscriber !== null) {
|
195 | subscriber.onWorkStopped(interactions, threadID);
|
196 | }
|
197 | } finally {
|
198 | interaction.__count--;
|
199 |
|
200 |
|
201 |
|
202 | if (subscriber !== null && interaction.__count === 0) {
|
203 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
204 | }
|
205 | }
|
206 | }
|
207 | }
|
208 | }
|
209 |
|
210 | return returnValue;
|
211 | }
|
212 |
|
213 | function unstable_wrap(callback) {
|
214 | var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
|
215 |
|
216 | if (!enableSchedulerTracing) {
|
217 | return callback;
|
218 | }
|
219 |
|
220 | var wrappedInteractions = exports.__interactionsRef.current;
|
221 |
|
222 | var subscriber = exports.__subscriberRef.current;
|
223 | if (subscriber !== null) {
|
224 | subscriber.onWorkScheduled(wrappedInteractions, threadID);
|
225 | }
|
226 |
|
227 |
|
228 |
|
229 | wrappedInteractions.forEach(function (interaction) {
|
230 | interaction.__count++;
|
231 | });
|
232 |
|
233 | var hasRun = false;
|
234 |
|
235 | function wrapped() {
|
236 | var prevInteractions = exports.__interactionsRef.current;
|
237 | exports.__interactionsRef.current = wrappedInteractions;
|
238 |
|
239 | subscriber = exports.__subscriberRef.current;
|
240 |
|
241 | try {
|
242 | var returnValue = void 0;
|
243 |
|
244 | try {
|
245 | if (subscriber !== null) {
|
246 | subscriber.onWorkStarted(wrappedInteractions, threadID);
|
247 | }
|
248 | } finally {
|
249 | try {
|
250 | returnValue = callback.apply(undefined, arguments);
|
251 | } finally {
|
252 | exports.__interactionsRef.current = prevInteractions;
|
253 |
|
254 | if (subscriber !== null) {
|
255 | subscriber.onWorkStopped(wrappedInteractions, threadID);
|
256 | }
|
257 | }
|
258 | }
|
259 |
|
260 | return returnValue;
|
261 | } finally {
|
262 | if (!hasRun) {
|
263 |
|
264 |
|
265 |
|
266 | hasRun = true;
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | wrappedInteractions.forEach(function (interaction) {
|
272 | interaction.__count--;
|
273 |
|
274 | if (subscriber !== null && interaction.__count === 0) {
|
275 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
276 | }
|
277 | });
|
278 | }
|
279 | }
|
280 | }
|
281 |
|
282 | wrapped.cancel = function cancel() {
|
283 | subscriber = exports.__subscriberRef.current;
|
284 |
|
285 | try {
|
286 | if (subscriber !== null) {
|
287 | subscriber.onWorkCanceled(wrappedInteractions, threadID);
|
288 | }
|
289 | } finally {
|
290 |
|
291 |
|
292 |
|
293 | wrappedInteractions.forEach(function (interaction) {
|
294 | interaction.__count--;
|
295 |
|
296 | if (subscriber && interaction.__count === 0) {
|
297 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
298 | }
|
299 | });
|
300 | }
|
301 | };
|
302 |
|
303 | return wrapped;
|
304 | }
|
305 |
|
306 | var subscribers = null;
|
307 | if (enableSchedulerTracing) {
|
308 | subscribers = new Set();
|
309 | }
|
310 |
|
311 | function unstable_subscribe(subscriber) {
|
312 | if (enableSchedulerTracing) {
|
313 | subscribers.add(subscriber);
|
314 |
|
315 | if (subscribers.size === 1) {
|
316 | exports.__subscriberRef.current = {
|
317 | onInteractionScheduledWorkCompleted: onInteractionScheduledWorkCompleted,
|
318 | onInteractionTraced: onInteractionTraced,
|
319 | onWorkCanceled: onWorkCanceled,
|
320 | onWorkScheduled: onWorkScheduled,
|
321 | onWorkStarted: onWorkStarted,
|
322 | onWorkStopped: onWorkStopped
|
323 | };
|
324 | }
|
325 | }
|
326 | }
|
327 |
|
328 | function unstable_unsubscribe(subscriber) {
|
329 | if (enableSchedulerTracing) {
|
330 | subscribers.delete(subscriber);
|
331 |
|
332 | if (subscribers.size === 0) {
|
333 | exports.__subscriberRef.current = null;
|
334 | }
|
335 | }
|
336 | }
|
337 |
|
338 | function onInteractionTraced(interaction) {
|
339 | var didCatchError = false;
|
340 | var caughtError = null;
|
341 |
|
342 | subscribers.forEach(function (subscriber) {
|
343 | try {
|
344 | subscriber.onInteractionTraced(interaction);
|
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 onInteractionScheduledWorkCompleted(interaction) {
|
359 | var didCatchError = false;
|
360 | var caughtError = null;
|
361 |
|
362 | subscribers.forEach(function (subscriber) {
|
363 | try {
|
364 | subscriber.onInteractionScheduledWorkCompleted(interaction);
|
365 | } catch (error) {
|
366 | if (!didCatchError) {
|
367 | didCatchError = true;
|
368 | caughtError = error;
|
369 | }
|
370 | }
|
371 | });
|
372 |
|
373 | if (didCatchError) {
|
374 | throw caughtError;
|
375 | }
|
376 | }
|
377 |
|
378 | function onWorkScheduled(interactions, threadID) {
|
379 | var didCatchError = false;
|
380 | var caughtError = null;
|
381 |
|
382 | subscribers.forEach(function (subscriber) {
|
383 | try {
|
384 | subscriber.onWorkScheduled(interactions, threadID);
|
385 | } catch (error) {
|
386 | if (!didCatchError) {
|
387 | didCatchError = true;
|
388 | caughtError = error;
|
389 | }
|
390 | }
|
391 | });
|
392 |
|
393 | if (didCatchError) {
|
394 | throw caughtError;
|
395 | }
|
396 | }
|
397 |
|
398 | function onWorkStarted(interactions, threadID) {
|
399 | var didCatchError = false;
|
400 | var caughtError = null;
|
401 |
|
402 | subscribers.forEach(function (subscriber) {
|
403 | try {
|
404 | subscriber.onWorkStarted(interactions, threadID);
|
405 | } catch (error) {
|
406 | if (!didCatchError) {
|
407 | didCatchError = true;
|
408 | caughtError = error;
|
409 | }
|
410 | }
|
411 | });
|
412 |
|
413 | if (didCatchError) {
|
414 | throw caughtError;
|
415 | }
|
416 | }
|
417 |
|
418 | function onWorkStopped(interactions, threadID) {
|
419 | var didCatchError = false;
|
420 | var caughtError = null;
|
421 |
|
422 | subscribers.forEach(function (subscriber) {
|
423 | try {
|
424 | subscriber.onWorkStopped(interactions, threadID);
|
425 | } catch (error) {
|
426 | if (!didCatchError) {
|
427 | didCatchError = true;
|
428 | caughtError = error;
|
429 | }
|
430 | }
|
431 | });
|
432 |
|
433 | if (didCatchError) {
|
434 | throw caughtError;
|
435 | }
|
436 | }
|
437 |
|
438 | function onWorkCanceled(interactions, threadID) {
|
439 | var didCatchError = false;
|
440 | var caughtError = null;
|
441 |
|
442 | subscribers.forEach(function (subscriber) {
|
443 | try {
|
444 | subscriber.onWorkCanceled(interactions, threadID);
|
445 | } catch (error) {
|
446 | if (!didCatchError) {
|
447 | didCatchError = true;
|
448 | caughtError = error;
|
449 | }
|
450 | }
|
451 | });
|
452 |
|
453 | if (didCatchError) {
|
454 | throw caughtError;
|
455 | }
|
456 | }
|
457 |
|
458 | exports.unstable_clear = unstable_clear;
|
459 | exports.unstable_getCurrent = unstable_getCurrent;
|
460 | exports.unstable_getThreadID = unstable_getThreadID;
|
461 | exports.unstable_trace = unstable_trace;
|
462 | exports.unstable_wrap = unstable_wrap;
|
463 | exports.unstable_subscribe = unstable_subscribe;
|
464 | exports.unstable_unsubscribe = unstable_unsubscribe;
|
465 | })();
|
466 | }
|