elm-book
elm-book copied to clipboard
Chapter subscriptions
Context
Sometimes chapters will produce their own subscriptions or consume libraries which produce subscriptions. Elm-book currently handles subscriptions at the Book
level but does not make available chapter state that may be required for a subscription.
-- SomeChapter.elm
subscriptions : SomeChapterModel -> Sub SomeChapterMsg
subscriptions model =
if model.run then
-- some Sub
else
Sub.none
It seems the ElmBook.StatefulOptions.subscriptions
allows you to modify state after a subscription but not give you access to chapter models when creating one.
Would be great if the chapter state could be passed to the subscription handler in order to achieve the above.
e.g.
bookSubscriptions : SharedState -> Sub msg
bookSubscriptions state =
SomeChapter.subscriptions state.someChapterState |> mapWithElmBookMsgSomehow
book : Book SharedState
book "My Book"
|> withStatefulOptions
[ ElmBook.StatefulOptions.initialState sharedState
, ElmBook.StatefulOptions.subscriptions bookSubscriptions
]