Skip to content

Commit

Permalink
feat: make scheduler optional (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
stkevintan authored and janryWang committed Jul 3, 2019
1 parent 985af27 commit ed52e4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"npm": ">=3.0.0"
},
"peerDependencies": {
"@babel/runtime": "^7.4.4"
"@babel/runtime": "^7.4.4",
"scheduler": ">=0.11.2"
},
"dependencies": {
"@uform/utils": "^0.2.2",
"@uform/validator": "^0.2.2",
"dot-match": "^0.1.18",
"rxjs": "^6.3.3",
"scheduler": "^0.11.2"
"rxjs": "^6.3.3"
},
"publishConfig": {
"access": "public"
Expand Down
34 changes: 15 additions & 19 deletions packages/core/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/* eslint-disable camelcase */
import {
unstable_scheduleCallback,
scheduleCallback,
unstable_cancelCallback,
cancelCallback
} from 'scheduler'
/* eslint-disable camelcase */

import { isArr, isStr, getPathSegments, toArr, clone, isFn } from '@uform/utils'
export * from '@uform/utils'

const self = this || global || window

export const raf =
(self.requestAnimationFrame &&
(scheduleCallback ||
unstable_scheduleCallback ||
self.requestAnimationFrame)) ||
self.setTimeout
const getScheduler = () => {
if (!self.requestAnimationFrame) {
return [ self.setTimeout, self.clearTimeout ]
}
try {
const scheduler = require('scheduler')
return [
scheduler.scheduleCallback || scheduler.unstable_scheduleCallback,
scheduler.cancelCallback || scheduler.unstable_cancelCallback
]
} catch (err) {
return [ self.requestAnimationFrame, self.cancelAnimationFrame ]
}
}

export const caf =
(self.requestAnimationFrame &&
(cancelCallback || unstable_cancelCallback || self.cancelAnimationFrame)) ||
self.clearTimeout
export const [ raf, caf ] = getScheduler()

export const resolveFieldPath = path => {
if (!isArr(path)) {
Expand Down

0 comments on commit ed52e4a

Please sign in to comment.