} init : Foo -> Bar -> Model -> (Model, Cmd Msg) update : Baz -> Msg -> Model -> (Model, Cmd Msg, Event) view : Hoge -> Fuga -> Model -> Html Msg -- Main.elm pass concrete args explicitly -- which makes Main.elm dirty! -- -- Also, an extra event should be introduced -- to modify the global state.
: Session , ... } init : Session -> Model -> (Model, Cmd Msg) update : Msg -> Model -> (Model, Cmd Msg) view : Model -> Html Msg -- Main.elm passes session type which contains -- various contexts such as user/credential, -- cached data, etc.
page = case page of FooPage { session } -> session BarPage { session } -> session ... -- Sometimes `setSession` or `updateSession` -- is also needed...
Msg update session msg model = case msg of NoOp -> return model GetUser -> return model |> withTask (Api.getUser GotUser) GotUser user -> return model |> withSession (Session.setUser user session) |> withCommand ... -- There is no `Cmd.none`. -- -- More abstract than (Model, Cmd Msg), easy to -- extend the data structure.