What does a function with 2 values on the right side mean? (Model -> Html msg)
我在指南中遇到了这个问题:
1 2 3 4 5 6 7 8 9 10 | viewValidation : Model -> Html msg viewValidation model = let (color, message) = if model.password == model.passwordAgain then ("green","OK") else ("red","Passwords do not match!") in div [ style [("color", color)] ] [ text message ] |
这是一个使用
但是,
例如,如果您的HTML中有一个按钮,则它可能看起来像这样:
1 | button [ onClick DoSomething ] [ text"caption" ] |
请勿将类型定义与常规代码执行混合使用。
由于建立的注释
最常见的情况是返回
随着Elm鼓励组件化,您还需要牢记
1 | Html.map : (Child.Msg -> Parent.Msg) -> Html Child.Msg -> Html Parent.Msg |
请注意,当您在父组件中定义消息时,将具有以下内容:
1 | type Msg = ChildMsg Child.Msg |
表示
1 | ChildMsg : Child.Msg -> Parent.Msg |
所以我的视图函数有很多
1 2 3 | parentView model = -- childView model.child |> Html.map ChildMsg Html.map ChildMsg (childView model.child) |