Last active
August 29, 2015 14:22
-
-
Save rossPatton/1fc476950f95dc5b9b09 to your computer and use it in GitHub Desktop.
Scroll like a king
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
module.exports = function domUpdate( app ): Object { | |
if ( typeof app !== 'object' ) { return; } | |
// recursion recursion recursion | |
// we pass in the FSB stuff to make sure we're | |
// using the latest cache stuff | |
raf(() => { | |
return app.domUpdate( app ); | |
}); | |
let cache: Object = app.cache; | |
// dont move me. i go before the early return. | |
// visual perf gets killed if i move | |
cache.currScroll = window.pageYOffset + 60; | |
// exit early if possible and do no work (if not moving basically) | |
if ( cache.currScroll === cache.prevScroll ) { | |
return; | |
} | |
/* | |
do | |
your | |
logic | |
here | |
*/ | |
cache.prevScroll = window.pageYOffset + 60; | |
return cache; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment