@@ -59,15 +59,12 @@ type SchedulerCallbackOptions = {timeout?: number, ...};
5959
6060const fakeCallbackNode = { } ;
6161
62- // Except for NoPriority, these correspond to Scheduler priorities. We use
63- // ascending numbers so we can compare them like numbers. They start at 90 to
64- // avoid clashing with Scheduler's priorities.
65- export const ImmediatePriority : ReactPriorityLevel = 99 ;
66- export const UserBlockingPriority : ReactPriorityLevel = 98 ;
67- export const NormalPriority : ReactPriorityLevel = 97 ;
68- export const LowPriority : ReactPriorityLevel = 96 ;
69- export const IdlePriority : ReactPriorityLevel = 95 ;
70- // NoPriority is the absence of priority. Also React-only.
62+ export const ImmediatePriority : ReactPriorityLevel = Scheduler_ImmediatePriority ;
63+ export const UserBlockingPriority : ReactPriorityLevel = Scheduler_UserBlockingPriority ;
64+ export const NormalPriority : ReactPriorityLevel = Scheduler_NormalPriority ;
65+ export const LowPriority : ReactPriorityLevel = Scheduler_LowPriority ;
66+ export const IdlePriority : ReactPriorityLevel = Scheduler_IdlePriority ;
67+ // NoPriority is the absence of priority. React-only.
7168export const NoPriority : ReactPriorityLevel = 90 ;
7269
7370export const shouldYield = Scheduler_shouldYield ;
@@ -78,66 +75,25 @@ export const requestPaint =
7875let syncQueue : Array < SchedulerCallback > | null = null ;
7976let immediateQueueCallbackNode : mixed | null = null ;
8077let isFlushingSyncQueue : boolean = false ;
81- const initialTimeMs : number = Scheduler_now ( ) ;
82-
83- // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
84- // This will be the case for modern browsers that support `performance.now`. In
85- // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
86- // timestamp. In that case, subtract the module initialization time to simulate
87- // the behavior of performance.now and keep our times small enough to fit
88- // within 32 bits.
89- // TODO: Consider lifting this into Scheduler.
90- export const now =
91- initialTimeMs < 10000 ? Scheduler_now : ( ) => Scheduler_now ( ) - initialTimeMs ;
9278
93- export function getCurrentPriorityLevel ( ) : ReactPriorityLevel {
94- switch ( Scheduler_getCurrentPriorityLevel ( ) ) {
95- case Scheduler_ImmediatePriority :
96- return ImmediatePriority ;
97- case Scheduler_UserBlockingPriority :
98- return UserBlockingPriority ;
99- case Scheduler_NormalPriority :
100- return NormalPriority ;
101- case Scheduler_LowPriority :
102- return LowPriority ;
103- case Scheduler_IdlePriority :
104- return IdlePriority ;
105- default :
106- invariant ( false , 'Unknown priority level.' ) ;
107- }
108- }
79+ export const now = Scheduler_now ;
10980
110- function reactPriorityToSchedulerPriority ( reactPriorityLevel ) {
111- switch ( reactPriorityLevel ) {
112- case ImmediatePriority :
113- return Scheduler_ImmediatePriority ;
114- case UserBlockingPriority :
115- return Scheduler_UserBlockingPriority ;
116- case NormalPriority :
117- return Scheduler_NormalPriority ;
118- case LowPriority :
119- return Scheduler_LowPriority ;
120- case IdlePriority :
121- return Scheduler_IdlePriority ;
122- default :
123- invariant ( false , 'Unknown priority level.' ) ;
124- }
81+ export function getCurrentPriorityLevel ( ) : ReactPriorityLevel {
82+ return Scheduler_getCurrentPriorityLevel ( ) ;
12583}
12684
12785export function runWithPriority < T > (
128- reactPriorityLevel : ReactPriorityLevel ,
86+ priorityLevel : ReactPriorityLevel ,
12987 fn : ( ) => T ,
13088) : T {
131- const priorityLevel = reactPriorityToSchedulerPriority ( reactPriorityLevel ) ;
13289 return Scheduler_runWithPriority ( priorityLevel , fn ) ;
13390}
13491
13592export function scheduleCallback (
136- reactPriorityLevel : ReactPriorityLevel ,
93+ priorityLevel : ReactPriorityLevel ,
13794 callback : SchedulerCallback ,
13895 options : SchedulerCallbackOptions | void | null ,
13996) {
140- const priorityLevel = reactPriorityToSchedulerPriority ( reactPriorityLevel ) ;
14197 return Scheduler_scheduleCallback ( priorityLevel , callback , options ) ;
14298}
14399
0 commit comments