Maybe 错误和 Elm 中的嵌套资源
Error with Maybe and nested resources in Elm
我正在构建我的第一个 Elm SPA,我正在不同的文件夹和模块中组织我的组件。一切正常,直到我从这里更改主模型:
type alias Model =
{ contacts : Contacts.Model.Model
, contact : Contact.Model.Model
, route : Routing.Route
}
为此:
type alias Model =
{ contacts : Contacts.Model.Model
, contact : Maybe Contact.Model.Model
, route : Routing.Route
}
我已经在代码库中进行了所有必要的更改以使其正常工作,但我遗漏了一些我找不到的东西,因为在 Update
主模块中我经常遇到此编译错误:
The type annotation for `update` does not match its definition. - The type annotation is saying:
Msg
-> { ..., contact : Maybe Contact.Model.Model }
-> ( { contact : Maybe Contact.Model.Model
, contacts : Contacts.Model.Model
, route : Routing.Route
}
, Cmd Msg
)
But I am inferring that the definition has this type:
Msg
-> { ...
, contact :
{ birth_date : String
, email : String
, first_name : String
, gender : Int
, headline : String
, id : Int
, last_name : String
, location : String
, phone_number : String
, picture : String
}
}
-> ( { contact : Maybe Contact.Model.Model
, contacts : Contacts.Model.Model
, route : Routing.Route
}
, Cmd Msg
)
我好像错过了在某处传递 Maybe Model
但我找不到它。这是更新功能的样子:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ContactsMsg subMsg ->
let
( updatedContacts, cmd ) =
Contacts.Update.update subMsg model.contacts
in
( { model | contacts = updatedContacts, contact = Nothing }, Cmd.map ContactsMsg cmd )
ContactMsg subMsg ->
let
( updatedContact, cmd ) =
Contact.Update.update subMsg model.contact
in
( { model | contact = updatedContact }, Cmd.map ContactMsg cmd )
这是完整的回购协议,有错误:https://github.com/bigardone/phoenix-and-elm/tree/feature/routes-refactoring/web/elm
我做错了什么?非常感谢您!
问题是由 Update.update
函数中的类型不匹配引起的。
update : Msg -> Model -> ( Model, Cmd Msg )
您必须处理 Update.elm
中的 Maybe 值:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ContactsMsg subMsg ->
let
( updatedContacts, cmd ) =
Contacts.Update.update subMsg model.contacts
in
( { model | contacts = updatedContacts, contact = Nothing }
, Cmd.map ContactsMsg cmd
)
ContactMsg subMsg ->
case model.contact of
Just contact ->
let
( updatedContact, cmd ) =
Contact.Update.update subMsg contact
in
( { model | contact = updatedContact }
, Cmd.map ContactMsg cmd
)
Nothing ->
( model, Cmd.none )
我正在构建我的第一个 Elm SPA,我正在不同的文件夹和模块中组织我的组件。一切正常,直到我从这里更改主模型:
type alias Model =
{ contacts : Contacts.Model.Model
, contact : Contact.Model.Model
, route : Routing.Route
}
为此:
type alias Model =
{ contacts : Contacts.Model.Model
, contact : Maybe Contact.Model.Model
, route : Routing.Route
}
我已经在代码库中进行了所有必要的更改以使其正常工作,但我遗漏了一些我找不到的东西,因为在 Update
主模块中我经常遇到此编译错误:
The type annotation for `update` does not match its definition. - The type annotation is saying:
Msg
-> { ..., contact : Maybe Contact.Model.Model }
-> ( { contact : Maybe Contact.Model.Model
, contacts : Contacts.Model.Model
, route : Routing.Route
}
, Cmd Msg
)
But I am inferring that the definition has this type:
Msg
-> { ...
, contact :
{ birth_date : String
, email : String
, first_name : String
, gender : Int
, headline : String
, id : Int
, last_name : String
, location : String
, phone_number : String
, picture : String
}
}
-> ( { contact : Maybe Contact.Model.Model
, contacts : Contacts.Model.Model
, route : Routing.Route
}
, Cmd Msg
)
我好像错过了在某处传递 Maybe Model
但我找不到它。这是更新功能的样子:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ContactsMsg subMsg ->
let
( updatedContacts, cmd ) =
Contacts.Update.update subMsg model.contacts
in
( { model | contacts = updatedContacts, contact = Nothing }, Cmd.map ContactsMsg cmd )
ContactMsg subMsg ->
let
( updatedContact, cmd ) =
Contact.Update.update subMsg model.contact
in
( { model | contact = updatedContact }, Cmd.map ContactMsg cmd )
这是完整的回购协议,有错误:https://github.com/bigardone/phoenix-and-elm/tree/feature/routes-refactoring/web/elm
我做错了什么?非常感谢您!
问题是由 Update.update
函数中的类型不匹配引起的。
update : Msg -> Model -> ( Model, Cmd Msg )
您必须处理 Update.elm
中的 Maybe 值:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ContactsMsg subMsg ->
let
( updatedContacts, cmd ) =
Contacts.Update.update subMsg model.contacts
in
( { model | contacts = updatedContacts, contact = Nothing }
, Cmd.map ContactsMsg cmd
)
ContactMsg subMsg ->
case model.contact of
Just contact ->
let
( updatedContact, cmd ) =
Contact.Update.update subMsg contact
in
( { model | contact = updatedContact }
, Cmd.map ContactMsg cmd
)
Nothing ->
( model, Cmd.none )