Last active
August 17, 2021 14:33
-
-
Save glenjamin/3e8d65944d4f4761e521 to your computer and use it in GitHub Desktop.
requestAnimationFrame batching
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
/*eslint-env browser*/ | |
/** | |
* Cribbed from: | |
* github.com/facebook/react/blob/master/src/addons/ReactRAFBatchingStrategy.js | |
* github.com/petehunt/react-raf-batching/blob/master/ReactRAFBatching.js | |
*/ | |
var ReactUpdates = require('react/lib/ReactUpdates'); | |
var ReactRAFBatchingStrategy = { | |
isBatchingUpdates: true, | |
/** | |
* Call the provided function in a context within which calls to `setState` | |
* and friends are batched such that components aren't updated unnecessarily. | |
*/ | |
batchedUpdates: function(callback, param) { | |
callback(param); | |
} | |
}; | |
ReactUpdates.injection.injectBatchingStrategy(ReactRAFBatchingStrategy); | |
function tick() { | |
ReactUpdates.flushBatchedUpdates(); | |
requestAnimationFrame(tick); | |
} | |
if (window && typeof window.requestAnimationFrame == 'function') { | |
window.requestAnimationFrame(tick); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment