scheduler-tracing.development.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /** @license React v0.20.2
  2. * scheduler-tracing.development.js
  3. *
  4. * Copyright (c) Facebook, Inc. and its affiliates.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. 'use strict';
  10. if (process.env.NODE_ENV !== "production") {
  11. (function() {
  12. 'use strict';
  13. var DEFAULT_THREAD_ID = 0; // Counters used to generate unique IDs.
  14. var interactionIDCounter = 0;
  15. var threadIDCounter = 0; // Set of currently traced interactions.
  16. // Interactions "stack"–
  17. // Meaning that newly traced interactions are appended to the previously active set.
  18. // When an interaction goes out of scope, the previous set (if any) is restored.
  19. exports.__interactionsRef = null; // Listener(s) to notify when interactions begin and end.
  20. exports.__subscriberRef = null;
  21. {
  22. exports.__interactionsRef = {
  23. current: new Set()
  24. };
  25. exports.__subscriberRef = {
  26. current: null
  27. };
  28. }
  29. function unstable_clear(callback) {
  30. var prevInteractions = exports.__interactionsRef.current;
  31. exports.__interactionsRef.current = new Set();
  32. try {
  33. return callback();
  34. } finally {
  35. exports.__interactionsRef.current = prevInteractions;
  36. }
  37. }
  38. function unstable_getCurrent() {
  39. {
  40. return exports.__interactionsRef.current;
  41. }
  42. }
  43. function unstable_getThreadID() {
  44. return ++threadIDCounter;
  45. }
  46. function unstable_trace(name, timestamp, callback) {
  47. var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID;
  48. var interaction = {
  49. __count: 1,
  50. id: interactionIDCounter++,
  51. name: name,
  52. timestamp: timestamp
  53. };
  54. var prevInteractions = exports.__interactionsRef.current; // Traced interactions should stack/accumulate.
  55. // To do that, clone the current interactions.
  56. // The previous set will be restored upon completion.
  57. var interactions = new Set(prevInteractions);
  58. interactions.add(interaction);
  59. exports.__interactionsRef.current = interactions;
  60. var subscriber = exports.__subscriberRef.current;
  61. var returnValue;
  62. try {
  63. if (subscriber !== null) {
  64. subscriber.onInteractionTraced(interaction);
  65. }
  66. } finally {
  67. try {
  68. if (subscriber !== null) {
  69. subscriber.onWorkStarted(interactions, threadID);
  70. }
  71. } finally {
  72. try {
  73. returnValue = callback();
  74. } finally {
  75. exports.__interactionsRef.current = prevInteractions;
  76. try {
  77. if (subscriber !== null) {
  78. subscriber.onWorkStopped(interactions, threadID);
  79. }
  80. } finally {
  81. interaction.__count--; // If no async work was scheduled for this interaction,
  82. // Notify subscribers that it's completed.
  83. if (subscriber !== null && interaction.__count === 0) {
  84. subscriber.onInteractionScheduledWorkCompleted(interaction);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. return returnValue;
  91. }
  92. function unstable_wrap(callback) {
  93. var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
  94. var wrappedInteractions = exports.__interactionsRef.current;
  95. var subscriber = exports.__subscriberRef.current;
  96. if (subscriber !== null) {
  97. subscriber.onWorkScheduled(wrappedInteractions, threadID);
  98. } // Update the pending async work count for the current interactions.
  99. // Update after calling subscribers in case of error.
  100. wrappedInteractions.forEach(function (interaction) {
  101. interaction.__count++;
  102. });
  103. var hasRun = false;
  104. function wrapped() {
  105. var prevInteractions = exports.__interactionsRef.current;
  106. exports.__interactionsRef.current = wrappedInteractions;
  107. subscriber = exports.__subscriberRef.current;
  108. try {
  109. var returnValue;
  110. try {
  111. if (subscriber !== null) {
  112. subscriber.onWorkStarted(wrappedInteractions, threadID);
  113. }
  114. } finally {
  115. try {
  116. returnValue = callback.apply(undefined, arguments);
  117. } finally {
  118. exports.__interactionsRef.current = prevInteractions;
  119. if (subscriber !== null) {
  120. subscriber.onWorkStopped(wrappedInteractions, threadID);
  121. }
  122. }
  123. }
  124. return returnValue;
  125. } finally {
  126. if (!hasRun) {
  127. // We only expect a wrapped function to be executed once,
  128. // But in the event that it's executed more than once–
  129. // Only decrement the outstanding interaction counts once.
  130. hasRun = true; // Update pending async counts for all wrapped interactions.
  131. // If this was the last scheduled async work for any of them,
  132. // Mark them as completed.
  133. wrappedInteractions.forEach(function (interaction) {
  134. interaction.__count--;
  135. if (subscriber !== null && interaction.__count === 0) {
  136. subscriber.onInteractionScheduledWorkCompleted(interaction);
  137. }
  138. });
  139. }
  140. }
  141. }
  142. wrapped.cancel = function cancel() {
  143. subscriber = exports.__subscriberRef.current;
  144. try {
  145. if (subscriber !== null) {
  146. subscriber.onWorkCanceled(wrappedInteractions, threadID);
  147. }
  148. } finally {
  149. // Update pending async counts for all wrapped interactions.
  150. // If this was the last scheduled async work for any of them,
  151. // Mark them as completed.
  152. wrappedInteractions.forEach(function (interaction) {
  153. interaction.__count--;
  154. if (subscriber && interaction.__count === 0) {
  155. subscriber.onInteractionScheduledWorkCompleted(interaction);
  156. }
  157. });
  158. }
  159. };
  160. return wrapped;
  161. }
  162. var subscribers = null;
  163. {
  164. subscribers = new Set();
  165. }
  166. function unstable_subscribe(subscriber) {
  167. {
  168. subscribers.add(subscriber);
  169. if (subscribers.size === 1) {
  170. exports.__subscriberRef.current = {
  171. onInteractionScheduledWorkCompleted: onInteractionScheduledWorkCompleted,
  172. onInteractionTraced: onInteractionTraced,
  173. onWorkCanceled: onWorkCanceled,
  174. onWorkScheduled: onWorkScheduled,
  175. onWorkStarted: onWorkStarted,
  176. onWorkStopped: onWorkStopped
  177. };
  178. }
  179. }
  180. }
  181. function unstable_unsubscribe(subscriber) {
  182. {
  183. subscribers.delete(subscriber);
  184. if (subscribers.size === 0) {
  185. exports.__subscriberRef.current = null;
  186. }
  187. }
  188. }
  189. function onInteractionTraced(interaction) {
  190. var didCatchError = false;
  191. var caughtError = null;
  192. subscribers.forEach(function (subscriber) {
  193. try {
  194. subscriber.onInteractionTraced(interaction);
  195. } catch (error) {
  196. if (!didCatchError) {
  197. didCatchError = true;
  198. caughtError = error;
  199. }
  200. }
  201. });
  202. if (didCatchError) {
  203. throw caughtError;
  204. }
  205. }
  206. function onInteractionScheduledWorkCompleted(interaction) {
  207. var didCatchError = false;
  208. var caughtError = null;
  209. subscribers.forEach(function (subscriber) {
  210. try {
  211. subscriber.onInteractionScheduledWorkCompleted(interaction);
  212. } catch (error) {
  213. if (!didCatchError) {
  214. didCatchError = true;
  215. caughtError = error;
  216. }
  217. }
  218. });
  219. if (didCatchError) {
  220. throw caughtError;
  221. }
  222. }
  223. function onWorkScheduled(interactions, threadID) {
  224. var didCatchError = false;
  225. var caughtError = null;
  226. subscribers.forEach(function (subscriber) {
  227. try {
  228. subscriber.onWorkScheduled(interactions, threadID);
  229. } catch (error) {
  230. if (!didCatchError) {
  231. didCatchError = true;
  232. caughtError = error;
  233. }
  234. }
  235. });
  236. if (didCatchError) {
  237. throw caughtError;
  238. }
  239. }
  240. function onWorkStarted(interactions, threadID) {
  241. var didCatchError = false;
  242. var caughtError = null;
  243. subscribers.forEach(function (subscriber) {
  244. try {
  245. subscriber.onWorkStarted(interactions, threadID);
  246. } catch (error) {
  247. if (!didCatchError) {
  248. didCatchError = true;
  249. caughtError = error;
  250. }
  251. }
  252. });
  253. if (didCatchError) {
  254. throw caughtError;
  255. }
  256. }
  257. function onWorkStopped(interactions, threadID) {
  258. var didCatchError = false;
  259. var caughtError = null;
  260. subscribers.forEach(function (subscriber) {
  261. try {
  262. subscriber.onWorkStopped(interactions, threadID);
  263. } catch (error) {
  264. if (!didCatchError) {
  265. didCatchError = true;
  266. caughtError = error;
  267. }
  268. }
  269. });
  270. if (didCatchError) {
  271. throw caughtError;
  272. }
  273. }
  274. function onWorkCanceled(interactions, threadID) {
  275. var didCatchError = false;
  276. var caughtError = null;
  277. subscribers.forEach(function (subscriber) {
  278. try {
  279. subscriber.onWorkCanceled(interactions, threadID);
  280. } catch (error) {
  281. if (!didCatchError) {
  282. didCatchError = true;
  283. caughtError = error;
  284. }
  285. }
  286. });
  287. if (didCatchError) {
  288. throw caughtError;
  289. }
  290. }
  291. exports.unstable_clear = unstable_clear;
  292. exports.unstable_getCurrent = unstable_getCurrent;
  293. exports.unstable_getThreadID = unstable_getThreadID;
  294. exports.unstable_subscribe = unstable_subscribe;
  295. exports.unstable_trace = unstable_trace;
  296. exports.unstable_unsubscribe = unstable_unsubscribe;
  297. exports.unstable_wrap = unstable_wrap;
  298. })();
  299. }