scheduler
Advanced tools
Comparing version 0.15.0 to 0.16.0
{ | ||
"branch": "master", | ||
"buildNumber": "33869", | ||
"checksum": "2fe1c5c", | ||
"commit": "a1dbb852c", | ||
"buildNumber": "48138", | ||
"checksum": "d91410d", | ||
"commit": "3694a3b5e", | ||
"environment": "ci", | ||
"reactVersion": "16.8.6-canary-a1dbb852c" | ||
"reactVersion": "16.9.0-canary-3694a3b5e" | ||
} |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-tracing.development.js | ||
@@ -22,4 +22,3 @@ * | ||
// In some cases, StrictMode should also double-render lifecycles. | ||
// In some cases, StrictMode should also double-render lifecycles. | ||
// This can be confusing for tests though, | ||
@@ -29,88 +28,69 @@ // And it can be bad for performance in production. | ||
// To preserve the "Pause on caught exceptions" behavior of the debugger, we | ||
// To preserve the "Pause on caught exceptions" behavior of the debugger, we | ||
// replay the begin phase of a failed component inside invokeGuardedCallback. | ||
// Warn about deprecated, async-unsafe lifecycles; relates to RFC #6: | ||
// Warn about deprecated, async-unsafe lifecycles; relates to RFC #6: | ||
// Gather advanced timing metrics for Profiler subtrees. | ||
// Trace which interactions trigger each commit. | ||
// Gather advanced timing metrics for Profiler subtrees. | ||
var enableSchedulerTracing = true; // Only used in www builds. | ||
// Trace which interactions trigger each commit. | ||
var enableSchedulerTracing = true; | ||
// Only used in www builds. | ||
// TODO: true? Here it might just be false. | ||
// Only used in www builds. | ||
// Only used in www builds. | ||
// Only used in www builds. | ||
// Only used in www builds. | ||
// Disable javascript: URL strings in href for XSS protection. | ||
// Disable javascript: URL strings in href for XSS protection. | ||
// React Fire: prevent the value and checked attributes from syncing | ||
// React Fire: prevent the value and checked attributes from syncing | ||
// with their related DOM properties | ||
// These APIs will no longer be "unstable" in the upcoming 16.7 release, | ||
// These APIs will no longer be "unstable" in the upcoming 16.7 release, | ||
// Control this behavior with a flag to support 16.6 minor releases in the meanwhile. | ||
// See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information | ||
// See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information | ||
// This is a flag so we can fix warnings in RN core before turning it on | ||
// Experimental React Flare event system and event components support. | ||
// Experimental React Flare event system and event components support. | ||
// Experimental Host Component support. | ||
// Experimental Scope support. | ||
// Experimental Host Component support. | ||
// New API for JSX transforms to target - https://github.com/reactjs/rfcs/pull/107 | ||
// New API for JSX transforms to target - https://github.com/reactjs/rfcs/pull/107 | ||
// We will enforce mocking scheduler with scheduler/unstable_mock at some point. (v17?) | ||
// We will enforce mocking scheduler with scheduler/unstable_mock at some point. (v17?) | ||
// Till then, we warn about the missing mock, but still fallback to a sync mode compatible version | ||
// Temporary flag to revert the fix in #15650 | ||
// For tests, we flush suspense fallbacks in an act scope; | ||
// For tests, we flush suspense fallbacks in an act scope; | ||
// *except* in some of our own tests, where we test incremental loading states. | ||
// Changes priority of some events like mousemove to user-blocking priority, | ||
// Changes priority of some events like mousemove to user-blocking priority, | ||
// but without making them discrete. The flag exists in case it causes | ||
// starvation problems. | ||
// Add a callback property to suspense to notify which promises are currently | ||
// Add a callback property to suspense to notify which promises are currently | ||
// in the update queue. This allows reporting and tracing of what is causing | ||
// the user to see a loading state. | ||
// Also allows hydration callbacks to fire when a dehydrated boundary gets | ||
// hydrated or deleted. | ||
// Part of the simplification of React.createElement so we can eventually move | ||
// Part of the simplification of React.createElement so we can eventually move | ||
// from React.createElement to React.jsx | ||
// https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md | ||
var DEFAULT_THREAD_ID = 0; | ||
var DEFAULT_THREAD_ID = 0; // Counters used to generate unique IDs. | ||
// Counters used to generate unique IDs. | ||
var interactionIDCounter = 0; | ||
var threadIDCounter = 0; | ||
// Set of currently traced interactions. | ||
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.__interactionsRef = null; // Listener(s) to notify when interactions begin and end. | ||
exports.__subscriberRef = null; | ||
@@ -141,3 +121,2 @@ | ||
} | ||
function unstable_getCurrent() { | ||
@@ -150,7 +129,5 @@ if (!enableSchedulerTracing) { | ||
} | ||
function unstable_getThreadID() { | ||
return ++threadIDCounter; | ||
} | ||
function unstable_trace(name, timestamp, callback) { | ||
@@ -169,14 +146,11 @@ var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID; | ||
}; | ||
var prevInteractions = exports.__interactionsRef.current; | ||
// Traced interactions should stack/accumulate. | ||
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 = void 0; | ||
var returnValue; | ||
@@ -203,6 +177,5 @@ try { | ||
} finally { | ||
interaction.__count--; | ||
interaction.__count--; // If no async work was scheduled for this interaction, | ||
// Notify subscribers that it's completed. | ||
// If no async work was scheduled for this interaction, | ||
// Notify subscribers that it's completed. | ||
if (subscriber !== null && interaction.__count === 0) { | ||
@@ -218,3 +191,2 @@ subscriber.onInteractionScheduledWorkCompleted(interaction); | ||
} | ||
function unstable_wrap(callback) { | ||
@@ -228,14 +200,13 @@ var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID; | ||
var wrappedInteractions = exports.__interactionsRef.current; | ||
var subscriber = exports.__subscriberRef.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. | ||
// 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; | ||
@@ -246,7 +217,6 @@ | ||
exports.__interactionsRef.current = wrappedInteractions; | ||
subscriber = exports.__subscriberRef.current; | ||
try { | ||
var returnValue = void 0; | ||
var returnValue; | ||
@@ -275,7 +245,6 @@ try { | ||
// Only decrement the outstanding interaction counts once. | ||
hasRun = true; | ||
// Update pending async counts for all wrapped interactions. | ||
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) { | ||
@@ -317,2 +286,3 @@ interaction.__count--; | ||
var subscribers = null; | ||
if (enableSchedulerTracing) { | ||
@@ -338,3 +308,2 @@ subscribers = new Set(); | ||
} | ||
function unstable_unsubscribe(subscriber) { | ||
@@ -353,3 +322,2 @@ if (enableSchedulerTracing) { | ||
var caughtError = null; | ||
subscribers.forEach(function (subscriber) { | ||
@@ -374,3 +342,2 @@ try { | ||
var caughtError = null; | ||
subscribers.forEach(function (subscriber) { | ||
@@ -395,3 +362,2 @@ try { | ||
var caughtError = null; | ||
subscribers.forEach(function (subscriber) { | ||
@@ -416,3 +382,2 @@ try { | ||
var caughtError = null; | ||
subscribers.forEach(function (subscriber) { | ||
@@ -437,3 +402,2 @@ try { | ||
var caughtError = null; | ||
subscribers.forEach(function (subscriber) { | ||
@@ -458,3 +422,2 @@ try { | ||
var caughtError = null; | ||
subscribers.forEach(function (subscriber) { | ||
@@ -461,0 +424,0 @@ try { |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-tracing.production.min.js | ||
@@ -3,0 +3,0 @@ * |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-tracing.profiling.min.js | ||
@@ -10,9 +10,8 @@ * | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var g=0,m=0;exports.__interactionsRef=null;exports.__subscriberRef=null;exports.__interactionsRef={current:new Set};exports.__subscriberRef={current:null};var n=null;n=new Set;function p(e){var d=!1,a=null;n.forEach(function(c){try{c.onInteractionTraced(e)}catch(b){d||(d=!0,a=b)}});if(d)throw a;} | ||
function q(e){var d=!1,a=null;n.forEach(function(c){try{c.onInteractionScheduledWorkCompleted(e)}catch(b){d||(d=!0,a=b)}});if(d)throw a;}function r(e,d){var a=!1,c=null;n.forEach(function(b){try{b.onWorkScheduled(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;}function t(e,d){var a=!1,c=null;n.forEach(function(b){try{b.onWorkStarted(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;}function u(e,d){var a=!1,c=null;n.forEach(function(b){try{b.onWorkStopped(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;} | ||
function v(e,d){var a=!1,c=null;n.forEach(function(b){try{b.onWorkCanceled(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;}exports.unstable_clear=function(e){var d=exports.__interactionsRef.current;exports.__interactionsRef.current=new Set;try{return e()}finally{exports.__interactionsRef.current=d}};exports.unstable_getCurrent=function(){return exports.__interactionsRef.current};exports.unstable_getThreadID=function(){return++m}; | ||
exports.unstable_trace=function(e,d,a){var c=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0,b={__count:1,id:g++,name:e,timestamp:d},f=exports.__interactionsRef.current,k=new Set(f);k.add(b);exports.__interactionsRef.current=k;var h=exports.__subscriberRef.current,l=void 0;try{if(null!==h)h.onInteractionTraced(b)}finally{try{if(null!==h)h.onWorkStarted(k,c)}finally{try{l=a()}finally{exports.__interactionsRef.current=f;try{if(null!==h)h.onWorkStopped(k,c)}finally{if(b.__count--,null!==h&& | ||
0===b.__count)h.onInteractionScheduledWorkCompleted(b)}}}}return l}; | ||
exports.unstable_wrap=function(e){function d(){var d=exports.__interactionsRef.current;exports.__interactionsRef.current=c;b=exports.__subscriberRef.current;try{var h=void 0;try{if(null!==b)b.onWorkStarted(c,a)}finally{try{h=e.apply(void 0,arguments)}finally{if(exports.__interactionsRef.current=d,null!==b)b.onWorkStopped(c,a)}}return h}finally{f||(f=!0,c.forEach(function(a){a.__count--;if(null!==b&&0===a.__count)b.onInteractionScheduledWorkCompleted(a)}))}}var a=1<arguments.length&&void 0!==arguments[1]? | ||
arguments[1]:0,c=exports.__interactionsRef.current,b=exports.__subscriberRef.current;if(null!==b)b.onWorkScheduled(c,a);c.forEach(function(a){a.__count++});var f=!1;d.cancel=function(){b=exports.__subscriberRef.current;try{if(null!==b)b.onWorkCanceled(c,a)}finally{c.forEach(function(a){a.__count--;if(b&&0===a.__count)b.onInteractionScheduledWorkCompleted(a)})}};return d}; | ||
exports.unstable_subscribe=function(e){n.add(e);1===n.size&&(exports.__subscriberRef.current={onInteractionScheduledWorkCompleted:q,onInteractionTraced:p,onWorkCanceled:v,onWorkScheduled:r,onWorkStarted:t,onWorkStopped:u})};exports.unstable_unsubscribe=function(e){n.delete(e);0===n.size&&(exports.__subscriberRef.current=null)}; | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var g=0,l=0;exports.__interactionsRef=null;exports.__subscriberRef=null;exports.__interactionsRef={current:new Set};exports.__subscriberRef={current:null};var m=null;m=new Set;function n(e){var d=!1,a=null;m.forEach(function(c){try{c.onInteractionTraced(e)}catch(b){d||(d=!0,a=b)}});if(d)throw a;} | ||
function p(e){var d=!1,a=null;m.forEach(function(c){try{c.onInteractionScheduledWorkCompleted(e)}catch(b){d||(d=!0,a=b)}});if(d)throw a;}function q(e,d){var a=!1,c=null;m.forEach(function(b){try{b.onWorkScheduled(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;}function r(e,d){var a=!1,c=null;m.forEach(function(b){try{b.onWorkStarted(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;}function t(e,d){var a=!1,c=null;m.forEach(function(b){try{b.onWorkStopped(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;} | ||
function u(e,d){var a=!1,c=null;m.forEach(function(b){try{b.onWorkCanceled(e,d)}catch(f){a||(a=!0,c=f)}});if(a)throw c;}exports.unstable_clear=function(e){var d=exports.__interactionsRef.current;exports.__interactionsRef.current=new Set;try{return e()}finally{exports.__interactionsRef.current=d}};exports.unstable_getCurrent=function(){return exports.__interactionsRef.current};exports.unstable_getThreadID=function(){return++l}; | ||
exports.unstable_trace=function(e,d,a){var c=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0,b={__count:1,id:g++,name:e,timestamp:d},f=exports.__interactionsRef.current,k=new Set(f);k.add(b);exports.__interactionsRef.current=k;var h=exports.__subscriberRef.current;try{if(null!==h)h.onInteractionTraced(b)}finally{try{if(null!==h)h.onWorkStarted(k,c)}finally{try{var v=a()}finally{exports.__interactionsRef.current=f;try{if(null!==h)h.onWorkStopped(k,c)}finally{if(b.__count--,null!==h&&0===b.__count)h.onInteractionScheduledWorkCompleted(b)}}}}return v}; | ||
exports.unstable_wrap=function(e){function d(){var d=exports.__interactionsRef.current;exports.__interactionsRef.current=c;b=exports.__subscriberRef.current;try{try{if(null!==b)b.onWorkStarted(c,a)}finally{try{var h=e.apply(void 0,arguments)}finally{if(exports.__interactionsRef.current=d,null!==b)b.onWorkStopped(c,a)}}return h}finally{f||(f=!0,c.forEach(function(a){a.__count--;if(null!==b&&0===a.__count)b.onInteractionScheduledWorkCompleted(a)}))}}var a=1<arguments.length&&void 0!==arguments[1]?arguments[1]: | ||
0,c=exports.__interactionsRef.current,b=exports.__subscriberRef.current;if(null!==b)b.onWorkScheduled(c,a);c.forEach(function(a){a.__count++});var f=!1;d.cancel=function(){b=exports.__subscriberRef.current;try{if(null!==b)b.onWorkCanceled(c,a)}finally{c.forEach(function(a){a.__count--;if(b&&0===a.__count)b.onInteractionScheduledWorkCompleted(a)})}};return d}; | ||
exports.unstable_subscribe=function(e){m.add(e);1===m.size&&(exports.__subscriberRef.current={onInteractionScheduledWorkCompleted:p,onInteractionTraced:n,onWorkCanceled:u,onWorkScheduled:q,onWorkStarted:r,onWorkStopped:t})};exports.unstable_unsubscribe=function(e){m.delete(e);0===m.size&&(exports.__subscriberRef.current=null)}; |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-unstable_mock.development.js | ||
@@ -22,2 +22,5 @@ * | ||
var enableProfiling = true; | ||
var currentTime = 0; | ||
@@ -33,3 +36,2 @@ var scheduledCallback = null; | ||
var shouldYieldForPaint = false; | ||
function requestHostCallback(callback) { | ||
@@ -39,4 +41,2 @@ scheduledCallback = callback; | ||
function requestHostTimeout(callback, ms) { | ||
@@ -46,3 +46,2 @@ scheduledTimeout = callback; | ||
} | ||
function cancelHostTimeout() { | ||
@@ -52,3 +51,2 @@ scheduledTimeout = null; | ||
} | ||
function shouldYieldToHost() { | ||
@@ -60,16 +58,12 @@ if (expectedNumberOfYields !== -1 && yieldedValues !== null && yieldedValues.length >= expectedNumberOfYields || shouldYieldForPaint && needsPaint) { | ||
} | ||
return false; | ||
} | ||
function getCurrentTime() { | ||
return currentTime; | ||
} | ||
function forceFrameRate() { | ||
// No-op | ||
function forceFrameRate() {// No-op | ||
} | ||
// Should only be used via an assertion helper that inspects the yielded values. | ||
// Should only be used via an assertion helper that inspects the yielded values. | ||
function unstable_flushNumberOfYields(count) { | ||
@@ -79,2 +73,3 @@ if (isFlushing) { | ||
} | ||
if (scheduledCallback !== null) { | ||
@@ -84,7 +79,10 @@ var cb = scheduledCallback; | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = true; | ||
do { | ||
hasMoreWork = cb(true, currentTime); | ||
} while (hasMoreWork && !didStop); | ||
if (!hasMoreWork) { | ||
@@ -100,3 +98,2 @@ scheduledCallback = null; | ||
} | ||
function unstable_flushUntilNextPaint() { | ||
@@ -106,2 +103,3 @@ if (isFlushing) { | ||
} | ||
if (scheduledCallback !== null) { | ||
@@ -112,7 +110,10 @@ var cb = scheduledCallback; | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = true; | ||
do { | ||
hasMoreWork = cb(true, currentTime); | ||
} while (hasMoreWork && !didStop); | ||
if (!hasMoreWork) { | ||
@@ -128,3 +129,2 @@ scheduledCallback = null; | ||
} | ||
function unstable_flushExpired() { | ||
@@ -134,6 +134,9 @@ if (isFlushing) { | ||
} | ||
if (scheduledCallback !== null) { | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = scheduledCallback(false, currentTime); | ||
if (!hasMoreWork) { | ||
@@ -147,3 +150,2 @@ scheduledCallback = null; | ||
} | ||
function unstable_flushAllWithoutAsserting() { | ||
@@ -154,13 +156,18 @@ // Returns false if no work was flushed. | ||
} | ||
if (scheduledCallback !== null) { | ||
var cb = scheduledCallback; | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = true; | ||
do { | ||
hasMoreWork = cb(true, currentTime); | ||
} while (hasMoreWork); | ||
if (!hasMoreWork) { | ||
scheduledCallback = null; | ||
} | ||
return true; | ||
@@ -174,3 +181,2 @@ } finally { | ||
} | ||
function unstable_clearYields() { | ||
@@ -180,2 +186,3 @@ if (yieldedValues === null) { | ||
} | ||
var values = yieldedValues; | ||
@@ -185,3 +192,2 @@ yieldedValues = null; | ||
} | ||
function unstable_flushAll() { | ||
@@ -191,3 +197,5 @@ if (yieldedValues !== null) { | ||
} | ||
unstable_flushAllWithoutAsserting(); | ||
if (yieldedValues !== null) { | ||
@@ -197,3 +205,2 @@ throw new Error('While flushing work, something yielded a value. Use an ' + 'assertion helper to assert on the log of yielded values, e.g. ' + 'expect(Scheduler).toFlushAndYield([...])'); | ||
} | ||
function unstable_yieldValue(value) { | ||
@@ -206,5 +213,5 @@ if (yieldedValues === null) { | ||
} | ||
function unstable_advanceTime(ms) { | ||
currentTime += ms; | ||
if (!isFlushing) { | ||
@@ -216,6 +223,6 @@ if (scheduledTimeout !== null && timeoutTime <= currentTime) { | ||
} | ||
unstable_flushExpired(); | ||
} | ||
} | ||
function requestPaint() { | ||
@@ -225,5 +232,86 @@ needsPaint = true; | ||
/* eslint-disable no-var */ | ||
function push(heap, node) { | ||
var index = heap.length; | ||
heap.push(node); | ||
siftUp(heap, node, index); | ||
} | ||
function peek(heap) { | ||
var first = heap[0]; | ||
return first === undefined ? null : first; | ||
} | ||
function pop(heap) { | ||
var first = heap[0]; | ||
if (first !== undefined) { | ||
var last = heap.pop(); | ||
if (last !== first) { | ||
heap[0] = last; | ||
siftDown(heap, last, 0); | ||
} | ||
return first; | ||
} else { | ||
return null; | ||
} | ||
} | ||
function siftUp(heap, node, i) { | ||
var index = i; | ||
while (true) { | ||
var parentIndex = Math.floor((index - 1) / 2); | ||
var parent = heap[parentIndex]; | ||
if (parent !== undefined && compare(parent, node) > 0) { | ||
// The parent is larger. Swap positions. | ||
heap[parentIndex] = node; | ||
heap[index] = parent; | ||
index = parentIndex; | ||
} else { | ||
// The parent is smaller. Exit. | ||
return; | ||
} | ||
} | ||
} | ||
function siftDown(heap, node, i) { | ||
var index = i; | ||
var length = heap.length; | ||
while (index < length) { | ||
var leftIndex = (index + 1) * 2 - 1; | ||
var left = heap[leftIndex]; | ||
var rightIndex = leftIndex + 1; | ||
var right = heap[rightIndex]; // If the left or right node is smaller, swap with the smaller of those. | ||
if (left !== undefined && compare(left, node) < 0) { | ||
if (right !== undefined && compare(right, left) < 0) { | ||
heap[index] = right; | ||
heap[rightIndex] = node; | ||
index = rightIndex; | ||
} else { | ||
heap[index] = left; | ||
heap[leftIndex] = node; | ||
index = leftIndex; | ||
} | ||
} else if (right !== undefined && compare(right, node) < 0) { | ||
heap[index] = right; | ||
heap[rightIndex] = node; | ||
index = rightIndex; | ||
} else { | ||
// Neither child is smaller. Exit. | ||
return; | ||
} | ||
} | ||
} | ||
function compare(a, b) { | ||
// Compare sort index first, then task id. | ||
var diff = a.sortIndex - b.sortIndex; | ||
return diff !== 0 ? diff : a.id - b.id; | ||
} | ||
// TODO: Use symbols? | ||
var NoPriority = 0; | ||
var ImmediatePriority = 1; | ||
@@ -235,161 +323,210 @@ var UserBlockingPriority = 2; | ||
// Max 31 bit integer. The max integer size in V8 for 32-bit systems. | ||
// Math.pow(2, 30) - 1 | ||
// 0b111111111111111111111111111111 | ||
var maxSigned31BitInt = 1073741823; | ||
var runIdCounter = 0; | ||
var mainThreadIdCounter = 0; | ||
var profilingStateSize = 4; | ||
var sharedProfilingBuffer = enableProfiling ? // $FlowFixMe Flow doesn't know about SharedArrayBuffer | ||
typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : // $FlowFixMe Flow doesn't know about ArrayBuffer | ||
typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9 | ||
: null; | ||
var profilingState = enableProfiling && sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : []; // We can't read this but it helps save bytes for null checks | ||
// Times out immediately | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; | ||
// Eventually times out | ||
var USER_BLOCKING_PRIORITY = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; | ||
// Never times out | ||
var IDLE_PRIORITY = maxSigned31BitInt; | ||
var PRIORITY = 0; | ||
var CURRENT_TASK_ID = 1; | ||
var CURRENT_RUN_ID = 2; | ||
var QUEUE_SIZE = 3; | ||
// Tasks are stored as a circular, doubly linked list. | ||
var firstTask = null; | ||
var firstDelayedTask = null; | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; // This is maintained with a counter, because the size of the priority queue | ||
// array might include canceled tasks. | ||
// Pausing the scheduler is useful for debugging. | ||
var isSchedulerPaused = false; | ||
profilingState[QUEUE_SIZE] = 0; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
} // Bytes per element is 4 | ||
var currentTask = null; | ||
var currentPriorityLevel = NormalPriority; | ||
// This is set while performing work, to prevent re-entrancy. | ||
var isPerformingWork = false; | ||
var INITIAL_EVENT_LOG_SIZE = 131072; | ||
var MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes | ||
var isHostCallbackScheduled = false; | ||
var isHostTimeoutScheduled = false; | ||
var eventLogSize = 0; | ||
var eventLogBuffer = null; | ||
var eventLog = null; | ||
var eventLogIndex = 0; | ||
var TaskStartEvent = 1; | ||
var TaskCompleteEvent = 2; | ||
var TaskErrorEvent = 3; | ||
var TaskCancelEvent = 4; | ||
var TaskRunEvent = 5; | ||
var TaskYieldEvent = 6; | ||
var SchedulerSuspendEvent = 7; | ||
var SchedulerResumeEvent = 8; | ||
function scheduler_flushTaskAtPriority_Immediate(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function logEvent(entries) { | ||
if (eventLog !== null) { | ||
var offset = eventLogIndex; | ||
eventLogIndex += entries.length; | ||
if (eventLogIndex + 1 > eventLogSize) { | ||
eventLogSize *= 2; | ||
if (eventLogSize > MAX_EVENT_LOG_SIZE) { | ||
console.error("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.'); | ||
stopLoggingProfilingEvents(); | ||
return; | ||
} | ||
var newEventLog = new Int32Array(eventLogSize * 4); | ||
newEventLog.set(eventLog); | ||
eventLogBuffer = newEventLog.buffer; | ||
eventLog = newEventLog; | ||
} | ||
eventLog.set(entries, offset); | ||
} | ||
} | ||
function scheduler_flushTaskAtPriority_UserBlocking(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function startLoggingProfilingEvents() { | ||
eventLogSize = INITIAL_EVENT_LOG_SIZE; | ||
eventLogBuffer = new ArrayBuffer(eventLogSize * 4); | ||
eventLog = new Int32Array(eventLogBuffer); | ||
eventLogIndex = 0; | ||
} | ||
function scheduler_flushTaskAtPriority_Normal(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function stopLoggingProfilingEvents() { | ||
var buffer = eventLogBuffer; | ||
eventLogSize = 0; | ||
eventLogBuffer = null; | ||
eventLog = null; | ||
eventLogIndex = 0; | ||
return buffer; | ||
} | ||
function scheduler_flushTaskAtPriority_Low(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function markTaskStart(task, time) { | ||
if (enableProfiling) { | ||
profilingState[QUEUE_SIZE]++; | ||
if (eventLog !== null) { | ||
logEvent([TaskStartEvent, time, task.id, task.priorityLevel]); | ||
} | ||
} | ||
} | ||
function scheduler_flushTaskAtPriority_Idle(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function markTaskCompleted(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[QUEUE_SIZE]--; | ||
if (eventLog !== null) { | ||
logEvent([TaskCompleteEvent, time, task.id]); | ||
} | ||
} | ||
} | ||
function markTaskCanceled(task, time) { | ||
if (enableProfiling) { | ||
profilingState[QUEUE_SIZE]--; | ||
function flushTask(task, currentTime) { | ||
// Remove the task from the list before calling the callback. That way the | ||
// list is in a consistent state even if the callback throws. | ||
var next = task.next; | ||
if (next === task) { | ||
// This is the only scheduled task. Clear the list. | ||
firstTask = null; | ||
} else { | ||
// Remove the task from its position in the list. | ||
if (task === firstTask) { | ||
firstTask = next; | ||
if (eventLog !== null) { | ||
logEvent([TaskCancelEvent, time, task.id]); | ||
} | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
} | ||
task.next = task.previous = null; | ||
} | ||
function markTaskErrored(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[QUEUE_SIZE]--; | ||
// Now it's safe to execute the task. | ||
var callback = task.callback; | ||
var previousPriorityLevel = currentPriorityLevel; | ||
var previousTask = currentTask; | ||
currentPriorityLevel = task.priorityLevel; | ||
currentTask = task; | ||
var continuationCallback; | ||
try { | ||
var didUserCallbackTimeout = task.expirationTime <= currentTime; | ||
// Add an extra function to the callstack. Profiling tools can use this | ||
// to infer the priority of work that appears higher in the stack. | ||
switch (currentPriorityLevel) { | ||
case ImmediatePriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Immediate(callback, didUserCallbackTimeout); | ||
break; | ||
case UserBlockingPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_UserBlocking(callback, didUserCallbackTimeout); | ||
break; | ||
case NormalPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Normal(callback, didUserCallbackTimeout); | ||
break; | ||
case LowPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Low(callback, didUserCallbackTimeout); | ||
break; | ||
case IdlePriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Idle(callback, didUserCallbackTimeout); | ||
break; | ||
if (eventLog !== null) { | ||
logEvent([TaskErrorEvent, time, task.id]); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentPriorityLevel = previousPriorityLevel; | ||
currentTask = previousTask; | ||
} | ||
} | ||
function markTaskRun(task, time) { | ||
if (enableProfiling) { | ||
runIdCounter++; | ||
profilingState[PRIORITY] = task.priorityLevel; | ||
profilingState[CURRENT_TASK_ID] = task.id; | ||
profilingState[CURRENT_RUN_ID] = runIdCounter; | ||
// A callback may return a continuation. The continuation should be scheduled | ||
// with the same priority and expiration as the just-finished callback. | ||
if (typeof continuationCallback === 'function') { | ||
var expirationTime = task.expirationTime; | ||
var continuationTask = task; | ||
continuationTask.callback = continuationCallback; | ||
if (eventLog !== null) { | ||
logEvent([TaskRunEvent, time, task.id, runIdCounter]); | ||
} | ||
} | ||
} | ||
function markTaskYield(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[CURRENT_RUN_ID] = 0; | ||
// Insert the new callback into the list, sorted by its timeout. This is | ||
// almost the same as the code in `scheduleCallback`, except the callback | ||
// is inserted into the list *before* callbacks of equal timeout instead | ||
// of after. | ||
if (firstTask === null) { | ||
// This is the first callback in the list. | ||
firstTask = continuationTask.next = continuationTask.previous = continuationTask; | ||
} else { | ||
var nextAfterContinuation = null; | ||
var t = firstTask; | ||
do { | ||
if (expirationTime <= t.expirationTime) { | ||
// This task times out at or after the continuation. We will insert | ||
// the continuation *before* this task. | ||
nextAfterContinuation = t; | ||
break; | ||
} | ||
t = t.next; | ||
} while (t !== firstTask); | ||
if (nextAfterContinuation === null) { | ||
// No equal or lower priority task was found, which means the new task | ||
// is the lowest priority task in the list. | ||
nextAfterContinuation = firstTask; | ||
} else if (nextAfterContinuation === firstTask) { | ||
// The new task is the highest priority task in the list. | ||
firstTask = continuationTask; | ||
} | ||
if (eventLog !== null) { | ||
logEvent([TaskYieldEvent, time, task.id, runIdCounter]); | ||
} | ||
} | ||
} | ||
function markSchedulerSuspended(time) { | ||
if (enableProfiling) { | ||
mainThreadIdCounter++; | ||
var _previous = nextAfterContinuation.previous; | ||
_previous.next = nextAfterContinuation.previous = continuationTask; | ||
continuationTask.next = nextAfterContinuation; | ||
continuationTask.previous = _previous; | ||
if (eventLog !== null) { | ||
logEvent([SchedulerSuspendEvent, time, mainThreadIdCounter]); | ||
} | ||
} | ||
} | ||
function markSchedulerUnsuspended(time) { | ||
if (enableProfiling) { | ||
if (eventLog !== null) { | ||
logEvent([SchedulerResumeEvent, time, mainThreadIdCounter]); | ||
} | ||
} | ||
} | ||
/* eslint-disable no-var */ | ||
// Math.pow(2, 30) - 1 | ||
// 0b111111111111111111111111111111 | ||
var maxSigned31BitInt = 1073741823; // Times out immediately | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out | ||
var USER_BLOCKING_PRIORITY = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; // Never times out | ||
var IDLE_PRIORITY = maxSigned31BitInt; // Tasks are stored on a min heap | ||
var taskQueue = []; | ||
var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. | ||
var taskIdCounter = 1; // Pausing the scheduler is useful for debugging. | ||
var isSchedulerPaused = false; | ||
var currentTask = null; | ||
var currentPriorityLevel = NormalPriority; // This is set while performing work, to prevent re-entrancy. | ||
var isPerformingWork = false; | ||
var isHostCallbackScheduled = false; | ||
var isHostTimeoutScheduled = false; | ||
function advanceTimers(currentTime) { | ||
// Check for tasks that are no longer delayed and add them to the queue. | ||
if (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime) { | ||
do { | ||
var task = firstDelayedTask; | ||
var next = task.next; | ||
if (task === next) { | ||
firstDelayedTask = null; | ||
} else { | ||
firstDelayedTask = next; | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
var timer = peek(timerQueue); | ||
while (timer !== null) { | ||
if (timer.callback === null) { | ||
// Timer was cancelled. | ||
pop(timerQueue); | ||
} else if (timer.startTime <= currentTime) { | ||
// Timer fired. Transfer to the task queue. | ||
pop(timerQueue); | ||
timer.sortIndex = timer.expirationTime; | ||
push(taskQueue, timer); | ||
if (enableProfiling) { | ||
markTaskStart(timer, currentTime); | ||
timer.isQueued = true; | ||
} | ||
task.next = task.previous = null; | ||
insertScheduledTask(task, task.expirationTime); | ||
} while (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime); | ||
} else { | ||
// Remaining timers are pending. | ||
return; | ||
} | ||
timer = peek(timerQueue); | ||
} | ||
@@ -403,7 +540,11 @@ } | ||
if (!isHostCallbackScheduled) { | ||
if (firstTask !== null) { | ||
if (peek(taskQueue) !== null) { | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
} else if (firstDelayedTask !== null) { | ||
requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime); | ||
} else { | ||
var firstTimer = peek(timerQueue); | ||
if (firstTimer !== null) { | ||
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime); | ||
} | ||
} | ||
@@ -414,9 +555,9 @@ } | ||
function flushWork(hasTimeRemaining, initialTime) { | ||
// Exit right away if we're currently paused | ||
if (enableSchedulerDebugging && isSchedulerPaused) { | ||
return; | ||
} | ||
if (enableProfiling) { | ||
markSchedulerUnsuspended(initialTime); | ||
} // We'll need a host callback the next time work is scheduled. | ||
// We'll need a host callback the next time work is scheduled. | ||
isHostCallbackScheduled = false; | ||
if (isHostTimeoutScheduled) { | ||
@@ -428,40 +569,92 @@ // We scheduled a timeout but it's no longer needed. Cancel it. | ||
var currentTime = initialTime; | ||
advanceTimers(currentTime); | ||
isPerformingWork = true; | ||
var previousPriorityLevel = currentPriorityLevel; | ||
isPerformingWork = true; | ||
try { | ||
if (!hasTimeRemaining) { | ||
// Flush all the expired callbacks without yielding. | ||
// TODO: Split flushWork into two separate functions instead of using | ||
// a boolean argument? | ||
while (firstTask !== null && firstTask.expirationTime <= currentTime && !(enableSchedulerDebugging && isSchedulerPaused)) { | ||
flushTask(firstTask, currentTime); | ||
currentTime = getCurrentTime(); | ||
advanceTimers(currentTime); | ||
if (enableProfiling) { | ||
try { | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} catch (error) { | ||
if (currentTask !== null) { | ||
var currentTime = getCurrentTime(); | ||
markTaskErrored(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
throw error; | ||
} | ||
} else { | ||
// Keep flushing callbacks until we run out of time in the frame. | ||
if (firstTask !== null) { | ||
do { | ||
flushTask(firstTask, currentTime); | ||
currentTime = getCurrentTime(); | ||
advanceTimers(currentTime); | ||
} while (firstTask !== null && !shouldYieldToHost() && !(enableSchedulerDebugging && isSchedulerPaused)); | ||
} | ||
// No catch in prod codepath. | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} | ||
// Return whether there's additional work | ||
if (firstTask !== null) { | ||
return true; | ||
} else { | ||
if (firstDelayedTask !== null) { | ||
requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime); | ||
} | ||
return false; | ||
} | ||
} finally { | ||
currentTask = null; | ||
currentPriorityLevel = previousPriorityLevel; | ||
isPerformingWork = false; | ||
if (enableProfiling) { | ||
var _currentTime = getCurrentTime(); | ||
markSchedulerSuspended(_currentTime); | ||
} | ||
} | ||
} | ||
function workLoop(hasTimeRemaining, initialTime) { | ||
var currentTime = initialTime; | ||
advanceTimers(currentTime); | ||
currentTask = peek(taskQueue); | ||
while (currentTask !== null && !(enableSchedulerDebugging && isSchedulerPaused)) { | ||
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) { | ||
// This currentTask hasn't expired, and we've reached the deadline. | ||
break; | ||
} | ||
var callback = currentTask.callback; | ||
if (callback !== null) { | ||
currentTask.callback = null; | ||
currentPriorityLevel = currentTask.priorityLevel; | ||
var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; | ||
markTaskRun(currentTask, currentTime); | ||
var continuationCallback = callback(didUserCallbackTimeout); | ||
currentTime = getCurrentTime(); | ||
if (typeof continuationCallback === 'function') { | ||
currentTask.callback = continuationCallback; | ||
markTaskYield(currentTask, currentTime); | ||
} else { | ||
if (enableProfiling) { | ||
markTaskCompleted(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
if (currentTask === peek(taskQueue)) { | ||
pop(taskQueue); | ||
} | ||
} | ||
advanceTimers(currentTime); | ||
} else { | ||
pop(taskQueue); | ||
} | ||
currentTask = peek(taskQueue); | ||
} // Return whether there's additional work | ||
if (currentTask !== null) { | ||
return true; | ||
} else { | ||
var firstTimer = peek(timerQueue); | ||
if (firstTimer !== null) { | ||
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime); | ||
} | ||
return false; | ||
} | ||
} | ||
function unstable_runWithPriority(priorityLevel, eventHandler) { | ||
@@ -475,2 +668,3 @@ switch (priorityLevel) { | ||
break; | ||
default: | ||
@@ -492,2 +686,3 @@ priorityLevel = NormalPriority; | ||
var priorityLevel; | ||
switch (currentPriorityLevel) { | ||
@@ -500,2 +695,3 @@ case ImmediatePriority: | ||
break; | ||
default: | ||
@@ -536,8 +732,12 @@ // Anything lower than normal priority should remain at the current level. | ||
return IMMEDIATE_PRIORITY_TIMEOUT; | ||
case UserBlockingPriority: | ||
return USER_BLOCKING_PRIORITY; | ||
case IdlePriority: | ||
return IDLE_PRIORITY; | ||
case LowPriority: | ||
return LOW_PRIORITY_TIMEOUT; | ||
case NormalPriority: | ||
@@ -551,7 +751,8 @@ default: | ||
var currentTime = getCurrentTime(); | ||
var startTime; | ||
var timeout; | ||
if (typeof options === 'object' && options !== null) { | ||
var delay = options.delay; | ||
if (typeof delay === 'number' && delay > 0) { | ||
@@ -562,2 +763,3 @@ startTime = currentTime + delay; | ||
} | ||
timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel); | ||
@@ -570,4 +772,4 @@ } else { | ||
var expirationTime = startTime + timeout; | ||
var newTask = { | ||
id: taskIdCounter++, | ||
callback: callback, | ||
@@ -577,10 +779,15 @@ priorityLevel: priorityLevel, | ||
expirationTime: expirationTime, | ||
next: null, | ||
previous: null | ||
sortIndex: -1 | ||
}; | ||
if (enableProfiling) { | ||
newTask.isQueued = false; | ||
} | ||
if (startTime > currentTime) { | ||
// This is a delayed task. | ||
insertDelayedTask(newTask, startTime); | ||
if (firstTask === null && firstDelayedTask === newTask) { | ||
newTask.sortIndex = startTime; | ||
push(timerQueue, newTask); | ||
if (peek(taskQueue) === null && newTask === peek(timerQueue)) { | ||
// All tasks are delayed, and this is the task with the earliest delay. | ||
@@ -592,10 +799,18 @@ if (isHostTimeoutScheduled) { | ||
isHostTimeoutScheduled = true; | ||
} | ||
// Schedule a timeout. | ||
} // Schedule a timeout. | ||
requestHostTimeout(handleTimeout, startTime - currentTime); | ||
} | ||
} else { | ||
insertScheduledTask(newTask, expirationTime); | ||
// Schedule a host callback, if needed. If we're already performing work, | ||
newTask.sortIndex = expirationTime; | ||
push(taskQueue, newTask); | ||
if (enableProfiling) { | ||
markTaskStart(newTask, currentTime); | ||
newTask.isQueued = true; | ||
} // Schedule a host callback, if needed. If we're already performing work, | ||
// wait until the next time we yield. | ||
if (!isHostCallbackScheduled && !isPerformingWork) { | ||
@@ -610,70 +825,2 @@ isHostCallbackScheduled = true; | ||
function insertScheduledTask(newTask, expirationTime) { | ||
// Insert the new task into the list, ordered first by its timeout, then by | ||
// insertion. So the new task is inserted after any other task the | ||
// same timeout | ||
if (firstTask === null) { | ||
// This is the first task in the list. | ||
firstTask = newTask.next = newTask.previous = newTask; | ||
} else { | ||
var next = null; | ||
var task = firstTask; | ||
do { | ||
if (expirationTime < task.expirationTime) { | ||
// The new task times out before this one. | ||
next = task; | ||
break; | ||
} | ||
task = task.next; | ||
} while (task !== firstTask); | ||
if (next === null) { | ||
// No task with a later timeout was found, which means the new task has | ||
// the latest timeout in the list. | ||
next = firstTask; | ||
} else if (next === firstTask) { | ||
// The new task has the earliest expiration in the entire list. | ||
firstTask = newTask; | ||
} | ||
var previous = next.previous; | ||
previous.next = next.previous = newTask; | ||
newTask.next = next; | ||
newTask.previous = previous; | ||
} | ||
} | ||
function insertDelayedTask(newTask, startTime) { | ||
// Insert the new task into the list, ordered by its start time. | ||
if (firstDelayedTask === null) { | ||
// This is the first task in the list. | ||
firstDelayedTask = newTask.next = newTask.previous = newTask; | ||
} else { | ||
var next = null; | ||
var task = firstDelayedTask; | ||
do { | ||
if (startTime < task.startTime) { | ||
// The new task times out before this one. | ||
next = task; | ||
break; | ||
} | ||
task = task.next; | ||
} while (task !== firstDelayedTask); | ||
if (next === null) { | ||
// No task with a later timeout was found, which means the new task has | ||
// the latest timeout in the list. | ||
next = firstDelayedTask; | ||
} else if (next === firstDelayedTask) { | ||
// The new task has the earliest expiration in the entire list. | ||
firstDelayedTask = newTask; | ||
} | ||
var previous = next.previous; | ||
previous.next = next.previous = newTask; | ||
newTask.next = next; | ||
newTask.previous = previous; | ||
} | ||
} | ||
function unstable_pauseExecution() { | ||
@@ -685,2 +832,3 @@ isSchedulerPaused = true; | ||
isSchedulerPaused = false; | ||
if (!isHostCallbackScheduled && !isPerformingWork) { | ||
@@ -693,30 +841,18 @@ isHostCallbackScheduled = true; | ||
function unstable_getFirstCallbackNode() { | ||
return firstTask; | ||
return peek(taskQueue); | ||
} | ||
function unstable_cancelCallback(task) { | ||
var next = task.next; | ||
if (next === null) { | ||
// Already cancelled. | ||
return; | ||
} | ||
if (task === next) { | ||
if (task === firstTask) { | ||
firstTask = null; | ||
} else if (task === firstDelayedTask) { | ||
firstDelayedTask = null; | ||
if (enableProfiling) { | ||
if (task.isQueued) { | ||
var currentTime = getCurrentTime(); | ||
markTaskCanceled(task, currentTime); | ||
task.isQueued = false; | ||
} | ||
} else { | ||
if (task === firstTask) { | ||
firstTask = next; | ||
} else if (task === firstDelayedTask) { | ||
firstDelayedTask = next; | ||
} | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
} | ||
} // Null out the callback to indicate the task has been canceled. (Can't | ||
// remove from the queue because you can't remove arbitrary nodes from an | ||
// array based heap, only the first one.) | ||
task.next = task.previous = null; | ||
task.callback = null; | ||
} | ||
@@ -731,6 +867,12 @@ | ||
advanceTimers(currentTime); | ||
return currentTask !== null && firstTask !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); | ||
var firstTask = peek(taskQueue); | ||
return firstTask !== currentTask && currentTask !== null && firstTask !== null && firstTask.callback !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); | ||
} | ||
var unstable_requestPaint = requestPaint; | ||
var unstable_Profiling = enableProfiling ? { | ||
startLoggingProfilingEvents: startLoggingProfilingEvents, | ||
stopLoggingProfilingEvents: stopLoggingProfilingEvents, | ||
sharedProfilingBuffer: sharedProfilingBuffer | ||
} : null; | ||
@@ -763,3 +905,4 @@ exports.unstable_flushAllWithoutAsserting = unstable_flushAllWithoutAsserting; | ||
exports.unstable_forceFrameRate = forceFrameRate; | ||
exports.unstable_Profiling = unstable_Profiling; | ||
})(); | ||
} |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-unstable_mock.production.min.js | ||
@@ -10,13 +10,12 @@ * | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var d=0,e=null,g=null,k=-1,l=null,n=-1,q=!1,r=!1,t=!1,u=!1;function v(){return-1!==n&&null!==l&&l.length>=n||u&&t?q=!0:!1}function w(){if(r)throw Error("Already flushing work.");if(null!==e){r=!0;try{e(!1,d)||(e=null)}finally{r=!1}}}function x(){if(r)throw Error("Already flushing work.");if(null!==e){var a=e;r=!0;try{var b=!0;do b=a(!0,d);while(b);b||(e=null);return!0}finally{r=!1}}else return!1} | ||
var y=null,z=null,A=null,B=3,C=!1,D=!1,E=!1; | ||
function F(a,b){var c=a.next;if(c===a)y=null;else{a===y&&(y=c);var f=a.previous;f.next=c;c.previous=f}a.next=a.previous=null;c=a.callback;f=B;var p=A;B=a.priorityLevel;A=a;try{var h=a.expirationTime<=b;switch(B){case 1:var m=c(h);break;case 2:m=c(h);break;case 3:m=c(h);break;case 4:m=c(h);break;case 5:m=c(h)}}catch(L){throw L;}finally{B=f,A=p}if("function"===typeof m)if(b=a.expirationTime,a.callback=m,null===y)y=a.next=a.previous=a;else{m=null;h=y;do{if(b<=h.expirationTime){m=h;break}h=h.next}while(h!== | ||
y);null===m?m=y:m===y&&(y=a);b=m.previous;b.next=m.previous=a;a.next=m;a.previous=b}}function G(a){if(null!==z&&z.startTime<=a){do{var b=z,c=b.next;if(b===c)z=null;else{z=c;var f=b.previous;f.next=c;c.previous=f}b.next=b.previous=null;H(b,b.expirationTime)}while(null!==z&&z.startTime<=a)}}function I(a){E=!1;G(a);D||(null!==y?(D=!0,e=J):null!==z&&(a=z.startTime-a,g=I,k=d+a))} | ||
function J(a,b){D=!1;E&&(E=!1,g=null,k=-1);G(b);C=!0;try{if(!a)for(;null!==y&&y.expirationTime<=b;)F(y,b),b=d,G(b);else if(null!==y){do F(y,b),b=d,G(b);while(null!==y&&!v())}if(null!==y)return!0;if(null!==z){var c=z.startTime-b;g=I;k=d+c}return!1}finally{C=!1}}function K(a){switch(a){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1E4;default:return 5E3}} | ||
function H(a,b){if(null===y)y=a.next=a.previous=a;else{var c=null,f=y;do{if(b<f.expirationTime){c=f;break}f=f.next}while(f!==y);null===c?c=y:c===y&&(y=a);b=c.previous;b.next=c.previous=a;a.next=c;a.previous=b}}exports.unstable_flushAllWithoutAsserting=x;exports.unstable_flushNumberOfYields=function(a){if(r)throw Error("Already flushing work.");if(null!==e){var b=e;n=a;r=!0;try{a=!0;do a=b(!0,d);while(a&&!q);a||(e=null)}finally{n=-1,r=q=!1}}};exports.unstable_flushExpired=w; | ||
exports.unstable_clearYields=function(){if(null===l)return[];var a=l;l=null;return a};exports.unstable_flushUntilNextPaint=function(){if(r)throw Error("Already flushing work.");if(null!==e){var a=e;u=!0;t=!1;r=!0;try{var b=!0;do b=a(!0,d);while(b&&!q);b||(e=null)}finally{r=q=u=!1}}}; | ||
exports.unstable_flushAll=function(){if(null!==l)throw Error("Log is not empty. Assert on the log of yielded values before flushing additional work.");x();if(null!==l)throw Error("While flushing work, something yielded a value. Use an assertion helper to assert on the log of yielded values, e.g. expect(Scheduler).toFlushAndYield([...])");};exports.unstable_yieldValue=function(a){null===l?l=[a]:l.push(a)};exports.unstable_advanceTime=function(a){d+=a;r||(null!==g&&k<=d&&(g(d),k=-1,g=null),w())}; | ||
exports.unstable_ImmediatePriority=1;exports.unstable_UserBlockingPriority=2;exports.unstable_NormalPriority=3;exports.unstable_IdlePriority=5;exports.unstable_LowPriority=4;exports.unstable_runWithPriority=function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=B;B=a;try{return b()}finally{B=c}};exports.unstable_next=function(a){switch(B){case 1:case 2:case 3:var b=3;break;default:b=B}var c=B;B=b;try{return a()}finally{B=c}}; | ||
exports.unstable_scheduleCallback=function(a,b,c){var f=d;if("object"===typeof c&&null!==c){var p=c.delay;p="number"===typeof p&&0<p?f+p:f;c="number"===typeof c.timeout?c.timeout:K(a)}else c=K(a),p=f;c=p+c;a={callback:b,priorityLevel:a,startTime:p,expirationTime:c,next:null,previous:null};if(p>f){c=p;if(null===z)z=a.next=a.previous=a;else{b=null;var h=z;do{if(c<h.startTime){b=h;break}h=h.next}while(h!==z);null===b?b=z:b===z&&(z=a);c=b.previous;c.next=b.previous=a;a.next=b;a.previous=c}null===y&&z=== | ||
a&&(E?(g=null,k=-1):E=!0,g=I,k=d+(p-f))}else H(a,c),D||C||(D=!0,e=J);return a};exports.unstable_cancelCallback=function(a){var b=a.next;if(null!==b){if(a===b)a===y?y=null:a===z&&(z=null);else{a===y?y=b:a===z&&(z=b);var c=a.previous;c.next=b;b.previous=c}a.next=a.previous=null}};exports.unstable_wrapCallback=function(a){var b=B;return function(){var c=B;B=b;try{return a.apply(this,arguments)}finally{B=c}}};exports.unstable_getCurrentPriorityLevel=function(){return B}; | ||
exports.unstable_shouldYield=function(){var a=d;G(a);return null!==A&&null!==y&&y.startTime<=a&&y.expirationTime<A.expirationTime||v()};exports.unstable_requestPaint=function(){t=!0};exports.unstable_continueExecution=function(){D||C||(D=!0,e=J)};exports.unstable_pauseExecution=function(){};exports.unstable_getFirstCallbackNode=function(){return y};exports.unstable_now=function(){return d};exports.unstable_forceFrameRate=function(){}; | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var f=0,g=null,h=null,k=-1,l=null,m=-1,n=!1,p=!1,q=!1,r=!1;function t(){return-1!==m&&null!==l&&l.length>=m||r&&q?n=!0:!1}function x(){if(p)throw Error("Already flushing work.");if(null!==g){p=!0;try{g(!1,f)||(g=null)}finally{p=!1}}}function z(){if(p)throw Error("Already flushing work.");if(null!==g){var a=g;p=!0;try{var b=!0;do b=a(!0,f);while(b);b||(g=null);return!0}finally{p=!1}}else return!1} | ||
function A(a,b){var c=a.length;a.push(b);a:for(;;){var d=Math.floor((c-1)/2),e=a[d];if(void 0!==e&&0<B(e,b))a[d]=b,a[c]=e,c=d;else break a}}function C(a){a=a[0];return void 0===a?null:a}function D(a){var b=a[0];if(void 0!==b){var c=a.pop();if(c!==b){a[0]=c;a:for(var d=0,e=a.length;d<e;){var u=2*(d+1)-1,v=a[u],w=u+1,y=a[w];if(void 0!==v&&0>B(v,c))void 0!==y&&0>B(y,v)?(a[d]=y,a[w]=c,d=w):(a[d]=v,a[u]=c,d=u);else if(void 0!==y&&0>B(y,c))a[d]=y,a[w]=c,d=w;else break a}}return b}return null} | ||
function B(a,b){var c=a.sortIndex-b.sortIndex;return 0!==c?c:a.id-b.id}var E=[],F=[],G=1,H=null,I=3,J=!1,K=!1,L=!1;function M(a){for(var b=C(F);null!==b;){if(null===b.callback)D(F);else if(b.startTime<=a)D(F),b.sortIndex=b.expirationTime,A(E,b);else break;b=C(F)}}function N(a){L=!1;M(a);if(!K)if(null!==C(E))K=!0,g=O;else{var b=C(F);null!==b&&(a=b.startTime-a,h=N,k=f+a)}} | ||
function O(a,b){K=!1;L&&(L=!1,h=null,k=-1);J=!0;var c=I;try{M(b);for(H=C(E);null!==H&&(!(H.expirationTime>b)||a&&!t());){var d=H.callback;if(null!==d){H.callback=null;I=H.priorityLevel;var e=d(H.expirationTime<=b);b=f;"function"===typeof e?H.callback=e:H===C(E)&&D(E);M(b)}else D(E);H=C(E)}if(null!==H)var u=!0;else{var v=C(F);if(null!==v){var w=v.startTime-b;h=N;k=f+w}u=!1}return u}finally{H=null,I=c,J=!1}} | ||
function P(a){switch(a){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1E4;default:return 5E3}}exports.unstable_flushAllWithoutAsserting=z;exports.unstable_flushNumberOfYields=function(a){if(p)throw Error("Already flushing work.");if(null!==g){var b=g;m=a;p=!0;try{a=!0;do a=b(!0,f);while(a&&!n);a||(g=null)}finally{m=-1,p=n=!1}}};exports.unstable_flushExpired=x;exports.unstable_clearYields=function(){if(null===l)return[];var a=l;l=null;return a}; | ||
exports.unstable_flushUntilNextPaint=function(){if(p)throw Error("Already flushing work.");if(null!==g){var a=g;r=!0;q=!1;p=!0;try{var b=!0;do b=a(!0,f);while(b&&!n);b||(g=null)}finally{p=n=r=!1}}}; | ||
exports.unstable_flushAll=function(){if(null!==l)throw Error("Log is not empty. Assert on the log of yielded values before flushing additional work.");z();if(null!==l)throw Error("While flushing work, something yielded a value. Use an assertion helper to assert on the log of yielded values, e.g. expect(Scheduler).toFlushAndYield([...])");};exports.unstable_yieldValue=function(a){null===l?l=[a]:l.push(a)};exports.unstable_advanceTime=function(a){f+=a;p||(null!==h&&k<=f&&(h(f),k=-1,h=null),x())}; | ||
exports.unstable_ImmediatePriority=1;exports.unstable_UserBlockingPriority=2;exports.unstable_NormalPriority=3;exports.unstable_IdlePriority=5;exports.unstable_LowPriority=4;exports.unstable_runWithPriority=function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=I;I=a;try{return b()}finally{I=c}};exports.unstable_next=function(a){switch(I){case 1:case 2:case 3:var b=3;break;default:b=I}var c=I;I=b;try{return a()}finally{I=c}}; | ||
exports.unstable_scheduleCallback=function(a,b,c){var d=f;if("object"===typeof c&&null!==c){var e=c.delay;e="number"===typeof e&&0<e?d+e:d;c="number"===typeof c.timeout?c.timeout:P(a)}else c=P(a),e=d;c=e+c;a={id:G++,callback:b,priorityLevel:a,startTime:e,expirationTime:c,sortIndex:-1};e>d?(a.sortIndex=e,A(F,a),null===C(E)&&a===C(F)&&(L?(h=null,k=-1):L=!0,h=N,k=f+(e-d))):(a.sortIndex=c,A(E,a),K||J||(K=!0,g=O));return a};exports.unstable_cancelCallback=function(a){a.callback=null}; | ||
exports.unstable_wrapCallback=function(a){var b=I;return function(){var c=I;I=b;try{return a.apply(this,arguments)}finally{I=c}}};exports.unstable_getCurrentPriorityLevel=function(){return I};exports.unstable_shouldYield=function(){var a=f;M(a);var b=C(E);return b!==H&&null!==H&&null!==b&&null!==b.callback&&b.startTime<=a&&b.expirationTime<H.expirationTime||t()};exports.unstable_requestPaint=function(){q=!0};exports.unstable_continueExecution=function(){K||J||(K=!0,g=O)}; | ||
exports.unstable_pauseExecution=function(){};exports.unstable_getFirstCallbackNode=function(){return C(E)};exports.unstable_now=function(){return f};exports.unstable_forceFrameRate=function(){};exports.unstable_Profiling=null; |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler.development.js | ||
@@ -22,7 +22,5 @@ * | ||
var enableIsInputPending = false; | ||
var requestIdleCallbackBeforeFirstFrame = false; | ||
var requestTimerEventBeforeFirstFrame = false; | ||
var enableMessageLoopImplementation = false; | ||
var enableMessageLoopImplementation = true; | ||
var enableProfiling = true; | ||
// The DOM Scheduler implementation is similar to requestIdleCallback. It | ||
// works by scheduling a requestAnimationFrame, storing the time for the start | ||
@@ -35,16 +33,14 @@ // of the frame, then scheduling a postMessage which gets scheduled after paint. | ||
var requestHostCallback = void 0; | ||
var requestHostCallback; | ||
var requestHostTimeout = void 0; | ||
var cancelHostTimeout = void 0; | ||
var shouldYieldToHost = void 0; | ||
var requestPaint = void 0; | ||
exports.unstable_now = void 0; | ||
exports.unstable_forceFrameRate = void 0; | ||
var requestHostTimeout; | ||
var cancelHostTimeout; | ||
var shouldYieldToHost; | ||
var requestPaint; | ||
if ( | ||
// If Scheduler runs in a non-DOM environment, it falls back to a naive | ||
if ( // If Scheduler runs in a non-DOM environment, it falls back to a naive | ||
// implementation using setTimeout. | ||
typeof window === 'undefined' || | ||
// Check if MessageChannel is supported, too. | ||
typeof window === 'undefined' || // Check if MessageChannel is supported, too. | ||
typeof MessageChannel !== 'function') { | ||
@@ -55,2 +51,3 @@ // If this accidentally gets imported in a non-browser environment, e.g. JavaScriptCore, | ||
var _timeoutID = null; | ||
var _flushCallback = function () { | ||
@@ -61,3 +58,5 @@ if (_callback !== null) { | ||
var hasRemainingTime = true; | ||
_callback(hasRemainingTime, currentTime); | ||
_callback = null; | ||
@@ -70,5 +69,9 @@ } catch (e) { | ||
}; | ||
var initialTime = Date.now(); | ||
exports.unstable_now = function () { | ||
return Date.now(); | ||
return Date.now() - initialTime; | ||
}; | ||
requestHostCallback = function (cb) { | ||
@@ -83,11 +86,15 @@ if (_callback !== null) { | ||
}; | ||
requestHostTimeout = function (cb, ms) { | ||
_timeoutID = setTimeout(cb, ms); | ||
}; | ||
cancelHostTimeout = function () { | ||
clearTimeout(_timeoutID); | ||
}; | ||
shouldYieldToHost = function () { | ||
return false; | ||
}; | ||
requestPaint = exports.unstable_forceFrameRate = function () {}; | ||
@@ -102,3 +109,2 @@ } else { | ||
var cancelAnimationFrame = window.cancelAnimationFrame; | ||
var requestIdleCallback = window.requestIdleCallback; | ||
@@ -110,2 +116,3 @@ if (typeof console !== 'undefined') { | ||
} | ||
if (typeof cancelAnimationFrame !== 'function') { | ||
@@ -116,9 +123,13 @@ console.error("This browser doesn't support cancelAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills'); | ||
var requestIdleCallbackBeforeFirstFrame$1 = requestIdleCallbackBeforeFirstFrame && typeof requestIdleCallback === 'function' && typeof cancelIdleCallback === 'function'; | ||
if (typeof performance === 'object' && typeof performance.now === 'function') { | ||
exports.unstable_now = function () { | ||
return performance.now(); | ||
}; | ||
} else { | ||
var _initialTime = _Date.now(); | ||
exports.unstable_now = typeof performance === 'object' && typeof performance.now === 'function' ? function () { | ||
return performance.now(); | ||
} : function () { | ||
return _Date.now(); | ||
}; | ||
exports.unstable_now = function () { | ||
return _Date.now() - _initialTime; | ||
}; | ||
} | ||
@@ -130,3 +141,2 @@ var isRAFLoopRunning = false; | ||
var taskTimeoutID = -1; | ||
var frameLength = enableMessageLoopImplementation ? // We won't attempt to align with the vsync. Instead we'll yield multiple | ||
@@ -140,11 +150,8 @@ // times per frame, often enough to keep it responsive even at really | ||
33.33; | ||
var prevRAFTime = -1; | ||
var prevRAFInterval = -1; | ||
var frameDeadline = 0; | ||
var fpsLocked = false; // TODO: Make this configurable | ||
// TODO: Adjust this based on priority? | ||
var fpsLocked = false; | ||
// TODO: Make this configurable | ||
// TODO: Adjust this based on priority? | ||
var maxFrameLength = 300; | ||
@@ -155,4 +162,6 @@ var needsPaint = false; | ||
var scheduling = navigator.scheduling; | ||
shouldYieldToHost = function () { | ||
var currentTime = exports.unstable_now(); | ||
if (currentTime >= frameDeadline) { | ||
@@ -170,5 +179,6 @@ // There's no time left in the frame. We may want to yield control of | ||
return true; | ||
} | ||
// There's no pending input. Only yield if we've reached the max | ||
} // There's no pending input. Only yield if we've reached the max | ||
// frame length. | ||
return currentTime >= frameDeadline + maxFrameLength; | ||
@@ -189,5 +199,5 @@ } else { | ||
return exports.unstable_now() >= frameDeadline; | ||
}; | ||
}; // Since we yield every frame regardless, `requestPaint` has no effect. | ||
// Since we yield every frame regardless, `requestPaint` has no effect. | ||
requestPaint = function () {}; | ||
@@ -201,2 +211,3 @@ } | ||
} | ||
if (fps > 0) { | ||
@@ -215,10 +226,12 @@ frameLength = Math.floor(1000 / fps); | ||
if (scheduledHostCallback !== null) { | ||
var currentTime = exports.unstable_now(); | ||
// Yield after `frameLength` ms, regardless of where we are in the vsync | ||
var currentTime = exports.unstable_now(); // Yield after `frameLength` ms, regardless of where we are in the vsync | ||
// cycle. This means there's always time remaining at the beginning of | ||
// the message event. | ||
frameDeadline = currentTime + frameLength; | ||
var hasTimeRemaining = true; | ||
try { | ||
var hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime); | ||
if (!hasMoreWork) { | ||
@@ -238,5 +251,8 @@ isMessageLoopRunning = false; | ||
} | ||
} | ||
// Yielding to the browser will give it a chance to paint, so we can | ||
} else { | ||
isMessageLoopRunning = false; | ||
} // Yielding to the browser will give it a chance to paint, so we can | ||
// reset this. | ||
needsPaint = false; | ||
@@ -246,5 +262,8 @@ } else { | ||
var _currentTime = exports.unstable_now(); | ||
var _hasTimeRemaining = frameDeadline - _currentTime > 0; | ||
try { | ||
var _hasMoreWork = scheduledHostCallback(_hasTimeRemaining, _currentTime); | ||
if (!_hasMoreWork) { | ||
@@ -260,5 +279,6 @@ scheduledHostCallback = null; | ||
} | ||
} | ||
// Yielding to the browser will give it a chance to paint, so we can | ||
} // Yielding to the browser will give it a chance to paint, so we can | ||
// reset this. | ||
needsPaint = false; | ||
@@ -279,5 +299,3 @@ } | ||
return; | ||
} | ||
// Eagerly schedule the next animation callback at the beginning of the | ||
} // Eagerly schedule the next animation callback at the beginning of the | ||
// frame. If the scheduler queue is not empty at the end of the frame, it | ||
@@ -290,11 +308,13 @@ // will continue flushing inside that callback. If the queue *is* empty, | ||
// after that. | ||
isRAFLoopRunning = true; | ||
requestAnimationFrame(function (nextRAFTime) { | ||
_clearTimeout(rAFTimeoutID); | ||
onAnimationFrame(nextRAFTime); | ||
}); | ||
// requestAnimationFrame is throttled when the tab is backgrounded. We | ||
}); // requestAnimationFrame is throttled when the tab is backgrounded. We | ||
// don't want to stop working entirely. So we'll fallback to a timeout loop. | ||
// TODO: Need a better heuristic for backgrounded work. | ||
var onTimeout = function () { | ||
@@ -305,9 +325,10 @@ frameDeadline = exports.unstable_now() + frameLength / 2; | ||
}; | ||
rAFTimeoutID = _setTimeout(onTimeout, frameLength * 3); | ||
if (prevRAFTime !== -1 && | ||
// Make sure this rAF time is different from the previous one. This check | ||
if (prevRAFTime !== -1 && // Make sure this rAF time is different from the previous one. This check | ||
// could fail if two rAFs fire in the same frame. | ||
rAFTime - prevRAFTime > 0.1) { | ||
var rAFInterval = rAFTime - prevRAFTime; | ||
if (!fpsLocked && prevRAFInterval !== -1) { | ||
@@ -325,2 +346,3 @@ // We've observed two consecutive frame intervals. We'll use this to | ||
frameLength = rAFInterval < prevRAFInterval ? prevRAFInterval : rAFInterval; | ||
if (frameLength < 8.33) { | ||
@@ -334,8 +356,9 @@ // Defensive coding. We don't support higher frame rates than 120hz. | ||
} | ||
prevRAFInterval = rAFInterval; | ||
} | ||
prevRAFTime = rAFTime; | ||
frameDeadline = rAFTime + frameLength; | ||
frameDeadline = rAFTime + frameLength; // We use the postMessage trick to defer idle work until after the repaint. | ||
// We use the postMessage trick to defer idle work until after the repaint. | ||
port.postMessage(null); | ||
@@ -346,2 +369,3 @@ }; | ||
scheduledHostCallback = callback; | ||
if (enableMessageLoopImplementation) { | ||
@@ -357,44 +381,4 @@ if (!isMessageLoopRunning) { | ||
requestAnimationFrame(function (rAFTime) { | ||
if (requestIdleCallbackBeforeFirstFrame$1) { | ||
cancelIdleCallback(idleCallbackID); | ||
} | ||
if (requestTimerEventBeforeFirstFrame) { | ||
_clearTimeout(idleTimeoutID); | ||
} | ||
onAnimationFrame(rAFTime); | ||
}); | ||
// If we just missed the last vsync, the next rAF might not happen for | ||
// another frame. To claim as much idle time as possible, post a | ||
// callback with `requestIdleCallback`, which should fire if there's | ||
// idle time left in the frame. | ||
// | ||
// This should only be an issue for the first rAF in the loop; | ||
// subsequent rAFs are scheduled at the beginning of the | ||
// preceding frame. | ||
var idleCallbackID = void 0; | ||
if (requestIdleCallbackBeforeFirstFrame$1) { | ||
idleCallbackID = requestIdleCallback(function onIdleCallbackBeforeFirstFrame() { | ||
if (requestTimerEventBeforeFirstFrame) { | ||
_clearTimeout(idleTimeoutID); | ||
} | ||
frameDeadline = exports.unstable_now() + frameLength; | ||
performWorkUntilDeadline(); | ||
}); | ||
} | ||
// Alternate strategy to address the same problem. Scheduler a timer | ||
// with no delay. If this fires before the rAF, that likely indicates | ||
// that there's idle time before the next vsync. This isn't always the | ||
// case, but we'll be aggressive and assume it is, as a trade off to | ||
// prevent idle periods. | ||
var idleTimeoutID = void 0; | ||
if (requestTimerEventBeforeFirstFrame) { | ||
idleTimeoutID = _setTimeout(function onTimerEventBeforeFirstFrame() { | ||
if (requestIdleCallbackBeforeFirstFrame$1) { | ||
cancelIdleCallback(idleCallbackID); | ||
} | ||
frameDeadline = exports.unstable_now() + frameLength; | ||
performWorkUntilDeadline(); | ||
}, 0); | ||
} | ||
} | ||
@@ -412,2 +396,3 @@ } | ||
_clearTimeout(taskTimeoutID); | ||
taskTimeoutID = -1; | ||
@@ -417,5 +402,86 @@ }; | ||
/* eslint-disable no-var */ | ||
function push(heap, node) { | ||
var index = heap.length; | ||
heap.push(node); | ||
siftUp(heap, node, index); | ||
} | ||
function peek(heap) { | ||
var first = heap[0]; | ||
return first === undefined ? null : first; | ||
} | ||
function pop(heap) { | ||
var first = heap[0]; | ||
if (first !== undefined) { | ||
var last = heap.pop(); | ||
if (last !== first) { | ||
heap[0] = last; | ||
siftDown(heap, last, 0); | ||
} | ||
return first; | ||
} else { | ||
return null; | ||
} | ||
} | ||
function siftUp(heap, node, i) { | ||
var index = i; | ||
while (true) { | ||
var parentIndex = Math.floor((index - 1) / 2); | ||
var parent = heap[parentIndex]; | ||
if (parent !== undefined && compare(parent, node) > 0) { | ||
// The parent is larger. Swap positions. | ||
heap[parentIndex] = node; | ||
heap[index] = parent; | ||
index = parentIndex; | ||
} else { | ||
// The parent is smaller. Exit. | ||
return; | ||
} | ||
} | ||
} | ||
function siftDown(heap, node, i) { | ||
var index = i; | ||
var length = heap.length; | ||
while (index < length) { | ||
var leftIndex = (index + 1) * 2 - 1; | ||
var left = heap[leftIndex]; | ||
var rightIndex = leftIndex + 1; | ||
var right = heap[rightIndex]; // If the left or right node is smaller, swap with the smaller of those. | ||
if (left !== undefined && compare(left, node) < 0) { | ||
if (right !== undefined && compare(right, left) < 0) { | ||
heap[index] = right; | ||
heap[rightIndex] = node; | ||
index = rightIndex; | ||
} else { | ||
heap[index] = left; | ||
heap[leftIndex] = node; | ||
index = leftIndex; | ||
} | ||
} else if (right !== undefined && compare(right, node) < 0) { | ||
heap[index] = right; | ||
heap[rightIndex] = node; | ||
index = rightIndex; | ||
} else { | ||
// Neither child is smaller. Exit. | ||
return; | ||
} | ||
} | ||
} | ||
function compare(a, b) { | ||
// Compare sort index first, then task id. | ||
var diff = a.sortIndex - b.sortIndex; | ||
return diff !== 0 ? diff : a.id - b.id; | ||
} | ||
// TODO: Use symbols? | ||
var NoPriority = 0; | ||
var ImmediatePriority = 1; | ||
@@ -427,161 +493,210 @@ var UserBlockingPriority = 2; | ||
// Max 31 bit integer. The max integer size in V8 for 32-bit systems. | ||
// Math.pow(2, 30) - 1 | ||
// 0b111111111111111111111111111111 | ||
var maxSigned31BitInt = 1073741823; | ||
var runIdCounter = 0; | ||
var mainThreadIdCounter = 0; | ||
var profilingStateSize = 4; | ||
var sharedProfilingBuffer = enableProfiling ? // $FlowFixMe Flow doesn't know about SharedArrayBuffer | ||
typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : // $FlowFixMe Flow doesn't know about ArrayBuffer | ||
typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9 | ||
: null; | ||
var profilingState = enableProfiling && sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : []; // We can't read this but it helps save bytes for null checks | ||
// Times out immediately | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; | ||
// Eventually times out | ||
var USER_BLOCKING_PRIORITY = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; | ||
// Never times out | ||
var IDLE_PRIORITY = maxSigned31BitInt; | ||
var PRIORITY = 0; | ||
var CURRENT_TASK_ID = 1; | ||
var CURRENT_RUN_ID = 2; | ||
var QUEUE_SIZE = 3; | ||
// Tasks are stored as a circular, doubly linked list. | ||
var firstTask = null; | ||
var firstDelayedTask = null; | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; // This is maintained with a counter, because the size of the priority queue | ||
// array might include canceled tasks. | ||
// Pausing the scheduler is useful for debugging. | ||
var isSchedulerPaused = false; | ||
profilingState[QUEUE_SIZE] = 0; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
} // Bytes per element is 4 | ||
var currentTask = null; | ||
var currentPriorityLevel = NormalPriority; | ||
// This is set while performing work, to prevent re-entrancy. | ||
var isPerformingWork = false; | ||
var INITIAL_EVENT_LOG_SIZE = 131072; | ||
var MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes | ||
var isHostCallbackScheduled = false; | ||
var isHostTimeoutScheduled = false; | ||
var eventLogSize = 0; | ||
var eventLogBuffer = null; | ||
var eventLog = null; | ||
var eventLogIndex = 0; | ||
var TaskStartEvent = 1; | ||
var TaskCompleteEvent = 2; | ||
var TaskErrorEvent = 3; | ||
var TaskCancelEvent = 4; | ||
var TaskRunEvent = 5; | ||
var TaskYieldEvent = 6; | ||
var SchedulerSuspendEvent = 7; | ||
var SchedulerResumeEvent = 8; | ||
function scheduler_flushTaskAtPriority_Immediate(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function logEvent(entries) { | ||
if (eventLog !== null) { | ||
var offset = eventLogIndex; | ||
eventLogIndex += entries.length; | ||
if (eventLogIndex + 1 > eventLogSize) { | ||
eventLogSize *= 2; | ||
if (eventLogSize > MAX_EVENT_LOG_SIZE) { | ||
console.error("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.'); | ||
stopLoggingProfilingEvents(); | ||
return; | ||
} | ||
var newEventLog = new Int32Array(eventLogSize * 4); | ||
newEventLog.set(eventLog); | ||
eventLogBuffer = newEventLog.buffer; | ||
eventLog = newEventLog; | ||
} | ||
eventLog.set(entries, offset); | ||
} | ||
} | ||
function scheduler_flushTaskAtPriority_UserBlocking(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function startLoggingProfilingEvents() { | ||
eventLogSize = INITIAL_EVENT_LOG_SIZE; | ||
eventLogBuffer = new ArrayBuffer(eventLogSize * 4); | ||
eventLog = new Int32Array(eventLogBuffer); | ||
eventLogIndex = 0; | ||
} | ||
function scheduler_flushTaskAtPriority_Normal(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function stopLoggingProfilingEvents() { | ||
var buffer = eventLogBuffer; | ||
eventLogSize = 0; | ||
eventLogBuffer = null; | ||
eventLog = null; | ||
eventLogIndex = 0; | ||
return buffer; | ||
} | ||
function scheduler_flushTaskAtPriority_Low(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function markTaskStart(task, time) { | ||
if (enableProfiling) { | ||
profilingState[QUEUE_SIZE]++; | ||
if (eventLog !== null) { | ||
logEvent([TaskStartEvent, time, task.id, task.priorityLevel]); | ||
} | ||
} | ||
} | ||
function scheduler_flushTaskAtPriority_Idle(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function markTaskCompleted(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[QUEUE_SIZE]--; | ||
if (eventLog !== null) { | ||
logEvent([TaskCompleteEvent, time, task.id]); | ||
} | ||
} | ||
} | ||
function markTaskCanceled(task, time) { | ||
if (enableProfiling) { | ||
profilingState[QUEUE_SIZE]--; | ||
function flushTask(task, currentTime) { | ||
// Remove the task from the list before calling the callback. That way the | ||
// list is in a consistent state even if the callback throws. | ||
var next = task.next; | ||
if (next === task) { | ||
// This is the only scheduled task. Clear the list. | ||
firstTask = null; | ||
} else { | ||
// Remove the task from its position in the list. | ||
if (task === firstTask) { | ||
firstTask = next; | ||
if (eventLog !== null) { | ||
logEvent([TaskCancelEvent, time, task.id]); | ||
} | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
} | ||
task.next = task.previous = null; | ||
} | ||
function markTaskErrored(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[QUEUE_SIZE]--; | ||
// Now it's safe to execute the task. | ||
var callback = task.callback; | ||
var previousPriorityLevel = currentPriorityLevel; | ||
var previousTask = currentTask; | ||
currentPriorityLevel = task.priorityLevel; | ||
currentTask = task; | ||
var continuationCallback; | ||
try { | ||
var didUserCallbackTimeout = task.expirationTime <= currentTime; | ||
// Add an extra function to the callstack. Profiling tools can use this | ||
// to infer the priority of work that appears higher in the stack. | ||
switch (currentPriorityLevel) { | ||
case ImmediatePriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Immediate(callback, didUserCallbackTimeout); | ||
break; | ||
case UserBlockingPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_UserBlocking(callback, didUserCallbackTimeout); | ||
break; | ||
case NormalPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Normal(callback, didUserCallbackTimeout); | ||
break; | ||
case LowPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Low(callback, didUserCallbackTimeout); | ||
break; | ||
case IdlePriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Idle(callback, didUserCallbackTimeout); | ||
break; | ||
if (eventLog !== null) { | ||
logEvent([TaskErrorEvent, time, task.id]); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentPriorityLevel = previousPriorityLevel; | ||
currentTask = previousTask; | ||
} | ||
} | ||
function markTaskRun(task, time) { | ||
if (enableProfiling) { | ||
runIdCounter++; | ||
profilingState[PRIORITY] = task.priorityLevel; | ||
profilingState[CURRENT_TASK_ID] = task.id; | ||
profilingState[CURRENT_RUN_ID] = runIdCounter; | ||
// A callback may return a continuation. The continuation should be scheduled | ||
// with the same priority and expiration as the just-finished callback. | ||
if (typeof continuationCallback === 'function') { | ||
var expirationTime = task.expirationTime; | ||
var continuationTask = task; | ||
continuationTask.callback = continuationCallback; | ||
if (eventLog !== null) { | ||
logEvent([TaskRunEvent, time, task.id, runIdCounter]); | ||
} | ||
} | ||
} | ||
function markTaskYield(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[CURRENT_RUN_ID] = 0; | ||
// Insert the new callback into the list, sorted by its timeout. This is | ||
// almost the same as the code in `scheduleCallback`, except the callback | ||
// is inserted into the list *before* callbacks of equal timeout instead | ||
// of after. | ||
if (firstTask === null) { | ||
// This is the first callback in the list. | ||
firstTask = continuationTask.next = continuationTask.previous = continuationTask; | ||
} else { | ||
var nextAfterContinuation = null; | ||
var t = firstTask; | ||
do { | ||
if (expirationTime <= t.expirationTime) { | ||
// This task times out at or after the continuation. We will insert | ||
// the continuation *before* this task. | ||
nextAfterContinuation = t; | ||
break; | ||
} | ||
t = t.next; | ||
} while (t !== firstTask); | ||
if (nextAfterContinuation === null) { | ||
// No equal or lower priority task was found, which means the new task | ||
// is the lowest priority task in the list. | ||
nextAfterContinuation = firstTask; | ||
} else if (nextAfterContinuation === firstTask) { | ||
// The new task is the highest priority task in the list. | ||
firstTask = continuationTask; | ||
} | ||
if (eventLog !== null) { | ||
logEvent([TaskYieldEvent, time, task.id, runIdCounter]); | ||
} | ||
} | ||
} | ||
function markSchedulerSuspended(time) { | ||
if (enableProfiling) { | ||
mainThreadIdCounter++; | ||
var _previous = nextAfterContinuation.previous; | ||
_previous.next = nextAfterContinuation.previous = continuationTask; | ||
continuationTask.next = nextAfterContinuation; | ||
continuationTask.previous = _previous; | ||
if (eventLog !== null) { | ||
logEvent([SchedulerSuspendEvent, time, mainThreadIdCounter]); | ||
} | ||
} | ||
} | ||
function markSchedulerUnsuspended(time) { | ||
if (enableProfiling) { | ||
if (eventLog !== null) { | ||
logEvent([SchedulerResumeEvent, time, mainThreadIdCounter]); | ||
} | ||
} | ||
} | ||
/* eslint-disable no-var */ | ||
// Math.pow(2, 30) - 1 | ||
// 0b111111111111111111111111111111 | ||
var maxSigned31BitInt = 1073741823; // Times out immediately | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out | ||
var USER_BLOCKING_PRIORITY = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; // Never times out | ||
var IDLE_PRIORITY = maxSigned31BitInt; // Tasks are stored on a min heap | ||
var taskQueue = []; | ||
var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. | ||
var taskIdCounter = 1; // Pausing the scheduler is useful for debugging. | ||
var isSchedulerPaused = false; | ||
var currentTask = null; | ||
var currentPriorityLevel = NormalPriority; // This is set while performing work, to prevent re-entrancy. | ||
var isPerformingWork = false; | ||
var isHostCallbackScheduled = false; | ||
var isHostTimeoutScheduled = false; | ||
function advanceTimers(currentTime) { | ||
// Check for tasks that are no longer delayed and add them to the queue. | ||
if (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime) { | ||
do { | ||
var task = firstDelayedTask; | ||
var next = task.next; | ||
if (task === next) { | ||
firstDelayedTask = null; | ||
} else { | ||
firstDelayedTask = next; | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
var timer = peek(timerQueue); | ||
while (timer !== null) { | ||
if (timer.callback === null) { | ||
// Timer was cancelled. | ||
pop(timerQueue); | ||
} else if (timer.startTime <= currentTime) { | ||
// Timer fired. Transfer to the task queue. | ||
pop(timerQueue); | ||
timer.sortIndex = timer.expirationTime; | ||
push(taskQueue, timer); | ||
if (enableProfiling) { | ||
markTaskStart(timer, currentTime); | ||
timer.isQueued = true; | ||
} | ||
task.next = task.previous = null; | ||
insertScheduledTask(task, task.expirationTime); | ||
} while (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime); | ||
} else { | ||
// Remaining timers are pending. | ||
return; | ||
} | ||
timer = peek(timerQueue); | ||
} | ||
@@ -595,7 +710,11 @@ } | ||
if (!isHostCallbackScheduled) { | ||
if (firstTask !== null) { | ||
if (peek(taskQueue) !== null) { | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
} else if (firstDelayedTask !== null) { | ||
requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime); | ||
} else { | ||
var firstTimer = peek(timerQueue); | ||
if (firstTimer !== null) { | ||
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime); | ||
} | ||
} | ||
@@ -606,9 +725,9 @@ } | ||
function flushWork(hasTimeRemaining, initialTime) { | ||
// Exit right away if we're currently paused | ||
if (enableSchedulerDebugging && isSchedulerPaused) { | ||
return; | ||
} | ||
if (enableProfiling) { | ||
markSchedulerUnsuspended(initialTime); | ||
} // We'll need a host callback the next time work is scheduled. | ||
// We'll need a host callback the next time work is scheduled. | ||
isHostCallbackScheduled = false; | ||
if (isHostTimeoutScheduled) { | ||
@@ -620,40 +739,92 @@ // We scheduled a timeout but it's no longer needed. Cancel it. | ||
var currentTime = initialTime; | ||
advanceTimers(currentTime); | ||
isPerformingWork = true; | ||
var previousPriorityLevel = currentPriorityLevel; | ||
isPerformingWork = true; | ||
try { | ||
if (!hasTimeRemaining) { | ||
// Flush all the expired callbacks without yielding. | ||
// TODO: Split flushWork into two separate functions instead of using | ||
// a boolean argument? | ||
while (firstTask !== null && firstTask.expirationTime <= currentTime && !(enableSchedulerDebugging && isSchedulerPaused)) { | ||
flushTask(firstTask, currentTime); | ||
currentTime = exports.unstable_now(); | ||
advanceTimers(currentTime); | ||
if (enableProfiling) { | ||
try { | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} catch (error) { | ||
if (currentTask !== null) { | ||
var currentTime = exports.unstable_now(); | ||
markTaskErrored(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
throw error; | ||
} | ||
} else { | ||
// Keep flushing callbacks until we run out of time in the frame. | ||
if (firstTask !== null) { | ||
do { | ||
flushTask(firstTask, currentTime); | ||
currentTime = exports.unstable_now(); | ||
advanceTimers(currentTime); | ||
} while (firstTask !== null && !shouldYieldToHost() && !(enableSchedulerDebugging && isSchedulerPaused)); | ||
} | ||
// No catch in prod codepath. | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} | ||
// Return whether there's additional work | ||
if (firstTask !== null) { | ||
return true; | ||
} else { | ||
if (firstDelayedTask !== null) { | ||
requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime); | ||
} | ||
return false; | ||
} | ||
} finally { | ||
currentTask = null; | ||
currentPriorityLevel = previousPriorityLevel; | ||
isPerformingWork = false; | ||
if (enableProfiling) { | ||
var _currentTime = exports.unstable_now(); | ||
markSchedulerSuspended(_currentTime); | ||
} | ||
} | ||
} | ||
function workLoop(hasTimeRemaining, initialTime) { | ||
var currentTime = initialTime; | ||
advanceTimers(currentTime); | ||
currentTask = peek(taskQueue); | ||
while (currentTask !== null && !(enableSchedulerDebugging && isSchedulerPaused)) { | ||
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) { | ||
// This currentTask hasn't expired, and we've reached the deadline. | ||
break; | ||
} | ||
var callback = currentTask.callback; | ||
if (callback !== null) { | ||
currentTask.callback = null; | ||
currentPriorityLevel = currentTask.priorityLevel; | ||
var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; | ||
markTaskRun(currentTask, currentTime); | ||
var continuationCallback = callback(didUserCallbackTimeout); | ||
currentTime = exports.unstable_now(); | ||
if (typeof continuationCallback === 'function') { | ||
currentTask.callback = continuationCallback; | ||
markTaskYield(currentTask, currentTime); | ||
} else { | ||
if (enableProfiling) { | ||
markTaskCompleted(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
if (currentTask === peek(taskQueue)) { | ||
pop(taskQueue); | ||
} | ||
} | ||
advanceTimers(currentTime); | ||
} else { | ||
pop(taskQueue); | ||
} | ||
currentTask = peek(taskQueue); | ||
} // Return whether there's additional work | ||
if (currentTask !== null) { | ||
return true; | ||
} else { | ||
var firstTimer = peek(timerQueue); | ||
if (firstTimer !== null) { | ||
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime); | ||
} | ||
return false; | ||
} | ||
} | ||
function unstable_runWithPriority(priorityLevel, eventHandler) { | ||
@@ -667,2 +838,3 @@ switch (priorityLevel) { | ||
break; | ||
default: | ||
@@ -684,2 +856,3 @@ priorityLevel = NormalPriority; | ||
var priorityLevel; | ||
switch (currentPriorityLevel) { | ||
@@ -692,2 +865,3 @@ case ImmediatePriority: | ||
break; | ||
default: | ||
@@ -728,8 +902,12 @@ // Anything lower than normal priority should remain at the current level. | ||
return IMMEDIATE_PRIORITY_TIMEOUT; | ||
case UserBlockingPriority: | ||
return USER_BLOCKING_PRIORITY; | ||
case IdlePriority: | ||
return IDLE_PRIORITY; | ||
case LowPriority: | ||
return LOW_PRIORITY_TIMEOUT; | ||
case NormalPriority: | ||
@@ -743,7 +921,8 @@ default: | ||
var currentTime = exports.unstable_now(); | ||
var startTime; | ||
var timeout; | ||
if (typeof options === 'object' && options !== null) { | ||
var delay = options.delay; | ||
if (typeof delay === 'number' && delay > 0) { | ||
@@ -754,2 +933,3 @@ startTime = currentTime + delay; | ||
} | ||
timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel); | ||
@@ -762,4 +942,4 @@ } else { | ||
var expirationTime = startTime + timeout; | ||
var newTask = { | ||
id: taskIdCounter++, | ||
callback: callback, | ||
@@ -769,10 +949,15 @@ priorityLevel: priorityLevel, | ||
expirationTime: expirationTime, | ||
next: null, | ||
previous: null | ||
sortIndex: -1 | ||
}; | ||
if (enableProfiling) { | ||
newTask.isQueued = false; | ||
} | ||
if (startTime > currentTime) { | ||
// This is a delayed task. | ||
insertDelayedTask(newTask, startTime); | ||
if (firstTask === null && firstDelayedTask === newTask) { | ||
newTask.sortIndex = startTime; | ||
push(timerQueue, newTask); | ||
if (peek(taskQueue) === null && newTask === peek(timerQueue)) { | ||
// All tasks are delayed, and this is the task with the earliest delay. | ||
@@ -784,10 +969,18 @@ if (isHostTimeoutScheduled) { | ||
isHostTimeoutScheduled = true; | ||
} | ||
// Schedule a timeout. | ||
} // Schedule a timeout. | ||
requestHostTimeout(handleTimeout, startTime - currentTime); | ||
} | ||
} else { | ||
insertScheduledTask(newTask, expirationTime); | ||
// Schedule a host callback, if needed. If we're already performing work, | ||
newTask.sortIndex = expirationTime; | ||
push(taskQueue, newTask); | ||
if (enableProfiling) { | ||
markTaskStart(newTask, currentTime); | ||
newTask.isQueued = true; | ||
} // Schedule a host callback, if needed. If we're already performing work, | ||
// wait until the next time we yield. | ||
if (!isHostCallbackScheduled && !isPerformingWork) { | ||
@@ -802,70 +995,2 @@ isHostCallbackScheduled = true; | ||
function insertScheduledTask(newTask, expirationTime) { | ||
// Insert the new task into the list, ordered first by its timeout, then by | ||
// insertion. So the new task is inserted after any other task the | ||
// same timeout | ||
if (firstTask === null) { | ||
// This is the first task in the list. | ||
firstTask = newTask.next = newTask.previous = newTask; | ||
} else { | ||
var next = null; | ||
var task = firstTask; | ||
do { | ||
if (expirationTime < task.expirationTime) { | ||
// The new task times out before this one. | ||
next = task; | ||
break; | ||
} | ||
task = task.next; | ||
} while (task !== firstTask); | ||
if (next === null) { | ||
// No task with a later timeout was found, which means the new task has | ||
// the latest timeout in the list. | ||
next = firstTask; | ||
} else if (next === firstTask) { | ||
// The new task has the earliest expiration in the entire list. | ||
firstTask = newTask; | ||
} | ||
var previous = next.previous; | ||
previous.next = next.previous = newTask; | ||
newTask.next = next; | ||
newTask.previous = previous; | ||
} | ||
} | ||
function insertDelayedTask(newTask, startTime) { | ||
// Insert the new task into the list, ordered by its start time. | ||
if (firstDelayedTask === null) { | ||
// This is the first task in the list. | ||
firstDelayedTask = newTask.next = newTask.previous = newTask; | ||
} else { | ||
var next = null; | ||
var task = firstDelayedTask; | ||
do { | ||
if (startTime < task.startTime) { | ||
// The new task times out before this one. | ||
next = task; | ||
break; | ||
} | ||
task = task.next; | ||
} while (task !== firstDelayedTask); | ||
if (next === null) { | ||
// No task with a later timeout was found, which means the new task has | ||
// the latest timeout in the list. | ||
next = firstDelayedTask; | ||
} else if (next === firstDelayedTask) { | ||
// The new task has the earliest expiration in the entire list. | ||
firstDelayedTask = newTask; | ||
} | ||
var previous = next.previous; | ||
previous.next = next.previous = newTask; | ||
newTask.next = next; | ||
newTask.previous = previous; | ||
} | ||
} | ||
function unstable_pauseExecution() { | ||
@@ -877,2 +1002,3 @@ isSchedulerPaused = true; | ||
isSchedulerPaused = false; | ||
if (!isHostCallbackScheduled && !isPerformingWork) { | ||
@@ -885,30 +1011,18 @@ isHostCallbackScheduled = true; | ||
function unstable_getFirstCallbackNode() { | ||
return firstTask; | ||
return peek(taskQueue); | ||
} | ||
function unstable_cancelCallback(task) { | ||
var next = task.next; | ||
if (next === null) { | ||
// Already cancelled. | ||
return; | ||
} | ||
if (task === next) { | ||
if (task === firstTask) { | ||
firstTask = null; | ||
} else if (task === firstDelayedTask) { | ||
firstDelayedTask = null; | ||
if (enableProfiling) { | ||
if (task.isQueued) { | ||
var currentTime = exports.unstable_now(); | ||
markTaskCanceled(task, currentTime); | ||
task.isQueued = false; | ||
} | ||
} else { | ||
if (task === firstTask) { | ||
firstTask = next; | ||
} else if (task === firstDelayedTask) { | ||
firstDelayedTask = next; | ||
} | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
} | ||
} // Null out the callback to indicate the task has been canceled. (Can't | ||
// remove from the queue because you can't remove arbitrary nodes from an | ||
// array based heap, only the first one.) | ||
task.next = task.previous = null; | ||
task.callback = null; | ||
} | ||
@@ -923,6 +1037,12 @@ | ||
advanceTimers(currentTime); | ||
return currentTask !== null && firstTask !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); | ||
var firstTask = peek(taskQueue); | ||
return firstTask !== currentTask && currentTask !== null && firstTask !== null && firstTask.callback !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); | ||
} | ||
var unstable_requestPaint = requestPaint; | ||
var unstable_Profiling = enableProfiling ? { | ||
startLoggingProfilingEvents: startLoggingProfilingEvents, | ||
stopLoggingProfilingEvents: stopLoggingProfilingEvents, | ||
sharedProfilingBuffer: sharedProfilingBuffer | ||
} : null; | ||
@@ -945,3 +1065,4 @@ exports.unstable_ImmediatePriority = ImmediatePriority; | ||
exports.unstable_getFirstCallbackNode = unstable_getFirstCallbackNode; | ||
exports.unstable_Profiling = unstable_Profiling; | ||
})(); | ||
} |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler.production.min.js | ||
@@ -10,15 +10,14 @@ * | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var d=void 0,e=void 0,g=void 0,m=void 0,n=void 0;exports.unstable_now=void 0;exports.unstable_forceFrameRate=void 0; | ||
if("undefined"===typeof window||"function"!==typeof MessageChannel){var p=null,q=null,r=function(){if(null!==p)try{var a=exports.unstable_now();p(!0,a);p=null}catch(b){throw setTimeout(r,0),b;}};exports.unstable_now=function(){return Date.now()};d=function(a){null!==p?setTimeout(d,0,a):(p=a,setTimeout(r,0))};e=function(a,b){q=setTimeout(a,b)};g=function(){clearTimeout(q)};m=function(){return!1};n=exports.unstable_forceFrameRate=function(){}}else{var t=window.performance,u=window.Date,v=window.setTimeout, | ||
w=window.clearTimeout,x=window.requestAnimationFrame,y=window.cancelAnimationFrame;"undefined"!==typeof console&&("function"!==typeof x&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"),"function"!==typeof y&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"));exports.unstable_now="object"===typeof t&& | ||
"function"===typeof t.now?function(){return t.now()}:function(){return u.now()};var z=!1,A=null,B=-1,C=-1,D=33.33,E=-1,F=-1,G=0,H=!1;m=function(){return exports.unstable_now()>=G};n=function(){};exports.unstable_forceFrameRate=function(a){0>a||125<a?console.error("forceFrameRate takes a positive int between 0 and 125, forcing framerates higher than 125 fps is not unsupported"):0<a?(D=Math.floor(1E3/a),H=!0):(D=33.33,H=!1)};var J=function(){if(null!==A){var a=exports.unstable_now(),b=0<G-a;try{A(b, | ||
a)||(A=null)}catch(c){throw I.postMessage(null),c;}}},K=new MessageChannel,I=K.port2;K.port1.onmessage=J;var L=function(a){if(null===A)F=E=-1,z=!1;else{z=!0;x(function(a){w(B);L(a)});var b=function(){G=exports.unstable_now()+D/2;J();B=v(b,3*D)};B=v(b,3*D);if(-1!==E&&.1<a-E){var c=a-E;!H&&-1!==F&&c<D&&F<D&&(D=c<F?F:c,8.33>D&&(D=8.33));F=c}E=a;G=a+D;I.postMessage(null)}};d=function(a){A=a;z||(z=!0,x(function(a){L(a)}))};e=function(a,b){C=v(function(){a(exports.unstable_now())},b)};g=function(){w(C); | ||
C=-1}}var M=null,N=null,O=null,P=3,Q=!1,R=!1,S=!1; | ||
function T(a,b){var c=a.next;if(c===a)M=null;else{a===M&&(M=c);var f=a.previous;f.next=c;c.previous=f}a.next=a.previous=null;c=a.callback;f=P;var l=O;P=a.priorityLevel;O=a;try{var h=a.expirationTime<=b;switch(P){case 1:var k=c(h);break;case 2:k=c(h);break;case 3:k=c(h);break;case 4:k=c(h);break;case 5:k=c(h)}}catch(Z){throw Z;}finally{P=f,O=l}if("function"===typeof k)if(b=a.expirationTime,a.callback=k,null===M)M=a.next=a.previous=a;else{k=null;h=M;do{if(b<=h.expirationTime){k=h;break}h=h.next}while(h!== | ||
M);null===k?k=M:k===M&&(M=a);b=k.previous;b.next=k.previous=a;a.next=k;a.previous=b}}function U(a){if(null!==N&&N.startTime<=a){do{var b=N,c=b.next;if(b===c)N=null;else{N=c;var f=b.previous;f.next=c;c.previous=f}b.next=b.previous=null;V(b,b.expirationTime)}while(null!==N&&N.startTime<=a)}}function W(a){S=!1;U(a);R||(null!==M?(R=!0,d(X)):null!==N&&e(W,N.startTime-a))} | ||
function X(a,b){R=!1;S&&(S=!1,g());U(b);Q=!0;try{if(!a)for(;null!==M&&M.expirationTime<=b;)T(M,b),b=exports.unstable_now(),U(b);else if(null!==M){do T(M,b),b=exports.unstable_now(),U(b);while(null!==M&&!m())}if(null!==M)return!0;null!==N&&e(W,N.startTime-b);return!1}finally{Q=!1}}function Y(a){switch(a){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1E4;default:return 5E3}} | ||
function V(a,b){if(null===M)M=a.next=a.previous=a;else{var c=null,f=M;do{if(b<f.expirationTime){c=f;break}f=f.next}while(f!==M);null===c?c=M:c===M&&(M=a);b=c.previous;b.next=c.previous=a;a.next=c;a.previous=b}}var aa=n;exports.unstable_ImmediatePriority=1;exports.unstable_UserBlockingPriority=2;exports.unstable_NormalPriority=3;exports.unstable_IdlePriority=5;exports.unstable_LowPriority=4; | ||
exports.unstable_runWithPriority=function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=P;P=a;try{return b()}finally{P=c}};exports.unstable_next=function(a){switch(P){case 1:case 2:case 3:var b=3;break;default:b=P}var c=P;P=b;try{return a()}finally{P=c}}; | ||
exports.unstable_scheduleCallback=function(a,b,c){var f=exports.unstable_now();if("object"===typeof c&&null!==c){var l=c.delay;l="number"===typeof l&&0<l?f+l:f;c="number"===typeof c.timeout?c.timeout:Y(a)}else c=Y(a),l=f;c=l+c;a={callback:b,priorityLevel:a,startTime:l,expirationTime:c,next:null,previous:null};if(l>f){c=l;if(null===N)N=a.next=a.previous=a;else{b=null;var h=N;do{if(c<h.startTime){b=h;break}h=h.next}while(h!==N);null===b?b=N:b===N&&(N=a);c=b.previous;c.next=b.previous=a;a.next=b;a.previous= | ||
c}null===M&&N===a&&(S?g():S=!0,e(W,l-f))}else V(a,c),R||Q||(R=!0,d(X));return a};exports.unstable_cancelCallback=function(a){var b=a.next;if(null!==b){if(a===b)a===M?M=null:a===N&&(N=null);else{a===M?M=b:a===N&&(N=b);var c=a.previous;c.next=b;b.previous=c}a.next=a.previous=null}};exports.unstable_wrapCallback=function(a){var b=P;return function(){var c=P;P=b;try{return a.apply(this,arguments)}finally{P=c}}};exports.unstable_getCurrentPriorityLevel=function(){return P}; | ||
exports.unstable_shouldYield=function(){var a=exports.unstable_now();U(a);return null!==O&&null!==M&&M.startTime<=a&&M.expirationTime<O.expirationTime||m()};exports.unstable_requestPaint=aa;exports.unstable_continueExecution=function(){R||Q||(R=!0,d(X))};exports.unstable_pauseExecution=function(){};exports.unstable_getFirstCallbackNode=function(){return M}; | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var f,g,h,k,l; | ||
if("undefined"===typeof window||"function"!==typeof MessageChannel){var p=null,q=null,t=function(){if(null!==p)try{var a=exports.unstable_now();p(!0,a);p=null}catch(b){throw setTimeout(t,0),b;}},u=Date.now();exports.unstable_now=function(){return Date.now()-u};f=function(a){null!==p?setTimeout(f,0,a):(p=a,setTimeout(t,0))};g=function(a,b){q=setTimeout(a,b)};h=function(){clearTimeout(q)};k=function(){return!1};l=exports.unstable_forceFrameRate=function(){}}else{var w=window.performance,x=window.Date, | ||
y=window.setTimeout,z=window.clearTimeout,A=window.requestAnimationFrame,B=window.cancelAnimationFrame;"undefined"!==typeof console&&("function"!==typeof A&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"),"function"!==typeof B&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"));if("object"===typeof w&& | ||
"function"===typeof w.now)exports.unstable_now=function(){return w.now()};else{var C=x.now();exports.unstable_now=function(){return x.now()-C}}var D=!1,E=null,F=-1,G=5,H=0;k=function(){return exports.unstable_now()>=H};l=function(){};exports.unstable_forceFrameRate=function(a){0>a||125<a?console.error("forceFrameRate takes a positive int between 0 and 125, forcing framerates higher than 125 fps is not unsupported"):G=0<a?Math.floor(1E3/a):33.33};var I=new MessageChannel,J=I.port2;I.port1.onmessage= | ||
function(){if(null!==E){var a=exports.unstable_now();H=a+G;try{E(!0,a)?J.postMessage(null):(D=!1,E=null)}catch(b){throw J.postMessage(null),b;}}else D=!1};f=function(a){E=a;D||(D=!0,J.postMessage(null))};g=function(a,b){F=y(function(){a(exports.unstable_now())},b)};h=function(){z(F);F=-1}}function K(a,b){var c=a.length;a.push(b);a:for(;;){var d=Math.floor((c-1)/2),e=a[d];if(void 0!==e&&0<L(e,b))a[d]=b,a[c]=e,c=d;else break a}}function M(a){a=a[0];return void 0===a?null:a} | ||
function N(a){var b=a[0];if(void 0!==b){var c=a.pop();if(c!==b){a[0]=c;a:for(var d=0,e=a.length;d<e;){var m=2*(d+1)-1,n=a[m],v=m+1,r=a[v];if(void 0!==n&&0>L(n,c))void 0!==r&&0>L(r,n)?(a[d]=r,a[v]=c,d=v):(a[d]=n,a[m]=c,d=m);else if(void 0!==r&&0>L(r,c))a[d]=r,a[v]=c,d=v;else break a}}return b}return null}function L(a,b){var c=a.sortIndex-b.sortIndex;return 0!==c?c:a.id-b.id}var O=[],P=[],Q=1,R=null,S=3,T=!1,U=!1,V=!1; | ||
function W(a){for(var b=M(P);null!==b;){if(null===b.callback)N(P);else if(b.startTime<=a)N(P),b.sortIndex=b.expirationTime,K(O,b);else break;b=M(P)}}function X(a){V=!1;W(a);if(!U)if(null!==M(O))U=!0,f(Y);else{var b=M(P);null!==b&&g(X,b.startTime-a)}} | ||
function Y(a,b){U=!1;V&&(V=!1,h());T=!0;var c=S;try{W(b);for(R=M(O);null!==R&&(!(R.expirationTime>b)||a&&!k());){var d=R.callback;if(null!==d){R.callback=null;S=R.priorityLevel;var e=d(R.expirationTime<=b);b=exports.unstable_now();"function"===typeof e?R.callback=e:R===M(O)&&N(O);W(b)}else N(O);R=M(O)}if(null!==R)var m=!0;else{var n=M(P);null!==n&&g(X,n.startTime-b);m=!1}return m}finally{R=null,S=c,T=!1}} | ||
function Z(a){switch(a){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1E4;default:return 5E3}}var aa=l;exports.unstable_ImmediatePriority=1;exports.unstable_UserBlockingPriority=2;exports.unstable_NormalPriority=3;exports.unstable_IdlePriority=5;exports.unstable_LowPriority=4;exports.unstable_runWithPriority=function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=S;S=a;try{return b()}finally{S=c}}; | ||
exports.unstable_next=function(a){switch(S){case 1:case 2:case 3:var b=3;break;default:b=S}var c=S;S=b;try{return a()}finally{S=c}}; | ||
exports.unstable_scheduleCallback=function(a,b,c){var d=exports.unstable_now();if("object"===typeof c&&null!==c){var e=c.delay;e="number"===typeof e&&0<e?d+e:d;c="number"===typeof c.timeout?c.timeout:Z(a)}else c=Z(a),e=d;c=e+c;a={id:Q++,callback:b,priorityLevel:a,startTime:e,expirationTime:c,sortIndex:-1};e>d?(a.sortIndex=e,K(P,a),null===M(O)&&a===M(P)&&(V?h():V=!0,g(X,e-d))):(a.sortIndex=c,K(O,a),U||T||(U=!0,f(Y)));return a};exports.unstable_cancelCallback=function(a){a.callback=null}; | ||
exports.unstable_wrapCallback=function(a){var b=S;return function(){var c=S;S=b;try{return a.apply(this,arguments)}finally{S=c}}};exports.unstable_getCurrentPriorityLevel=function(){return S};exports.unstable_shouldYield=function(){var a=exports.unstable_now();W(a);var b=M(O);return b!==R&&null!==R&&null!==b&&null!==b.callback&&b.startTime<=a&&b.expirationTime<R.expirationTime||k()};exports.unstable_requestPaint=aa;exports.unstable_continueExecution=function(){U||T||(U=!0,f(Y))}; | ||
exports.unstable_pauseExecution=function(){};exports.unstable_getFirstCallbackNode=function(){return M(O)};exports.unstable_Profiling=null; |
{ | ||
"name": "scheduler", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "Cooperative scheduler for the browser environment.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-unstable_mock.development.js | ||
@@ -20,2 +20,5 @@ * | ||
var enableProfiling = true; | ||
var currentTime = 0; | ||
@@ -31,3 +34,2 @@ var scheduledCallback = null; | ||
var shouldYieldForPaint = false; | ||
function requestHostCallback(callback) { | ||
@@ -37,4 +39,2 @@ scheduledCallback = callback; | ||
function requestHostTimeout(callback, ms) { | ||
@@ -44,3 +44,2 @@ scheduledTimeout = callback; | ||
} | ||
function cancelHostTimeout() { | ||
@@ -50,3 +49,2 @@ scheduledTimeout = null; | ||
} | ||
function shouldYieldToHost() { | ||
@@ -58,16 +56,12 @@ if (expectedNumberOfYields !== -1 && yieldedValues !== null && yieldedValues.length >= expectedNumberOfYields || shouldYieldForPaint && needsPaint) { | ||
} | ||
return false; | ||
} | ||
function getCurrentTime() { | ||
return currentTime; | ||
} | ||
function forceFrameRate() { | ||
// No-op | ||
function forceFrameRate() {// No-op | ||
} | ||
// Should only be used via an assertion helper that inspects the yielded values. | ||
// Should only be used via an assertion helper that inspects the yielded values. | ||
function unstable_flushNumberOfYields(count) { | ||
@@ -77,2 +71,3 @@ if (isFlushing) { | ||
} | ||
if (scheduledCallback !== null) { | ||
@@ -82,7 +77,10 @@ var cb = scheduledCallback; | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = true; | ||
do { | ||
hasMoreWork = cb(true, currentTime); | ||
} while (hasMoreWork && !didStop); | ||
if (!hasMoreWork) { | ||
@@ -98,3 +96,2 @@ scheduledCallback = null; | ||
} | ||
function unstable_flushUntilNextPaint() { | ||
@@ -104,2 +101,3 @@ if (isFlushing) { | ||
} | ||
if (scheduledCallback !== null) { | ||
@@ -110,7 +108,10 @@ var cb = scheduledCallback; | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = true; | ||
do { | ||
hasMoreWork = cb(true, currentTime); | ||
} while (hasMoreWork && !didStop); | ||
if (!hasMoreWork) { | ||
@@ -126,3 +127,2 @@ scheduledCallback = null; | ||
} | ||
function unstable_flushExpired() { | ||
@@ -132,6 +132,9 @@ if (isFlushing) { | ||
} | ||
if (scheduledCallback !== null) { | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = scheduledCallback(false, currentTime); | ||
if (!hasMoreWork) { | ||
@@ -145,3 +148,2 @@ scheduledCallback = null; | ||
} | ||
function unstable_flushAllWithoutAsserting() { | ||
@@ -152,13 +154,18 @@ // Returns false if no work was flushed. | ||
} | ||
if (scheduledCallback !== null) { | ||
var cb = scheduledCallback; | ||
isFlushing = true; | ||
try { | ||
var hasMoreWork = true; | ||
do { | ||
hasMoreWork = cb(true, currentTime); | ||
} while (hasMoreWork); | ||
if (!hasMoreWork) { | ||
scheduledCallback = null; | ||
} | ||
return true; | ||
@@ -172,3 +179,2 @@ } finally { | ||
} | ||
function unstable_clearYields() { | ||
@@ -178,2 +184,3 @@ if (yieldedValues === null) { | ||
} | ||
var values = yieldedValues; | ||
@@ -183,3 +190,2 @@ yieldedValues = null; | ||
} | ||
function unstable_flushAll() { | ||
@@ -189,3 +195,5 @@ if (yieldedValues !== null) { | ||
} | ||
unstable_flushAllWithoutAsserting(); | ||
if (yieldedValues !== null) { | ||
@@ -195,3 +203,2 @@ throw new Error('While flushing work, something yielded a value. Use an ' + 'assertion helper to assert on the log of yielded values, e.g. ' + 'expect(Scheduler).toFlushAndYield([...])'); | ||
} | ||
function unstable_yieldValue(value) { | ||
@@ -204,5 +211,5 @@ if (yieldedValues === null) { | ||
} | ||
function unstable_advanceTime(ms) { | ||
currentTime += ms; | ||
if (!isFlushing) { | ||
@@ -214,6 +221,6 @@ if (scheduledTimeout !== null && timeoutTime <= currentTime) { | ||
} | ||
unstable_flushExpired(); | ||
} | ||
} | ||
function requestPaint() { | ||
@@ -223,5 +230,86 @@ needsPaint = true; | ||
/* eslint-disable no-var */ | ||
function push(heap, node) { | ||
var index = heap.length; | ||
heap.push(node); | ||
siftUp(heap, node, index); | ||
} | ||
function peek(heap) { | ||
var first = heap[0]; | ||
return first === undefined ? null : first; | ||
} | ||
function pop(heap) { | ||
var first = heap[0]; | ||
if (first !== undefined) { | ||
var last = heap.pop(); | ||
if (last !== first) { | ||
heap[0] = last; | ||
siftDown(heap, last, 0); | ||
} | ||
return first; | ||
} else { | ||
return null; | ||
} | ||
} | ||
function siftUp(heap, node, i) { | ||
var index = i; | ||
while (true) { | ||
var parentIndex = Math.floor((index - 1) / 2); | ||
var parent = heap[parentIndex]; | ||
if (parent !== undefined && compare(parent, node) > 0) { | ||
// The parent is larger. Swap positions. | ||
heap[parentIndex] = node; | ||
heap[index] = parent; | ||
index = parentIndex; | ||
} else { | ||
// The parent is smaller. Exit. | ||
return; | ||
} | ||
} | ||
} | ||
function siftDown(heap, node, i) { | ||
var index = i; | ||
var length = heap.length; | ||
while (index < length) { | ||
var leftIndex = (index + 1) * 2 - 1; | ||
var left = heap[leftIndex]; | ||
var rightIndex = leftIndex + 1; | ||
var right = heap[rightIndex]; // If the left or right node is smaller, swap with the smaller of those. | ||
if (left !== undefined && compare(left, node) < 0) { | ||
if (right !== undefined && compare(right, left) < 0) { | ||
heap[index] = right; | ||
heap[rightIndex] = node; | ||
index = rightIndex; | ||
} else { | ||
heap[index] = left; | ||
heap[leftIndex] = node; | ||
index = leftIndex; | ||
} | ||
} else if (right !== undefined && compare(right, node) < 0) { | ||
heap[index] = right; | ||
heap[rightIndex] = node; | ||
index = rightIndex; | ||
} else { | ||
// Neither child is smaller. Exit. | ||
return; | ||
} | ||
} | ||
} | ||
function compare(a, b) { | ||
// Compare sort index first, then task id. | ||
var diff = a.sortIndex - b.sortIndex; | ||
return diff !== 0 ? diff : a.id - b.id; | ||
} | ||
// TODO: Use symbols? | ||
var NoPriority = 0; | ||
var ImmediatePriority = 1; | ||
@@ -233,161 +321,210 @@ var UserBlockingPriority = 2; | ||
// Max 31 bit integer. The max integer size in V8 for 32-bit systems. | ||
// Math.pow(2, 30) - 1 | ||
// 0b111111111111111111111111111111 | ||
var maxSigned31BitInt = 1073741823; | ||
var runIdCounter = 0; | ||
var mainThreadIdCounter = 0; | ||
var profilingStateSize = 4; | ||
var sharedProfilingBuffer = enableProfiling ? // $FlowFixMe Flow doesn't know about SharedArrayBuffer | ||
typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : // $FlowFixMe Flow doesn't know about ArrayBuffer | ||
typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9 | ||
: null; | ||
var profilingState = enableProfiling && sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : []; // We can't read this but it helps save bytes for null checks | ||
// Times out immediately | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; | ||
// Eventually times out | ||
var USER_BLOCKING_PRIORITY = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; | ||
// Never times out | ||
var IDLE_PRIORITY = maxSigned31BitInt; | ||
var PRIORITY = 0; | ||
var CURRENT_TASK_ID = 1; | ||
var CURRENT_RUN_ID = 2; | ||
var QUEUE_SIZE = 3; | ||
// Tasks are stored as a circular, doubly linked list. | ||
var firstTask = null; | ||
var firstDelayedTask = null; | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; // This is maintained with a counter, because the size of the priority queue | ||
// array might include canceled tasks. | ||
// Pausing the scheduler is useful for debugging. | ||
var isSchedulerPaused = false; | ||
profilingState[QUEUE_SIZE] = 0; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
} // Bytes per element is 4 | ||
var currentTask = null; | ||
var currentPriorityLevel = NormalPriority; | ||
// This is set while performing work, to prevent re-entrancy. | ||
var isPerformingWork = false; | ||
var INITIAL_EVENT_LOG_SIZE = 131072; | ||
var MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes | ||
var isHostCallbackScheduled = false; | ||
var isHostTimeoutScheduled = false; | ||
var eventLogSize = 0; | ||
var eventLogBuffer = null; | ||
var eventLog = null; | ||
var eventLogIndex = 0; | ||
var TaskStartEvent = 1; | ||
var TaskCompleteEvent = 2; | ||
var TaskErrorEvent = 3; | ||
var TaskCancelEvent = 4; | ||
var TaskRunEvent = 5; | ||
var TaskYieldEvent = 6; | ||
var SchedulerSuspendEvent = 7; | ||
var SchedulerResumeEvent = 8; | ||
function scheduler_flushTaskAtPriority_Immediate(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function logEvent(entries) { | ||
if (eventLog !== null) { | ||
var offset = eventLogIndex; | ||
eventLogIndex += entries.length; | ||
if (eventLogIndex + 1 > eventLogSize) { | ||
eventLogSize *= 2; | ||
if (eventLogSize > MAX_EVENT_LOG_SIZE) { | ||
console.error("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.'); | ||
stopLoggingProfilingEvents(); | ||
return; | ||
} | ||
var newEventLog = new Int32Array(eventLogSize * 4); | ||
newEventLog.set(eventLog); | ||
eventLogBuffer = newEventLog.buffer; | ||
eventLog = newEventLog; | ||
} | ||
eventLog.set(entries, offset); | ||
} | ||
} | ||
function scheduler_flushTaskAtPriority_UserBlocking(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function startLoggingProfilingEvents() { | ||
eventLogSize = INITIAL_EVENT_LOG_SIZE; | ||
eventLogBuffer = new ArrayBuffer(eventLogSize * 4); | ||
eventLog = new Int32Array(eventLogBuffer); | ||
eventLogIndex = 0; | ||
} | ||
function scheduler_flushTaskAtPriority_Normal(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function stopLoggingProfilingEvents() { | ||
var buffer = eventLogBuffer; | ||
eventLogSize = 0; | ||
eventLogBuffer = null; | ||
eventLog = null; | ||
eventLogIndex = 0; | ||
return buffer; | ||
} | ||
function scheduler_flushTaskAtPriority_Low(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function markTaskStart(task, time) { | ||
if (enableProfiling) { | ||
profilingState[QUEUE_SIZE]++; | ||
if (eventLog !== null) { | ||
logEvent([TaskStartEvent, time, task.id, task.priorityLevel]); | ||
} | ||
} | ||
} | ||
function scheduler_flushTaskAtPriority_Idle(callback, didTimeout) { | ||
return callback(didTimeout); | ||
function markTaskCompleted(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[QUEUE_SIZE]--; | ||
if (eventLog !== null) { | ||
logEvent([TaskCompleteEvent, time, task.id]); | ||
} | ||
} | ||
} | ||
function markTaskCanceled(task, time) { | ||
if (enableProfiling) { | ||
profilingState[QUEUE_SIZE]--; | ||
function flushTask(task, currentTime) { | ||
// Remove the task from the list before calling the callback. That way the | ||
// list is in a consistent state even if the callback throws. | ||
var next = task.next; | ||
if (next === task) { | ||
// This is the only scheduled task. Clear the list. | ||
firstTask = null; | ||
} else { | ||
// Remove the task from its position in the list. | ||
if (task === firstTask) { | ||
firstTask = next; | ||
if (eventLog !== null) { | ||
logEvent([TaskCancelEvent, time, task.id]); | ||
} | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
} | ||
task.next = task.previous = null; | ||
} | ||
function markTaskErrored(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[QUEUE_SIZE]--; | ||
// Now it's safe to execute the task. | ||
var callback = task.callback; | ||
var previousPriorityLevel = currentPriorityLevel; | ||
var previousTask = currentTask; | ||
currentPriorityLevel = task.priorityLevel; | ||
currentTask = task; | ||
var continuationCallback; | ||
try { | ||
var didUserCallbackTimeout = task.expirationTime <= currentTime; | ||
// Add an extra function to the callstack. Profiling tools can use this | ||
// to infer the priority of work that appears higher in the stack. | ||
switch (currentPriorityLevel) { | ||
case ImmediatePriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Immediate(callback, didUserCallbackTimeout); | ||
break; | ||
case UserBlockingPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_UserBlocking(callback, didUserCallbackTimeout); | ||
break; | ||
case NormalPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Normal(callback, didUserCallbackTimeout); | ||
break; | ||
case LowPriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Low(callback, didUserCallbackTimeout); | ||
break; | ||
case IdlePriority: | ||
continuationCallback = scheduler_flushTaskAtPriority_Idle(callback, didUserCallbackTimeout); | ||
break; | ||
if (eventLog !== null) { | ||
logEvent([TaskErrorEvent, time, task.id]); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentPriorityLevel = previousPriorityLevel; | ||
currentTask = previousTask; | ||
} | ||
} | ||
function markTaskRun(task, time) { | ||
if (enableProfiling) { | ||
runIdCounter++; | ||
profilingState[PRIORITY] = task.priorityLevel; | ||
profilingState[CURRENT_TASK_ID] = task.id; | ||
profilingState[CURRENT_RUN_ID] = runIdCounter; | ||
// A callback may return a continuation. The continuation should be scheduled | ||
// with the same priority and expiration as the just-finished callback. | ||
if (typeof continuationCallback === 'function') { | ||
var expirationTime = task.expirationTime; | ||
var continuationTask = task; | ||
continuationTask.callback = continuationCallback; | ||
if (eventLog !== null) { | ||
logEvent([TaskRunEvent, time, task.id, runIdCounter]); | ||
} | ||
} | ||
} | ||
function markTaskYield(task, time) { | ||
if (enableProfiling) { | ||
profilingState[PRIORITY] = NoPriority; | ||
profilingState[CURRENT_TASK_ID] = 0; | ||
profilingState[CURRENT_RUN_ID] = 0; | ||
// Insert the new callback into the list, sorted by its timeout. This is | ||
// almost the same as the code in `scheduleCallback`, except the callback | ||
// is inserted into the list *before* callbacks of equal timeout instead | ||
// of after. | ||
if (firstTask === null) { | ||
// This is the first callback in the list. | ||
firstTask = continuationTask.next = continuationTask.previous = continuationTask; | ||
} else { | ||
var nextAfterContinuation = null; | ||
var t = firstTask; | ||
do { | ||
if (expirationTime <= t.expirationTime) { | ||
// This task times out at or after the continuation. We will insert | ||
// the continuation *before* this task. | ||
nextAfterContinuation = t; | ||
break; | ||
} | ||
t = t.next; | ||
} while (t !== firstTask); | ||
if (nextAfterContinuation === null) { | ||
// No equal or lower priority task was found, which means the new task | ||
// is the lowest priority task in the list. | ||
nextAfterContinuation = firstTask; | ||
} else if (nextAfterContinuation === firstTask) { | ||
// The new task is the highest priority task in the list. | ||
firstTask = continuationTask; | ||
} | ||
if (eventLog !== null) { | ||
logEvent([TaskYieldEvent, time, task.id, runIdCounter]); | ||
} | ||
} | ||
} | ||
function markSchedulerSuspended(time) { | ||
if (enableProfiling) { | ||
mainThreadIdCounter++; | ||
var _previous = nextAfterContinuation.previous; | ||
_previous.next = nextAfterContinuation.previous = continuationTask; | ||
continuationTask.next = nextAfterContinuation; | ||
continuationTask.previous = _previous; | ||
if (eventLog !== null) { | ||
logEvent([SchedulerSuspendEvent, time, mainThreadIdCounter]); | ||
} | ||
} | ||
} | ||
function markSchedulerUnsuspended(time) { | ||
if (enableProfiling) { | ||
if (eventLog !== null) { | ||
logEvent([SchedulerResumeEvent, time, mainThreadIdCounter]); | ||
} | ||
} | ||
} | ||
/* eslint-disable no-var */ | ||
// Math.pow(2, 30) - 1 | ||
// 0b111111111111111111111111111111 | ||
var maxSigned31BitInt = 1073741823; // Times out immediately | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out | ||
var USER_BLOCKING_PRIORITY = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; // Never times out | ||
var IDLE_PRIORITY = maxSigned31BitInt; // Tasks are stored on a min heap | ||
var taskQueue = []; | ||
var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. | ||
var taskIdCounter = 1; // Pausing the scheduler is useful for debugging. | ||
var isSchedulerPaused = false; | ||
var currentTask = null; | ||
var currentPriorityLevel = NormalPriority; // This is set while performing work, to prevent re-entrancy. | ||
var isPerformingWork = false; | ||
var isHostCallbackScheduled = false; | ||
var isHostTimeoutScheduled = false; | ||
function advanceTimers(currentTime) { | ||
// Check for tasks that are no longer delayed and add them to the queue. | ||
if (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime) { | ||
do { | ||
var task = firstDelayedTask; | ||
var next = task.next; | ||
if (task === next) { | ||
firstDelayedTask = null; | ||
} else { | ||
firstDelayedTask = next; | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
var timer = peek(timerQueue); | ||
while (timer !== null) { | ||
if (timer.callback === null) { | ||
// Timer was cancelled. | ||
pop(timerQueue); | ||
} else if (timer.startTime <= currentTime) { | ||
// Timer fired. Transfer to the task queue. | ||
pop(timerQueue); | ||
timer.sortIndex = timer.expirationTime; | ||
push(taskQueue, timer); | ||
if (enableProfiling) { | ||
markTaskStart(timer, currentTime); | ||
timer.isQueued = true; | ||
} | ||
task.next = task.previous = null; | ||
insertScheduledTask(task, task.expirationTime); | ||
} while (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime); | ||
} else { | ||
// Remaining timers are pending. | ||
return; | ||
} | ||
timer = peek(timerQueue); | ||
} | ||
@@ -401,7 +538,11 @@ } | ||
if (!isHostCallbackScheduled) { | ||
if (firstTask !== null) { | ||
if (peek(taskQueue) !== null) { | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
} else if (firstDelayedTask !== null) { | ||
requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime); | ||
} else { | ||
var firstTimer = peek(timerQueue); | ||
if (firstTimer !== null) { | ||
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime); | ||
} | ||
} | ||
@@ -412,9 +553,9 @@ } | ||
function flushWork(hasTimeRemaining, initialTime) { | ||
// Exit right away if we're currently paused | ||
if (enableSchedulerDebugging && isSchedulerPaused) { | ||
return; | ||
} | ||
if (enableProfiling) { | ||
markSchedulerUnsuspended(initialTime); | ||
} // We'll need a host callback the next time work is scheduled. | ||
// We'll need a host callback the next time work is scheduled. | ||
isHostCallbackScheduled = false; | ||
if (isHostTimeoutScheduled) { | ||
@@ -426,40 +567,92 @@ // We scheduled a timeout but it's no longer needed. Cancel it. | ||
var currentTime = initialTime; | ||
advanceTimers(currentTime); | ||
isPerformingWork = true; | ||
var previousPriorityLevel = currentPriorityLevel; | ||
isPerformingWork = true; | ||
try { | ||
if (!hasTimeRemaining) { | ||
// Flush all the expired callbacks without yielding. | ||
// TODO: Split flushWork into two separate functions instead of using | ||
// a boolean argument? | ||
while (firstTask !== null && firstTask.expirationTime <= currentTime && !(enableSchedulerDebugging && isSchedulerPaused)) { | ||
flushTask(firstTask, currentTime); | ||
currentTime = getCurrentTime(); | ||
advanceTimers(currentTime); | ||
if (enableProfiling) { | ||
try { | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} catch (error) { | ||
if (currentTask !== null) { | ||
var currentTime = getCurrentTime(); | ||
markTaskErrored(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
throw error; | ||
} | ||
} else { | ||
// Keep flushing callbacks until we run out of time in the frame. | ||
if (firstTask !== null) { | ||
do { | ||
flushTask(firstTask, currentTime); | ||
currentTime = getCurrentTime(); | ||
advanceTimers(currentTime); | ||
} while (firstTask !== null && !shouldYieldToHost() && !(enableSchedulerDebugging && isSchedulerPaused)); | ||
} | ||
// No catch in prod codepath. | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} | ||
// Return whether there's additional work | ||
if (firstTask !== null) { | ||
return true; | ||
} else { | ||
if (firstDelayedTask !== null) { | ||
requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime); | ||
} | ||
return false; | ||
} | ||
} finally { | ||
currentTask = null; | ||
currentPriorityLevel = previousPriorityLevel; | ||
isPerformingWork = false; | ||
if (enableProfiling) { | ||
var _currentTime = getCurrentTime(); | ||
markSchedulerSuspended(_currentTime); | ||
} | ||
} | ||
} | ||
function workLoop(hasTimeRemaining, initialTime) { | ||
var currentTime = initialTime; | ||
advanceTimers(currentTime); | ||
currentTask = peek(taskQueue); | ||
while (currentTask !== null && !(enableSchedulerDebugging && isSchedulerPaused)) { | ||
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) { | ||
// This currentTask hasn't expired, and we've reached the deadline. | ||
break; | ||
} | ||
var callback = currentTask.callback; | ||
if (callback !== null) { | ||
currentTask.callback = null; | ||
currentPriorityLevel = currentTask.priorityLevel; | ||
var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; | ||
markTaskRun(currentTask, currentTime); | ||
var continuationCallback = callback(didUserCallbackTimeout); | ||
currentTime = getCurrentTime(); | ||
if (typeof continuationCallback === 'function') { | ||
currentTask.callback = continuationCallback; | ||
markTaskYield(currentTask, currentTime); | ||
} else { | ||
if (enableProfiling) { | ||
markTaskCompleted(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
if (currentTask === peek(taskQueue)) { | ||
pop(taskQueue); | ||
} | ||
} | ||
advanceTimers(currentTime); | ||
} else { | ||
pop(taskQueue); | ||
} | ||
currentTask = peek(taskQueue); | ||
} // Return whether there's additional work | ||
if (currentTask !== null) { | ||
return true; | ||
} else { | ||
var firstTimer = peek(timerQueue); | ||
if (firstTimer !== null) { | ||
requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime); | ||
} | ||
return false; | ||
} | ||
} | ||
function unstable_runWithPriority(priorityLevel, eventHandler) { | ||
@@ -473,2 +666,3 @@ switch (priorityLevel) { | ||
break; | ||
default: | ||
@@ -490,2 +684,3 @@ priorityLevel = NormalPriority; | ||
var priorityLevel; | ||
switch (currentPriorityLevel) { | ||
@@ -498,2 +693,3 @@ case ImmediatePriority: | ||
break; | ||
default: | ||
@@ -534,8 +730,12 @@ // Anything lower than normal priority should remain at the current level. | ||
return IMMEDIATE_PRIORITY_TIMEOUT; | ||
case UserBlockingPriority: | ||
return USER_BLOCKING_PRIORITY; | ||
case IdlePriority: | ||
return IDLE_PRIORITY; | ||
case LowPriority: | ||
return LOW_PRIORITY_TIMEOUT; | ||
case NormalPriority: | ||
@@ -549,7 +749,8 @@ default: | ||
var currentTime = getCurrentTime(); | ||
var startTime; | ||
var timeout; | ||
if (typeof options === 'object' && options !== null) { | ||
var delay = options.delay; | ||
if (typeof delay === 'number' && delay > 0) { | ||
@@ -560,2 +761,3 @@ startTime = currentTime + delay; | ||
} | ||
timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel); | ||
@@ -568,4 +770,4 @@ } else { | ||
var expirationTime = startTime + timeout; | ||
var newTask = { | ||
id: taskIdCounter++, | ||
callback: callback, | ||
@@ -575,10 +777,15 @@ priorityLevel: priorityLevel, | ||
expirationTime: expirationTime, | ||
next: null, | ||
previous: null | ||
sortIndex: -1 | ||
}; | ||
if (enableProfiling) { | ||
newTask.isQueued = false; | ||
} | ||
if (startTime > currentTime) { | ||
// This is a delayed task. | ||
insertDelayedTask(newTask, startTime); | ||
if (firstTask === null && firstDelayedTask === newTask) { | ||
newTask.sortIndex = startTime; | ||
push(timerQueue, newTask); | ||
if (peek(taskQueue) === null && newTask === peek(timerQueue)) { | ||
// All tasks are delayed, and this is the task with the earliest delay. | ||
@@ -590,10 +797,18 @@ if (isHostTimeoutScheduled) { | ||
isHostTimeoutScheduled = true; | ||
} | ||
// Schedule a timeout. | ||
} // Schedule a timeout. | ||
requestHostTimeout(handleTimeout, startTime - currentTime); | ||
} | ||
} else { | ||
insertScheduledTask(newTask, expirationTime); | ||
// Schedule a host callback, if needed. If we're already performing work, | ||
newTask.sortIndex = expirationTime; | ||
push(taskQueue, newTask); | ||
if (enableProfiling) { | ||
markTaskStart(newTask, currentTime); | ||
newTask.isQueued = true; | ||
} // Schedule a host callback, if needed. If we're already performing work, | ||
// wait until the next time we yield. | ||
if (!isHostCallbackScheduled && !isPerformingWork) { | ||
@@ -608,70 +823,2 @@ isHostCallbackScheduled = true; | ||
function insertScheduledTask(newTask, expirationTime) { | ||
// Insert the new task into the list, ordered first by its timeout, then by | ||
// insertion. So the new task is inserted after any other task the | ||
// same timeout | ||
if (firstTask === null) { | ||
// This is the first task in the list. | ||
firstTask = newTask.next = newTask.previous = newTask; | ||
} else { | ||
var next = null; | ||
var task = firstTask; | ||
do { | ||
if (expirationTime < task.expirationTime) { | ||
// The new task times out before this one. | ||
next = task; | ||
break; | ||
} | ||
task = task.next; | ||
} while (task !== firstTask); | ||
if (next === null) { | ||
// No task with a later timeout was found, which means the new task has | ||
// the latest timeout in the list. | ||
next = firstTask; | ||
} else if (next === firstTask) { | ||
// The new task has the earliest expiration in the entire list. | ||
firstTask = newTask; | ||
} | ||
var previous = next.previous; | ||
previous.next = next.previous = newTask; | ||
newTask.next = next; | ||
newTask.previous = previous; | ||
} | ||
} | ||
function insertDelayedTask(newTask, startTime) { | ||
// Insert the new task into the list, ordered by its start time. | ||
if (firstDelayedTask === null) { | ||
// This is the first task in the list. | ||
firstDelayedTask = newTask.next = newTask.previous = newTask; | ||
} else { | ||
var next = null; | ||
var task = firstDelayedTask; | ||
do { | ||
if (startTime < task.startTime) { | ||
// The new task times out before this one. | ||
next = task; | ||
break; | ||
} | ||
task = task.next; | ||
} while (task !== firstDelayedTask); | ||
if (next === null) { | ||
// No task with a later timeout was found, which means the new task has | ||
// the latest timeout in the list. | ||
next = firstDelayedTask; | ||
} else if (next === firstDelayedTask) { | ||
// The new task has the earliest expiration in the entire list. | ||
firstDelayedTask = newTask; | ||
} | ||
var previous = next.previous; | ||
previous.next = next.previous = newTask; | ||
newTask.next = next; | ||
newTask.previous = previous; | ||
} | ||
} | ||
function unstable_pauseExecution() { | ||
@@ -683,2 +830,3 @@ isSchedulerPaused = true; | ||
isSchedulerPaused = false; | ||
if (!isHostCallbackScheduled && !isPerformingWork) { | ||
@@ -691,30 +839,18 @@ isHostCallbackScheduled = true; | ||
function unstable_getFirstCallbackNode() { | ||
return firstTask; | ||
return peek(taskQueue); | ||
} | ||
function unstable_cancelCallback(task) { | ||
var next = task.next; | ||
if (next === null) { | ||
// Already cancelled. | ||
return; | ||
} | ||
if (task === next) { | ||
if (task === firstTask) { | ||
firstTask = null; | ||
} else if (task === firstDelayedTask) { | ||
firstDelayedTask = null; | ||
if (enableProfiling) { | ||
if (task.isQueued) { | ||
var currentTime = getCurrentTime(); | ||
markTaskCanceled(task, currentTime); | ||
task.isQueued = false; | ||
} | ||
} else { | ||
if (task === firstTask) { | ||
firstTask = next; | ||
} else if (task === firstDelayedTask) { | ||
firstDelayedTask = next; | ||
} | ||
var previous = task.previous; | ||
previous.next = next; | ||
next.previous = previous; | ||
} | ||
} // Null out the callback to indicate the task has been canceled. (Can't | ||
// remove from the queue because you can't remove arbitrary nodes from an | ||
// array based heap, only the first one.) | ||
task.next = task.previous = null; | ||
task.callback = null; | ||
} | ||
@@ -729,6 +865,12 @@ | ||
advanceTimers(currentTime); | ||
return currentTask !== null && firstTask !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); | ||
var firstTask = peek(taskQueue); | ||
return firstTask !== currentTask && currentTask !== null && firstTask !== null && firstTask.callback !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); | ||
} | ||
var unstable_requestPaint = requestPaint; | ||
var unstable_Profiling = enableProfiling ? { | ||
startLoggingProfilingEvents: startLoggingProfilingEvents, | ||
stopLoggingProfilingEvents: stopLoggingProfilingEvents, | ||
sharedProfilingBuffer: sharedProfilingBuffer | ||
} : null; | ||
@@ -761,2 +903,3 @@ exports.unstable_flushAllWithoutAsserting = unstable_flushAllWithoutAsserting; | ||
exports.unstable_forceFrameRate = forceFrameRate; | ||
exports.unstable_Profiling = unstable_Profiling; | ||
@@ -763,0 +906,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,2 +0,2 @@ | ||
/** @license React v0.15.0 | ||
/** @license React v0.16.0 | ||
* scheduler-unstable_mock.production.min.js | ||
@@ -9,11 +9,10 @@ * | ||
*/ | ||
'use strict';(function(d,t){"object"===typeof exports&&"undefined"!==typeof module?t(exports):"function"===typeof define&&define.amd?define(["exports"],t):t(d.SchedulerMock={})})(this,function(d){function t(){return-1!==y&&null!==n&&n.length>=y||A&&B?u=!0:!1}function E(){if(m)throw Error("Already flushing work.");if(null!==f){m=!0;try{f(!1,l)||(f=null)}finally{m=!1}}}function F(){if(m)throw Error("Already flushing work.");if(null!==f){var a=f;m=!0;try{var b=!0;do b=a(!0,l);while(b);b||(f=null);return!0}finally{m= | ||
!1}}else return!1}function G(a,b){var c=a.next;if(c===a)e=null;else{a===e&&(e=c);var d=a.previous;d.next=c;c.previous=d}a.next=a.previous=null;c=a.callback;d=g;var h=v;g=a.priorityLevel;v=a;try{var k=a.expirationTime<=b;switch(g){case 1:var f=c(k);break;case 2:f=c(k);break;case 3:f=c(k);break;case 4:f=c(k);break;case 5:f=c(k)}}catch(J){throw J;}finally{g=d,v=h}if("function"===typeof f)if(b=a.expirationTime,a.callback=f,null===e)e=a.next=a.previous=a;else{f=null;k=e;do{if(b<=k.expirationTime){f=k; | ||
break}k=k.next}while(k!==e);null===f?f=e:f===e&&(e=a);b=f.previous;b.next=f.previous=a;a.next=f;a.previous=b}}function w(a){if(null!==h&&h.startTime<=a){do{var b=h,c=b.next;if(b===c)h=null;else{h=c;var d=b.previous;d.next=c;c.previous=d}b.next=b.previous=null;H(b,b.expirationTime)}while(null!==h&&h.startTime<=a)}}function C(a){x=!1;w(a);q||(null!==e?(q=!0,f=D):null!==h&&(a=h.startTime-a,p=C,r=l+a))}function D(a,b){q=!1;x&&(x=!1,p=null,r=-1);w(b);z=!0;try{if(!a)for(;null!==e&&e.expirationTime<=b;)G(e, | ||
b),b=l,w(b);else if(null!==e){do G(e,b),b=l,w(b);while(null!==e&&!t())}if(null!==e)return!0;if(null!==h){var c=h.startTime-b;p=C;r=l+c}return!1}finally{z=!1}}function I(a){switch(a){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1E4;default:return 5E3}}function H(a,b){if(null===e)e=a.next=a.previous=a;else{var c=null,d=e;do{if(b<d.expirationTime){c=d;break}d=d.next}while(d!==e);null===c?c=e:c===e&&(e=a);b=c.previous;b.next=c.previous=a;a.next=c;a.previous=b}}var l=0,f=null, | ||
p=null,r=-1,n=null,y=-1,u=!1,m=!1,B=!1,A=!1,e=null,h=null,v=null,g=3,z=!1,q=!1,x=!1;d.unstable_flushAllWithoutAsserting=F;d.unstable_flushNumberOfYields=function(a){if(m)throw Error("Already flushing work.");if(null!==f){var b=f;y=a;m=!0;try{a=!0;do a=b(!0,l);while(a&&!u);a||(f=null)}finally{y=-1,m=u=!1}}};d.unstable_flushExpired=E;d.unstable_clearYields=function(){if(null===n)return[];var a=n;n=null;return a};d.unstable_flushUntilNextPaint=function(){if(m)throw Error("Already flushing work.");if(null!== | ||
f){var a=f;A=!0;B=!1;m=!0;try{var b=!0;do b=a(!0,l);while(b&&!u);b||(f=null)}finally{m=u=A=!1}}};d.unstable_flushAll=function(){if(null!==n)throw Error("Log is not empty. Assert on the log of yielded values before flushing additional work.");F();if(null!==n)throw Error("While flushing work, something yielded a value. Use an assertion helper to assert on the log of yielded values, e.g. expect(Scheduler).toFlushAndYield([...])");};d.unstable_yieldValue=function(a){null===n?n=[a]:n.push(a)};d.unstable_advanceTime= | ||
function(a){l+=a;m||(null!==p&&r<=l&&(p(l),r=-1,p=null),E())};d.unstable_ImmediatePriority=1;d.unstable_UserBlockingPriority=2;d.unstable_NormalPriority=3;d.unstable_IdlePriority=5;d.unstable_LowPriority=4;d.unstable_runWithPriority=function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=g;g=a;try{return b()}finally{g=c}};d.unstable_next=function(a){switch(g){case 1:case 2:case 3:var b=3;break;default:b=g}var c=g;g=b;try{return a()}finally{g=c}};d.unstable_scheduleCallback= | ||
function(a,b,c){var d=l;if("object"===typeof c&&null!==c){var g=c.delay;g="number"===typeof g&&0<g?d+g:d;c="number"===typeof c.timeout?c.timeout:I(a)}else c=I(a),g=d;c=g+c;a={callback:b,priorityLevel:a,startTime:g,expirationTime:c,next:null,previous:null};if(g>d){c=g;if(null===h)h=a.next=a.previous=a;else{b=null;var k=h;do{if(c<k.startTime){b=k;break}k=k.next}while(k!==h);null===b?b=h:b===h&&(h=a);c=b.previous;c.next=b.previous=a;a.next=b;a.previous=c}null===e&&h===a&&(x?(p=null,r=-1):x=!0,p=C,r= | ||
l+(g-d))}else H(a,c),q||z||(q=!0,f=D);return a};d.unstable_cancelCallback=function(a){var b=a.next;if(null!==b){if(a===b)a===e?e=null:a===h&&(h=null);else{a===e?e=b:a===h&&(h=b);var c=a.previous;c.next=b;b.previous=c}a.next=a.previous=null}};d.unstable_wrapCallback=function(a){var b=g;return function(){var c=g;g=b;try{return a.apply(this,arguments)}finally{g=c}}};d.unstable_getCurrentPriorityLevel=function(){return g};d.unstable_shouldYield=function(){var a=l;w(a);return null!==v&&null!==e&&e.startTime<= | ||
a&&e.expirationTime<v.expirationTime||t()};d.unstable_requestPaint=function(){B=!0};d.unstable_continueExecution=function(){q||z||(q=!0,f=D)};d.unstable_pauseExecution=function(){};d.unstable_getFirstCallbackNode=function(){return e};d.unstable_now=function(){return l};d.unstable_forceFrameRate=function(){};Object.defineProperty(d,"__esModule",{value:!0})}); | ||
'use strict';(function(b,w){"object"===typeof exports&&"undefined"!==typeof module?w(exports):"function"===typeof define&&define.amd?define(["exports"],w):w(b.SchedulerMock={})})(this,function(b){function w(){return-1!==y&&null!==k&&k.length>=y||D&&E?t=!0:!1}function J(){if(h)throw Error("Already flushing work.");if(null!==f){h=!0;try{f(!1,g)||(f=null)}finally{h=!1}}}function K(){if(h)throw Error("Already flushing work.");if(null!==f){var a=f;h=!0;try{var c=!0;do c=a(!0,g);while(c);c||(f=null);return!0}finally{h= | ||
!1}}else return!1}function F(a,c){var G=a.length;a.push(c);a:for(;;){var b=Math.floor((G-1)/2),p=a[b];if(void 0!==p&&0<z(p,c))a[b]=c,a[G]=p,G=b;else break a}}function l(a){a=a[0];return void 0===a?null:a}function A(a){var c=a[0];if(void 0!==c){var b=a.pop();if(b!==c){a[0]=b;a:for(var n=0,p=a.length;n<p;){var e=2*(n+1)-1,f=a[e],d=e+1,g=a[d];if(void 0!==f&&0>z(f,b))void 0!==g&&0>z(g,f)?(a[n]=g,a[d]=b,n=d):(a[n]=f,a[e]=b,n=e);else if(void 0!==g&&0>z(g,b))a[n]=g,a[d]=b,n=d;else break a}}return c}return null} | ||
function z(a,c){var b=a.sortIndex-c.sortIndex;return 0!==b?b:a.id-c.id}function B(a){for(var c=l(q);null!==c;){if(null===c.callback)A(q);else if(c.startTime<=a)A(q),c.sortIndex=c.expirationTime,F(m,c);else break;c=l(q)}}function H(a){x=!1;B(a);if(!u)if(null!==l(m))u=!0,f=I;else{var c=l(q);null!==c&&(a=c.startTime-a,r=H,v=g+a)}}function I(a,c){u=!1;x&&(x=!1,r=null,v=-1);C=!0;var b=e;try{B(c);for(d=l(m);null!==d&&(!(d.expirationTime>c)||a&&!w());){var f=d.callback;if(null!==f){d.callback=null;e=d.priorityLevel; | ||
var p=f(d.expirationTime<=c);c=g;"function"===typeof p?d.callback=p:d===l(m)&&A(m);B(c)}else A(m);d=l(m)}if(null!==d)var h=!0;else{var k=l(q);if(null!==k){var t=k.startTime-c;r=H;v=g+t}h=!1}return h}finally{d=null,e=b,C=!1}}function L(a){switch(a){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1E4;default:return 5E3}}var g=0,f=null,r=null,v=-1,k=null,y=-1,t=!1,h=!1,E=!1,D=!1,m=[],q=[],M=1,d=null,e=3,C=!1,u=!1,x=!1;b.unstable_flushAllWithoutAsserting=K;b.unstable_flushNumberOfYields= | ||
function(a){if(h)throw Error("Already flushing work.");if(null!==f){var c=f;y=a;h=!0;try{a=!0;do a=c(!0,g);while(a&&!t);a||(f=null)}finally{y=-1,h=t=!1}}};b.unstable_flushExpired=J;b.unstable_clearYields=function(){if(null===k)return[];var a=k;k=null;return a};b.unstable_flushUntilNextPaint=function(){if(h)throw Error("Already flushing work.");if(null!==f){var a=f;D=!0;E=!1;h=!0;try{var c=!0;do c=a(!0,g);while(c&&!t);c||(f=null)}finally{h=t=D=!1}}};b.unstable_flushAll=function(){if(null!==k)throw Error("Log is not empty. Assert on the log of yielded values before flushing additional work."); | ||
K();if(null!==k)throw Error("While flushing work, something yielded a value. Use an assertion helper to assert on the log of yielded values, e.g. expect(Scheduler).toFlushAndYield([...])");};b.unstable_yieldValue=function(a){null===k?k=[a]:k.push(a)};b.unstable_advanceTime=function(a){g+=a;h||(null!==r&&v<=g&&(r(g),v=-1,r=null),J())};b.unstable_ImmediatePriority=1;b.unstable_UserBlockingPriority=2;b.unstable_NormalPriority=3;b.unstable_IdlePriority=5;b.unstable_LowPriority=4;b.unstable_runWithPriority= | ||
function(a,c){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var b=e;e=a;try{return c()}finally{e=b}};b.unstable_next=function(a){switch(e){case 1:case 2:case 3:var c=3;break;default:c=e}var b=e;e=c;try{return a()}finally{e=b}};b.unstable_scheduleCallback=function(a,c,b){var e=g;if("object"===typeof b&&null!==b){var d=b.delay;d="number"===typeof d&&0<d?e+d:e;b="number"===typeof b.timeout?b.timeout:L(a)}else b=L(a),d=e;b=d+b;a={id:M++,callback:c,priorityLevel:a,startTime:d,expirationTime:b, | ||
sortIndex:-1};d>e?(a.sortIndex=d,F(q,a),null===l(m)&&a===l(q)&&(x?(r=null,v=-1):x=!0,r=H,v=g+(d-e))):(a.sortIndex=b,F(m,a),u||C||(u=!0,f=I));return a};b.unstable_cancelCallback=function(a){a.callback=null};b.unstable_wrapCallback=function(a){var b=e;return function(){var c=e;e=b;try{return a.apply(this,arguments)}finally{e=c}}};b.unstable_getCurrentPriorityLevel=function(){return e};b.unstable_shouldYield=function(){var a=g;B(a);var b=l(m);return b!==d&&null!==d&&null!==b&&null!==b.callback&&b.startTime<= | ||
a&&b.expirationTime<d.expirationTime||w()};b.unstable_requestPaint=function(){E=!0};b.unstable_continueExecution=function(){u||C||(u=!0,f=I)};b.unstable_pauseExecution=function(){};b.unstable_getFirstCallbackNode=function(){return l(m)};b.unstable_now=function(){return g};b.unstable_forceFrameRate=function(){};b.unstable_Profiling=null;Object.defineProperty(b,"__esModule",{value:!0})}); |
@@ -147,3 +147,7 @@ /** | ||
}, | ||
get unstable_Profiling() { | ||
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED | ||
.Scheduler.unstable_Profiling; | ||
}, | ||
}); | ||
}); |
@@ -141,3 +141,7 @@ /** | ||
}, | ||
get unstable_Profiling() { | ||
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED | ||
.Scheduler.unstable_Profiling; | ||
}, | ||
}); | ||
}); |
@@ -141,3 +141,7 @@ /** | ||
}, | ||
get unstable_Profiling() { | ||
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED | ||
.Scheduler.unstable_Profiling; | ||
}, | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131298
3404