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 -> ElmBook.Internal.StatefulOptions.StatefulOptions state -> ElmBook.Internal.StatefulOptions.StatefulOptions state
Add an initial state to your book.
type alias SharedState =
{ value : String }
book : Book SharedState
book "MyApp"
|> withStatefulOptions [
initialState { value = "" }
]
subscriptions : List (Platform.Sub.Sub (ElmBook.Internal.Msg.Msg state)) -> ElmBook.Internal.StatefulOptions.StatefulOptions state -> ElmBook.Internal.StatefulOptions.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)
]
]
onDarkModeChange : (Basics.Bool -> state -> state) -> ElmBook.Internal.StatefulOptions.StatefulOptions state -> ElmBook.Internal.StatefulOptions.StatefulOptions state
Change your book's state based on the themes current mode.
This can be useful for showcasing your own dark themed components when using elm-book's dark mode.
type alias SharedState =
{ darkMode : Bool
}
initialState : SharedState
initialState =
{ darkMode = False
}
book : Book SharedState
book "MyApp"
|> withStatefulOptions
[ ElmBook.StatefulOptions.initialState
initialState
, ElmBook.StatefulOptions.onDarkModeChange
(\darkMode state ->
{ state | darkMode = darkMode }
)
]
ElmBook.Internal.StatefulOptions.StatefulOptions state -> ElmBook.Internal.StatefulOptions.StatefulOptions state