發送初始消息時,無法觸發響應消息。發送初始消息時無法觸發響應消息
我有一個按鈕:
button
[ class "register"
, value "Create Account"
, onClick Submit
]
我有以下消息:
type Msg
= Submit
| Response (Result Http.Error JsonProfile)
是通過點擊按鈕調用的消息處理程序如下:
update : Msg -> Form -> (Form, Cmd Msg)
update msg model =
case msg of
Submit ->
(model, runtime.tryRegister model Response)
...
這裏的其他消息處理程序:
update : Msg -> Form -> (Form, Cmd Msg)
update msg model =
case msg of
Submit ->
(model, runtime.tryRegister model Response)
Response (Ok json) ->
(model, Navigation.load <| "/#/portal/1")
Response (Err error) ->
(model, Cmd.none)
我tryRegister實現如下:
tryRegister : Form -> (Result Http.Error JsonProfile -> msg) -> Cmd msg
tryRegister form msg =
let
jsonProfile =
JsonProfile 1 form.firstName form.lastName form.email
newMsg v =
msg
in
Cmd.map (newMsg <| Result.Ok jsonProfile) Cmd.none
這裏的客戶端代碼榆樹模塊上面描述:
onRegistration : Registration.Msg -> Model -> (Model, Cmd Msg)
onRegistration subMsg model =
let
(form, _) =
Registration.update subMsg model.registration
in
case subMsg of
Registration.Submit ->
({ model | registration = form }, Cmd.none)
Registration.Response result ->
case result of
Result.Ok jsonProfile ->
let
newUser =
jsonProfileToProvider jsonProfile
newState =
{ model
| registration = form
, portal =
{ initPortal
| provider = newUser
, requested = Domain.EditProfile
, linksNavigation = False
, sourcesNavigation = False
}
}
in
(newState, Navigation.load <| "/#/portal/" ++ getId newUser.profile.id)
Result.Err _ ->
(model, Cmd.none)
後市展望:
我希望,當我點擊按鈕,導航就會發生。 但是,沒有任何反應,我不明白爲什麼。
源代碼here。
我非常感謝您的詳細解答。我該如何回饋? –