Skip to content

Commit

Permalink
fix(@uform/core): add scheduler backward compat (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Aug 9, 2019
1 parent a06598d commit ed94834
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export * from '@uform/utils'

const self = globalThisPolyfill

const compactScheduler = ([raf, caf, priority]) => {
return [callback => raf(priority, callback), caf]
const compactScheduler = ([raf, caf, priority], fresh: boolean) => {
return [fresh ? callback => raf(priority, callback) : raf, caf]
}

const getScheduler = () => {
Expand All @@ -24,11 +24,14 @@ const getScheduler = () => {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const scheduler = require('scheduler')
return compactScheduler([
scheduler.scheduleCallback || scheduler.unstable_scheduleCallback,
scheduler.cancelCallback || scheduler.unstable_cancelCallback,
scheduler.NormalPriority || scheduler.unstable_NormalPriority
])
return compactScheduler(
[
scheduler.scheduleCallback || scheduler.unstable_scheduleCallback,
scheduler.cancelCallback || scheduler.unstable_cancelCallback,
scheduler.NormalPriority || scheduler.unstable_NormalPriority
],
!!scheduler.unstable_requestPaint
)
} catch (err) {
return [self.requestAnimationFrame, self.cancelAnimationFrame]
}
Expand Down

0 comments on commit ed94834

Please sign in to comment.