Skip to content

Instantly share code, notes, and snippets.

@peteruithoven
Created February 1, 2016 16:52
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save peteruithoven/9a9363e064ee8bdf28ae to your computer and use it in GitHub Desktop.
Save peteruithoven/9a9363e064ee8bdf28ae to your computer and use it in GitHub Desktop.
/*
* Utility to only call Redux updates in RequestAnimationFrame's
* Also uses React-dom's batchedUpdates
*/
import raf from 'raf';
import { unstable_batchedUpdates as batchedUpdates } from 'react-dom';
let rafID;
let notifyFunc;
function animFrame() {
if (notifyFunc) {
batchedUpdates(notifyFunc);
notifyFunc = null;
}
rafID = raf(animFrame);
}
export default function rafUpdateBatcher(notify) {
if (rafID === undefined) rafID = raf(animFrame);
notifyFunc = notify;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment