GoldentTuft / elm-infinite-scroll / InfScroll

Type


type InfScroll


type Status
    = Loading
    | Loaded
    | Loadable
    | Stop


type Dir
    = Top
    | Bottom


type Msg


type alias DomId =
String

Init

init : DomId -> Dir -> InfScroll

InfScroll.init "item-list" InfScroll.Bottom
    |> setOffset 100

setDir : Dir -> InfScroll -> InfScroll

setOffset : Basics.Int -> InfScroll -> InfScroll

setInterval : Basics.Float -> InfScroll -> InfScroll

Update

subscriptions : InfScroll -> Platform.Sub.Sub Msg

update : Msg -> InfScroll -> ( InfScroll, Platform.Cmd.Cmd Msg )

whenLoadMore : (Msg -> msg) -> Platform.Cmd.Cmd msg -> ( InfScroll, Platform.Cmd.Cmd Msg ) -> ( InfScroll, Platform.Cmd.Cmd msg )

MapInfScroll subMsg ->
    let
        (newInfScroll, cmd) =
            InfScroll.update subMsg model.infScroll
                |> InfScroll.whenLoadMore MapInfScroll getItems
    in
    ( { model | infScroll = newInfScroll }
    , cmd
    )

toLoaded : InfScroll -> InfScroll

GotItems items ->
    ( { model
        | items =
            List.sort (model.items ++ items)
        , infScroll =
            if List.isEmpty items then
                InfScroll.toStop model.infScroll

            else
                InfScroll.toLoaded model.infScroll
        }
    , Cmd.none
    )

toStop : InfScroll -> InfScroll

View

view : InfScroll -> List (Html.Attribute msg) -> List (Html.Attribute msg) -> List (Html msg) -> Html msg

InfScroll.view model.infScroll
    (InfScroll.defaultContainerAttrs infScroll)
    (InfScroll.defaultItemsAttrs infScroll)
    (List.map viewItem model.items)

defaultContainerAttrs : InfScroll -> List (Html.Attribute msg)

defaultItemsAttrs : InfScroll -> List (Html.Attribute msg)

Get

getDir : InfScroll -> Dir

getStatus : InfScroll -> Status

getViewport : InfScroll -> Maybe Browser.Dom.Viewport