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