Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

ADD: use requestIdleCallback if its available instead of setTimeout t… #59

Closed

Conversation

agreene-coursera
Copy link
Contributor

…o provide a smoother dev experience

Description

Currently the package is using an arbitrary timeout to collect changed elements for batch checking them. This PR switches from a timeout to a wait for an idle period (requestIdleCallback) so that checks don't block UI or business logic. This should make the perceived experience of using the package much smoother

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Has documentation updated, a DU ticket, or requires no documentation change
  • Includes new tests, or was unnecessary
  • Code is reviewed for security by: << Name here >>

var timeout;
var _createElement;
var components = {};
var nodes = [];
var cache = {};

var scheduleFunction = requestIdleCallback || setTimeout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will raise a ReferenceError: requestIdleCallback is not defined in environments that do no have requestIdleCallback.

We should either pad this more defensively, or use a polyfill (eg npmjs.com/requestidlecallback).

}

var deferred = createDeferred()
var scheduleOptions = scheduleFunction === requestIdleCallback ? { timeout: timeout } : timeout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too will raise a ReferenceError.

stephenmathieson added a commit that referenced this pull request Jan 8, 2019
This patch builds on #59 (hat tip to @agreene-coursera!!) and uses `requestIdleCallback` rather than `setTimeout` in environments that support it. If the host environment does not support `requestIdleCallback`, a shim will be used (via [`npmjs.com/requestidlecallback`](https://www.npmjs.com/package/requestidlecallback)).

Closes #59.
stephenmathieson added a commit that referenced this pull request Jan 9, 2019
This patch builds on #59 (hat tip to @agreene-coursera!!) and uses `requestIdleCallback` rather than `setTimeout` in environments that support it. If the host environment does not support `requestIdleCallback`, a shim will be used (via [`npmjs.com/requestidlecallback`](https://www.npmjs.com/package/requestidlecallback)).

Closes #59.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants