Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization: Only update the model when you scroll enough to change the skipCount #5

Open
Herteby opened this issue Nov 19, 2019 · 1 comment

Comments

@Herteby
Copy link

Herteby commented Nov 19, 2019

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

@FabienHenon
Copy link
Owner

Nice :)
Would you mind creating a PR? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants