Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/client/batchUpdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// fallback to timers if rAF not present
const stopUpdate = window.cancelAnimationFrame || window.clearTimeout
const startUpdate = window.requestAnimationFrame || ((cb) => window.setTimeout(cb, 0))

/**
* Performs a batched update. Uses requestAnimationFrame to prevent
* calling a function too many times in quick succession.
Expand All @@ -13,7 +9,14 @@ const startUpdate = window.requestAnimationFrame || ((cb) => window.setTimeout(c
* @return {Number} id - a new ID
*/
export default function batchUpdate (id, callback) {
// fallback to timers if rAF not present
const stopUpdate = window.cancelAnimationFrame || window.clearTimeout
const startUpdate = window.requestAnimationFrame || ((cb) => window.setTimeout(cb, 0))

// stop any existing updates
stopUpdate(id)

// perform an update
return startUpdate(() => {
id = null
callback()
Expand Down