榆木在更新功能中向邮箱发送消息 [英] Elm send message to mailbox in update function
问题描述
我在Elm StartApp MUV框架的更新函数中具有以下Action处理程序。
I've the following Action handler in my update function of Elm StartApp MUV framework.
signupAlertMailbox : Signal.Mailbox String
signupAlertMailbox =
Signal.mailbox ""
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Submit ->
let isInputValid = Dict.foldl (\fieldName fieldState validity -> if validity
then (fieldState == IsOkay)
else validity)
True model.inputState
rnd = log "Input valid" isInputValid
-- in (model, Effects.none)
in if isInputValid
then (model, Signal.send signupAlertMailbox.address "Oh snap! Change a few things up and try submitting again."
|> Effects.task
|> Effects.map (always Submit))
else (model, Signal.send signupAlertMailbox.address "Well done! All input correct!"
|> Effects.task
|> Effects.map (always Submit))
在提交操作上,我可以在浏览器控制台中看到日志消息,但是没有消息发送到signupAlertMailbox。请帮我解决这个问题。
Upon Submit action, I can see the log message in browser console, but no message is being sent to signupAlertMailbox. Please help me with this issue.
-编辑
StartApp按照下面的注释要求连接代码:
The StartApp wiring up code as requested in comment below:
import StartApp exposing (start)
import Time exposing (every, second)
import Pages.Signup.Model
import Pages.Signup.Update exposing (signupAlertMailbox)
import Pages.Signup.View
app =
start
{ init = Pages.Signup.Model.init
, view = Pages.Signup.View.view
, update = Pages.Signup.Update.update
, inputs = []
}
推荐答案
原因是我没有交出应用程序到端口的.tasks将被执行,如Chad Gilbert @ chad-gilbert在上面的评论中所述。谢谢!
The reason was I hadnt handed over the app.tasks to a port for it be executed as mentioned by Chad Gilbert @chad-gilbert in a comment above. Thanks!
我添加了以下部分,并开始通过更新功能在sigupAlertMailbox邮箱中获取这些消息
I added the following section and I started getting those messages in sigupAlertMailbox mailbox from the update function
port tasks : Signal (Task.Task Never ())
port tasks =
app.tasks
这篇关于榆木在更新功能中向邮箱发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!