elm-infinite-list-view
elm-infinite-list-view copied to clipboard
Optimization: Only update the model when you scroll enough to change the skipCount
When scrolling, instead of updating on every scroll event/animationFrame, you could save a lot of rerenders by only doing it when it actually changes the skipCount. You can even add "chunking" so that it only updates every third row for example.
Example from my own virtual-list implementation:
on "scroll"
(Decode.map2
(\scrollTop clientHeight ->
{ offset = floor scrollTop // itemHeight // chunkSize
, containerHeight = floor clientHeight
}
)
(Decode.at [ "target", "scrollTop" ] Decode.float)
(Decode.at [ "target", "clientHeight" ] Decode.float)
|> Decode.andThen
(\newState ->
if newState == state then
Decode.fail "No difference, ignore"
else
Decode.succeed (onScroll newState)
)
)
https://gist.github.com/Herteby/ef0a9b4d688a216d9ebdc6968c9a0907
Nice :) Would you mind creating a PR? :)