source: node_modules/scheduler/cjs/scheduler.native.development.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 12.0 KB
Line 
1/**
2 * @license React
3 * scheduler.native.development.js
4 *
5 * Copyright (c) Meta Platforms, Inc. and affiliates.
6 *
7 * This source code is licensed under the MIT license found in the
8 * LICENSE file in the root directory of this source tree.
9 */
10
11"use strict";
12"production" !== process.env.NODE_ENV &&
13 (function () {
14 function performWorkUntilDeadline() {
15 needsPaint = !1;
16 if (isMessageLoopRunning) {
17 var currentTime = getCurrentTime();
18 startTime = currentTime;
19 var hasMoreWork = !0;
20 try {
21 a: {
22 isHostCallbackScheduled = !1;
23 isHostTimeoutScheduled &&
24 ((isHostTimeoutScheduled = !1),
25 localClearTimeout(taskTimeoutID),
26 (taskTimeoutID = -1));
27 isPerformingWork = !0;
28 var previousPriorityLevel = currentPriorityLevel;
29 try {
30 b: {
31 advanceTimers(currentTime);
32 for (
33 currentTask = peek(taskQueue);
34 null !== currentTask &&
35 !(
36 currentTask.expirationTime > currentTime &&
37 shouldYieldToHost()
38 );
39
40 ) {
41 var callback = currentTask.callback;
42 if ("function" === typeof callback) {
43 currentTask.callback = null;
44 currentPriorityLevel = currentTask.priorityLevel;
45 var continuationCallback = callback(
46 currentTask.expirationTime <= currentTime
47 );
48 currentTime = getCurrentTime();
49 if ("function" === typeof continuationCallback) {
50 currentTask.callback = continuationCallback;
51 advanceTimers(currentTime);
52 hasMoreWork = !0;
53 break b;
54 }
55 currentTask === peek(taskQueue) && pop(taskQueue);
56 advanceTimers(currentTime);
57 } else pop(taskQueue);
58 currentTask = peek(taskQueue);
59 }
60 if (null !== currentTask) hasMoreWork = !0;
61 else {
62 var firstTimer = peek(timerQueue);
63 null !== firstTimer &&
64 requestHostTimeout(
65 handleTimeout,
66 firstTimer.startTime - currentTime
67 );
68 hasMoreWork = !1;
69 }
70 }
71 break a;
72 } finally {
73 (currentTask = null),
74 (currentPriorityLevel = previousPriorityLevel),
75 (isPerformingWork = !1);
76 }
77 hasMoreWork = void 0;
78 }
79 } finally {
80 hasMoreWork
81 ? schedulePerformWorkUntilDeadline()
82 : (isMessageLoopRunning = !1);
83 }
84 }
85 }
86 function push(heap, node) {
87 var index = heap.length;
88 heap.push(node);
89 a: for (; 0 < index; ) {
90 var parentIndex = (index - 1) >>> 1,
91 parent = heap[parentIndex];
92 if (0 < compare(parent, node))
93 (heap[parentIndex] = node),
94 (heap[index] = parent),
95 (index = parentIndex);
96 else break a;
97 }
98 }
99 function peek(heap) {
100 return 0 === heap.length ? null : heap[0];
101 }
102 function pop(heap) {
103 if (0 === heap.length) return null;
104 var first = heap[0],
105 last = heap.pop();
106 if (last !== first) {
107 heap[0] = last;
108 a: for (
109 var index = 0, length = heap.length, halfLength = length >>> 1;
110 index < halfLength;
111
112 ) {
113 var leftIndex = 2 * (index + 1) - 1,
114 left = heap[leftIndex],
115 rightIndex = leftIndex + 1,
116 right = heap[rightIndex];
117 if (0 > compare(left, last))
118 rightIndex < length && 0 > compare(right, left)
119 ? ((heap[index] = right),
120 (heap[rightIndex] = last),
121 (index = rightIndex))
122 : ((heap[index] = left),
123 (heap[leftIndex] = last),
124 (index = leftIndex));
125 else if (rightIndex < length && 0 > compare(right, last))
126 (heap[index] = right),
127 (heap[rightIndex] = last),
128 (index = rightIndex);
129 else break a;
130 }
131 }
132 return first;
133 }
134 function compare(a, b) {
135 var diff = a.sortIndex - b.sortIndex;
136 return 0 !== diff ? diff : a.id - b.id;
137 }
138 function advanceTimers(currentTime) {
139 for (var timer = peek(timerQueue); null !== timer; ) {
140 if (null === timer.callback) pop(timerQueue);
141 else if (timer.startTime <= currentTime)
142 pop(timerQueue),
143 (timer.sortIndex = timer.expirationTime),
144 push(taskQueue, timer);
145 else break;
146 timer = peek(timerQueue);
147 }
148 }
149 function handleTimeout(currentTime) {
150 isHostTimeoutScheduled = !1;
151 advanceTimers(currentTime);
152 if (!isHostCallbackScheduled)
153 if (null !== peek(taskQueue))
154 (isHostCallbackScheduled = !0),
155 isMessageLoopRunning ||
156 ((isMessageLoopRunning = !0), schedulePerformWorkUntilDeadline());
157 else {
158 var firstTimer = peek(timerQueue);
159 null !== firstTimer &&
160 requestHostTimeout(
161 handleTimeout,
162 firstTimer.startTime - currentTime
163 );
164 }
165 }
166 function unstable_scheduleCallback$1(priorityLevel, callback, options) {
167 var currentTime = getCurrentTime();
168 "object" === typeof options && null !== options
169 ? ((options = options.delay),
170 (options =
171 "number" === typeof options && 0 < options
172 ? currentTime + options
173 : currentTime))
174 : (options = currentTime);
175 switch (priorityLevel) {
176 case 1:
177 var timeout = -1;
178 break;
179 case 2:
180 timeout = 250;
181 break;
182 case 5:
183 timeout = 1073741823;
184 break;
185 case 4:
186 timeout = 1e4;
187 break;
188 default:
189 timeout = 5e3;
190 }
191 timeout = options + timeout;
192 priorityLevel = {
193 id: taskIdCounter++,
194 callback: callback,
195 priorityLevel: priorityLevel,
196 startTime: options,
197 expirationTime: timeout,
198 sortIndex: -1
199 };
200 options > currentTime
201 ? ((priorityLevel.sortIndex = options),
202 push(timerQueue, priorityLevel),
203 null === peek(taskQueue) &&
204 priorityLevel === peek(timerQueue) &&
205 (isHostTimeoutScheduled
206 ? (localClearTimeout(taskTimeoutID), (taskTimeoutID = -1))
207 : (isHostTimeoutScheduled = !0),
208 requestHostTimeout(handleTimeout, options - currentTime)))
209 : ((priorityLevel.sortIndex = timeout),
210 push(taskQueue, priorityLevel),
211 isHostCallbackScheduled ||
212 isPerformingWork ||
213 ((isHostCallbackScheduled = !0),
214 isMessageLoopRunning ||
215 ((isMessageLoopRunning = !0),
216 schedulePerformWorkUntilDeadline())));
217 return priorityLevel;
218 }
219 function unstable_cancelCallback$1(task) {
220 task.callback = null;
221 }
222 function unstable_getCurrentPriorityLevel$1() {
223 return currentPriorityLevel;
224 }
225 function shouldYieldToHost() {
226 return needsPaint
227 ? !0
228 : getCurrentTime() - startTime < frameInterval
229 ? !1
230 : !0;
231 }
232 function requestPaint() {
233 needsPaint = !0;
234 }
235 function requestHostTimeout(callback, ms) {
236 taskTimeoutID = localSetTimeout(function () {
237 callback(getCurrentTime());
238 }, ms);
239 }
240 function throwNotImplemented() {
241 throw Error("Not implemented.");
242 }
243 if (
244 "object" === typeof performance &&
245 "function" === typeof performance.now
246 ) {
247 var localPerformance = performance;
248 var getCurrentTime = function () {
249 return localPerformance.now();
250 };
251 } else {
252 var localDate = Date,
253 initialTime = localDate.now();
254 getCurrentTime = function () {
255 return localDate.now() - initialTime;
256 };
257 }
258 var taskQueue = [],
259 timerQueue = [],
260 taskIdCounter = 1,
261 currentTask = null,
262 currentPriorityLevel = 3,
263 isPerformingWork = !1,
264 isHostCallbackScheduled = !1,
265 isHostTimeoutScheduled = !1,
266 needsPaint = !1,
267 localSetTimeout = "function" === typeof setTimeout ? setTimeout : null,
268 localClearTimeout =
269 "function" === typeof clearTimeout ? clearTimeout : null,
270 localSetImmediate =
271 "undefined" !== typeof setImmediate ? setImmediate : null,
272 isMessageLoopRunning = !1,
273 taskTimeoutID = -1,
274 frameInterval = 5,
275 startTime = -1;
276 if ("function" === typeof localSetImmediate)
277 var schedulePerformWorkUntilDeadline = function () {
278 localSetImmediate(performWorkUntilDeadline);
279 };
280 else if ("undefined" !== typeof MessageChannel) {
281 var channel = new MessageChannel(),
282 port = channel.port2;
283 channel.port1.onmessage = performWorkUntilDeadline;
284 schedulePerformWorkUntilDeadline = function () {
285 port.postMessage(null);
286 };
287 } else
288 schedulePerformWorkUntilDeadline = function () {
289 localSetTimeout(performWorkUntilDeadline, 0);
290 };
291 channel =
292 "undefined" !== typeof nativeRuntimeScheduler
293 ? nativeRuntimeScheduler.unstable_UserBlockingPriority
294 : 2;
295 var unstable_NormalPriority =
296 "undefined" !== typeof nativeRuntimeScheduler
297 ? nativeRuntimeScheduler.unstable_NormalPriority
298 : 3,
299 unstable_LowPriority =
300 "undefined" !== typeof nativeRuntimeScheduler
301 ? nativeRuntimeScheduler.unstable_LowPriority
302 : 4,
303 unstable_ImmediatePriority =
304 "undefined" !== typeof nativeRuntimeScheduler
305 ? nativeRuntimeScheduler.unstable_ImmediatePriority
306 : 1,
307 unstable_scheduleCallback =
308 "undefined" !== typeof nativeRuntimeScheduler
309 ? nativeRuntimeScheduler.unstable_scheduleCallback
310 : unstable_scheduleCallback$1,
311 unstable_cancelCallback =
312 "undefined" !== typeof nativeRuntimeScheduler
313 ? nativeRuntimeScheduler.unstable_cancelCallback
314 : unstable_cancelCallback$1,
315 unstable_getCurrentPriorityLevel =
316 "undefined" !== typeof nativeRuntimeScheduler
317 ? nativeRuntimeScheduler.unstable_getCurrentPriorityLevel
318 : unstable_getCurrentPriorityLevel$1,
319 unstable_shouldYield =
320 "undefined" !== typeof nativeRuntimeScheduler
321 ? nativeRuntimeScheduler.unstable_shouldYield
322 : shouldYieldToHost,
323 unstable_requestPaint =
324 "undefined" !== typeof nativeRuntimeScheduler
325 ? nativeRuntimeScheduler.unstable_requestPaint
326 : requestPaint,
327 unstable_now =
328 "undefined" !== typeof nativeRuntimeScheduler
329 ? nativeRuntimeScheduler.unstable_now
330 : getCurrentTime;
331 exports.unstable_IdlePriority =
332 "undefined" !== typeof nativeRuntimeScheduler
333 ? nativeRuntimeScheduler.unstable_IdlePriority
334 : 5;
335 exports.unstable_ImmediatePriority = unstable_ImmediatePriority;
336 exports.unstable_LowPriority = unstable_LowPriority;
337 exports.unstable_NormalPriority = unstable_NormalPriority;
338 exports.unstable_Profiling = null;
339 exports.unstable_UserBlockingPriority = channel;
340 exports.unstable_cancelCallback = unstable_cancelCallback;
341 exports.unstable_forceFrameRate = throwNotImplemented;
342 exports.unstable_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel;
343 exports.unstable_next = throwNotImplemented;
344 exports.unstable_now = unstable_now;
345 exports.unstable_requestPaint = unstable_requestPaint;
346 exports.unstable_runWithPriority = throwNotImplemented;
347 exports.unstable_scheduleCallback = unstable_scheduleCallback;
348 exports.unstable_shouldYield = unstable_shouldYield;
349 exports.unstable_wrapCallback = throwNotImplemented;
350 })();
Note: See TracBrowser for help on using the repository browser.