2016-08-27 1 views
0

첫 번째 Elm SPA를 구축 중이며 다른 폴더와 모듈에 구성 요소를 구성하고 있습니다. 이에Elm의 어쩌면 중첩 된 리소스와의 오류

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 
} 

을,하지만 난 누락 나는 Maybe Model 곳의 B를 통과 누락처럼 보이는

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 
    ) 

: 나는 주요 Update 모듈로 인해 찾을 수없는 무언가가 나는 끊임없이이 컴파일 오류를 받고 있어요 나는 그것을 찾을 수 없다. https://github.com/bigardone/phoenix-and-elm/tree/feature/routes-refactoring/web/elm

내가 잘못 뭐하는 거지 :

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) 

여기에 전체의 repo가 ​​오류와 함께,이다 :이 업데이트 기능이 같은 모습입니다? 대단히 감사드립니다!

답변

2

이 문제는 Update.update 함수의 형식이 일치하지 않아 발생합니다. ,

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) 
+0

안녕 @halfzebra, 이것은 실제로했던 일을 대단히 감사합니다 :

update : Msg -> Model -> (Model, Cmd Msg) 

당신은 당신의 Update.elm에 어쩌면 값을 처리 할 필요가! 현재 문제는 'Contact.Update.update' 함수와 올바르게 매핑되지 않는다는 것입니다. 왜냐하면 연락처의 gravatar를 클릭하면 표시 경로를 방문하고 백엔드에서 연락처 데이터를 가져 오는 명령을 실행하지만 doesn 모델을 설정하고 화면에 표시하려면'FetchContactSucceed' 안에 입력하십시오. ( – bigardone

+0

@bigardone Elm을 처음 접한다면 [간단한 예제] (https://github.com/halfzebra/elm)를 확인하는 것이 좋습니다. 예를 들어, 당신이 가지고있는 것은 처음부터 약간 압도적 인 것일 수도있다. – halfzebra