Created
February 1, 2016 16:52
-
-
Save peteruithoven/9a9363e064ee8bdf28ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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