dtwrks/elm-book/1.0.1

NOTE: the latest version is 1.5.1

ElmBook.StatefulOptions

Attributes used by ElmBook.withStatefulOptions.

The attributes below are mostly used for Stateful Books. Take a look at the "Stateful Chapters" guide for more details.

initialState : state -> StatefulOptions state -> StatefulOptions state

Add an initial state to your book.

type alias SharedState =
    { value : String }




book : Book SharedState
book "MyApp"
    |> withStatefulOptions [
        initialState { value = "" }
    ]
List (Sub (Msg state))
-> StatefulOptions state
-> StatefulOptions state

Add subscriptions to your book.

import ElmBook.Actions exposing (updateState)


type alias SharedState =
    { value : String
    , timestamp : Posix
    }




updateAnimationState : Posix -> SharedState -> SharedState
updateAnimationState posix state =
    { state | timestamp = posix }




book : Book SharedState
book "MyApp"
    |> withStatefulOptions [
        subscriptions [
            Browser.Events.onAnimationFrame
                (updateStateWith updateAnimationState)
        ]
    ]

Types

type alias Attribute state =
StatefulOptions state -> StatefulOptions state