我的榆木代码中有以下这段代码。
type alias Model =
{ content : String
}
update : Msg -> Model -> Model
update msg model =
case msg of
Change newContent ->
{ model | content = newContent }
{ model | content = newContent }
做什么?它是否将newContent
的值分配(绑定)到model
以及content
,这就是为什么|
运算符放在那里的原因?
管道不是case表达式的一部分。它是记录更新语法,如此处所述:https://elm-lang.org/docs/records#updating-records。
{ model | content = newContent }
将newContent
的值分配给content
记录中的model
字段。
阅读|为“ with”。
{模型'with'内容(设置为= newContent}