elm-book icon indicating copy to clipboard operation
elm-book copied to clipboard

Chapter subscriptions

Open Confidenceman02 opened this issue 2 years ago • 0 comments

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
            ]

Confidenceman02 avatar Sep 29 '22 00:09 Confidenceman02