1

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

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.

-- Edit

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 = []
    }
alpha_cod
  • 1,933
  • 5
  • 25
  • 43
  • 1
    Can you post your code wiring up StartApp? Oftentimes this type of issue shows up when the return value of `start` doesn't also assign `app.tasks` to a port – Chad Gilbert Jan 24 '16 at 16:50
  • I've added the code wiring up StartApp. Please assist me on it. Thanks. – alpha_cod Jan 24 '16 at 18:29
  • I handed over the app.tasks to a port like you mentioned and it worked great. Thanks! :) – alpha_cod Jan 24 '16 at 18:38
  • Oh k, am new to Elm and still making sense of signals, tasks and Effects. Sry abt the duplicate. – alpha_cod Jan 25 '16 at 08:19
  • No worries! The flag is just standard stackoverflow curation. It leaves a paper trail for future visitors to the site who may have similar questions. – Chad Gilbert Jan 25 '16 at 09:38

1 Answers1

1

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!

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
alpha_cod
  • 1,933
  • 5
  • 25
  • 43