Table where you can scroll through tons of items AKA “Infinite scroll” Useful when… pagination would be ugly client wants to display 1k+ items for whatever reason making something not laggy What is this “Scroll Table”?
What is Elm? Toolset for making web apps Language + Framework in one Simple, but useful type system “If it compiles, it works” Basically no runtime exceptions
Getting started - Brainstorming How to make something slow faster? Pretty much can’t -- only so many gigahertzies Solution Only rows clients can see need to be visible Cuts down our workload from O(N) to O(1) Sounds like magic
Maybe the US is way behind on education… Height AreaVisible = Number RowsVisible * Height Row ➡ Number RowsVisible = Height AreaVisible / Height Row Index FirstVisibleRow = Position Scroll / Height Row Index LastVisibleRow = Index FirstVisibleRow + Rows Visible Indices Visible = [Index FirstVisibleRow .. Index LastVisibleRow ] Doing 8th grade math (basic Algebra)
Basic Math to Code calculateVisibleIndices model scrollTop = let { rowHeight, rowCount, height } = model firstRow = max 0 visibleRows = (height + 1) // rowHeight lastRow = min rowCount in { model | visibleIndices = [firstRow..lastRow] } (buffering more rows so scrolling looks nicer)
Update type Msg = NoOp | UserScroll Int update : Msg -> Model -> Model update action model = case action of NoOp -> model UserScroll scrollTop -> calculateVisibleIndices model scrollTop
Purescript! This version done with Halogen Based on Components kind of like React Uses Queries for what needs to change Eval for getting the new state More involved - being simplified in the next major version http://www.slideshare.net/jdegoes/halogen-past-present-and-future`
Purescript (cont. 2) calculateVisibleIndices :: State -> Int -> State calculateVisibleIndices model scrollTop = case model of { rowHeight, rowCount, height } -> do let firstRow = scrollTop / rowHeight let visibleRows = (height + 1) / rowHeight let lastRow = firstRow + visibleRows model { visibleIndices = firstRow..lastRow } eval :: Natural Query (ComponentDSL State Query g) eval (UserScroll e next) = do modify $ \s -> calculateVisibleIndices s e pure next