123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- /** @license React v0.20.2
- * scheduler-tracing.development.js
- *
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
- 'use strict';
- if (process.env.NODE_ENV !== "production") {
- (function() {
- 'use strict';
- var DEFAULT_THREAD_ID = 0; // Counters used to generate unique IDs.
- var interactionIDCounter = 0;
- var threadIDCounter = 0; // Set of currently traced interactions.
- // Interactions "stack"–
- // Meaning that newly traced interactions are appended to the previously active set.
- // When an interaction goes out of scope, the previous set (if any) is restored.
- exports.__interactionsRef = null; // Listener(s) to notify when interactions begin and end.
- exports.__subscriberRef = null;
- {
- exports.__interactionsRef = {
- current: new Set()
- };
- exports.__subscriberRef = {
- current: null
- };
- }
- function unstable_clear(callback) {
- var prevInteractions = exports.__interactionsRef.current;
- exports.__interactionsRef.current = new Set();
- try {
- return callback();
- } finally {
- exports.__interactionsRef.current = prevInteractions;
- }
- }
- function unstable_getCurrent() {
- {
- return exports.__interactionsRef.current;
- }
- }
- function unstable_getThreadID() {
- return ++threadIDCounter;
- }
- function unstable_trace(name, timestamp, callback) {
- var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID;
- var interaction = {
- __count: 1,
- id: interactionIDCounter++,
- name: name,
- timestamp: timestamp
- };
- var prevInteractions = exports.__interactionsRef.current; // Traced interactions should stack/accumulate.
- // To do that, clone the current interactions.
- // The previous set will be restored upon completion.
- var interactions = new Set(prevInteractions);
- interactions.add(interaction);
- exports.__interactionsRef.current = interactions;
- var subscriber = exports.__subscriberRef.current;
- var returnValue;
- try {
- if (subscriber !== null) {
- subscriber.onInteractionTraced(interaction);
- }
- } finally {
- try {
- if (subscriber !== null) {
- subscriber.onWorkStarted(interactions, threadID);
- }
- } finally {
- try {
- returnValue = callback();
- } finally {
- exports.__interactionsRef.current = prevInteractions;
- try {
- if (subscriber !== null) {
- subscriber.onWorkStopped(interactions, threadID);
- }
- } finally {
- interaction.__count--; // If no async work was scheduled for this interaction,
- // Notify subscribers that it's completed.
- if (subscriber !== null && interaction.__count === 0) {
- subscriber.onInteractionScheduledWorkCompleted(interaction);
- }
- }
- }
- }
- }
- return returnValue;
- }
- function unstable_wrap(callback) {
- var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
- var wrappedInteractions = exports.__interactionsRef.current;
- var subscriber = exports.__subscriberRef.current;
- if (subscriber !== null) {
- subscriber.onWorkScheduled(wrappedInteractions, threadID);
- } // Update the pending async work count for the current interactions.
- // Update after calling subscribers in case of error.
- wrappedInteractions.forEach(function (interaction) {
- interaction.__count++;
- });
- var hasRun = false;
- function wrapped() {
- var prevInteractions = exports.__interactionsRef.current;
- exports.__interactionsRef.current = wrappedInteractions;
- subscriber = exports.__subscriberRef.current;
- try {
- var returnValue;
- try {
- if (subscriber !== null) {
- subscriber.onWorkStarted(wrappedInteractions, threadID);
- }
- } finally {
- try {
- returnValue = callback.apply(undefined, arguments);
- } finally {
- exports.__interactionsRef.current = prevInteractions;
- if (subscriber !== null) {
- subscriber.onWorkStopped(wrappedInteractions, threadID);
- }
- }
- }
- return returnValue;
- } finally {
- if (!hasRun) {
- // We only expect a wrapped function to be executed once,
- // But in the event that it's executed more than once–
- // Only decrement the outstanding interaction counts once.
- hasRun = true; // Update pending async counts for all wrapped interactions.
- // If this was the last scheduled async work for any of them,
- // Mark them as completed.
- wrappedInteractions.forEach(function (interaction) {
- interaction.__count--;
- if (subscriber !== null && interaction.__count === 0) {
- subscriber.onInteractionScheduledWorkCompleted(interaction);
- }
- });
- }
- }
- }
- wrapped.cancel = function cancel() {
- subscriber = exports.__subscriberRef.current;
- try {
- if (subscriber !== null) {
- subscriber.onWorkCanceled(wrappedInteractions, threadID);
- }
- } finally {
- // Update pending async counts for all wrapped interactions.
- // If this was the last scheduled async work for any of them,
- // Mark them as completed.
- wrappedInteractions.forEach(function (interaction) {
- interaction.__count--;
- if (subscriber && interaction.__count === 0) {
- subscriber.onInteractionScheduledWorkCompleted(interaction);
- }
- });
- }
- };
- return wrapped;
- }
- var subscribers = null;
- {
- subscribers = new Set();
- }
- function unstable_subscribe(subscriber) {
- {
- subscribers.add(subscriber);
- if (subscribers.size === 1) {
- exports.__subscriberRef.current = {
- onInteractionScheduledWorkCompleted: onInteractionScheduledWorkCompleted,
- onInteractionTraced: onInteractionTraced,
- onWorkCanceled: onWorkCanceled,
- onWorkScheduled: onWorkScheduled,
- onWorkStarted: onWorkStarted,
- onWorkStopped: onWorkStopped
- };
- }
- }
- }
- function unstable_unsubscribe(subscriber) {
- {
- subscribers.delete(subscriber);
- if (subscribers.size === 0) {
- exports.__subscriberRef.current = null;
- }
- }
- }
- function onInteractionTraced(interaction) {
- var didCatchError = false;
- var caughtError = null;
- subscribers.forEach(function (subscriber) {
- try {
- subscriber.onInteractionTraced(interaction);
- } catch (error) {
- if (!didCatchError) {
- didCatchError = true;
- caughtError = error;
- }
- }
- });
- if (didCatchError) {
- throw caughtError;
- }
- }
- function onInteractionScheduledWorkCompleted(interaction) {
- var didCatchError = false;
- var caughtError = null;
- subscribers.forEach(function (subscriber) {
- try {
- subscriber.onInteractionScheduledWorkCompleted(interaction);
- } catch (error) {
- if (!didCatchError) {
- didCatchError = true;
- caughtError = error;
- }
- }
- });
- if (didCatchError) {
- throw caughtError;
- }
- }
- function onWorkScheduled(interactions, threadID) {
- var didCatchError = false;
- var caughtError = null;
- subscribers.forEach(function (subscriber) {
- try {
- subscriber.onWorkScheduled(interactions, threadID);
- } catch (error) {
- if (!didCatchError) {
- didCatchError = true;
- caughtError = error;
- }
- }
- });
- if (didCatchError) {
- throw caughtError;
- }
- }
- function onWorkStarted(interactions, threadID) {
- var didCatchError = false;
- var caughtError = null;
- subscribers.forEach(function (subscriber) {
- try {
- subscriber.onWorkStarted(interactions, threadID);
- } catch (error) {
- if (!didCatchError) {
- didCatchError = true;
- caughtError = error;
- }
- }
- });
- if (didCatchError) {
- throw caughtError;
- }
- }
- function onWorkStopped(interactions, threadID) {
- var didCatchError = false;
- var caughtError = null;
- subscribers.forEach(function (subscriber) {
- try {
- subscriber.onWorkStopped(interactions, threadID);
- } catch (error) {
- if (!didCatchError) {
- didCatchError = true;
- caughtError = error;
- }
- }
- });
- if (didCatchError) {
- throw caughtError;
- }
- }
- function onWorkCanceled(interactions, threadID) {
- var didCatchError = false;
- var caughtError = null;
- subscribers.forEach(function (subscriber) {
- try {
- subscriber.onWorkCanceled(interactions, threadID);
- } catch (error) {
- if (!didCatchError) {
- didCatchError = true;
- caughtError = error;
- }
- }
- });
- if (didCatchError) {
- throw caughtError;
- }
- }
- exports.unstable_clear = unstable_clear;
- exports.unstable_getCurrent = unstable_getCurrent;
- exports.unstable_getThreadID = unstable_getThreadID;
- exports.unstable_subscribe = unstable_subscribe;
- exports.unstable_trace = unstable_trace;
- exports.unstable_unsubscribe = unstable_unsubscribe;
- exports.unstable_wrap = unstable_wrap;
- })();
- }
|