@@ -59,15 +59,12 @@ type SchedulerCallbackOptions = {timeout?: number, ...};
59
59
60
60
const fakeCallbackNode = { } ;
61
61
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.
71
68
export const NoPriority : ReactPriorityLevel = 90 ;
72
69
73
70
export const shouldYield = Scheduler_shouldYield ;
@@ -78,66 +75,25 @@ export const requestPaint =
78
75
let syncQueue : Array < SchedulerCallback > | null = null ;
79
76
let immediateQueueCallbackNode : mixed | null = null ;
80
77
let 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 ;
92
78
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 ;
109
80
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 ( ) ;
125
83
}
126
84
127
85
export function runWithPriority < T > (
128
- reactPriorityLevel : ReactPriorityLevel ,
86
+ priorityLevel : ReactPriorityLevel ,
129
87
fn : ( ) => T ,
130
88
) : T {
131
- const priorityLevel = reactPriorityToSchedulerPriority ( reactPriorityLevel ) ;
132
89
return Scheduler_runWithPriority ( priorityLevel , fn ) ;
133
90
}
134
91
135
92
export function scheduleCallback (
136
- reactPriorityLevel : ReactPriorityLevel ,
93
+ priorityLevel : ReactPriorityLevel ,
137
94
callback : SchedulerCallback ,
138
95
options : SchedulerCallbackOptions | void | null ,
139
96
) {
140
- const priorityLevel = reactPriorityToSchedulerPriority ( reactPriorityLevel ) ;
141
97
return Scheduler_scheduleCallback ( priorityLevel , callback , options ) ;
142
98
}
143
99
0 commit comments