1.0.7 • Published 6 years ago

@fseehawer/requestidlecallback v1.0.7

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

requestIdleCallback polyfill

npm.io npm.io

This requestIdleCallback polyfill doesn't use the window object to detect if the feature is supported in the browser and falls back to a simple timeout if the feature isn't supported.

install

npm install @fseehawer/requestidlecallback

example

import requestIdleCallback from '@fseehawer/requestidlecallback'

requestIdleCallback(() => {
  // your non-splittable task
})

for splittable task you can use the yielding technique:

requestIdleCallback((deadline) => {
  while ((deadline.timeRemaining() > 0) || deadline.didTimeout) {
    // your splittable tasks
  }
})

Or node-style:

var requestIdleCallback = require('@fseehawer/requestidlecallback')

// same as above

for cancelling?

import requestIdleCallback, { cancelIdleCallback } from '@fseehawer/requestidlecallback'

// your code
const id = requestIdleCallback(doSomething)

// then if you need to cancel
cancelIdleCallback(id)

Or node-style:

var requestIdleCallback = require('@fseehawer/requestidlecallback')
var cancel = requestIdleCallback.cancelIdleCallback

// your code
var id = requestIdleCallback(doSomething)

// then if you need to cancel
cancel(id)

license

MIT License

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago