elm - How to filter a Signal on page load -


for sake of learning, i'm trying load content when click on button. far i've managed :

  • reload content when click button.
  • and filter signal when click (if string send not "getperf")

but problem ajax call still triggered once page loads.

here's code:

-- signals & mailbox  inbox : signal.mailbox string inbox =   signal.mailbox "some text"  result : signal.mailbox string result =   signal.mailbox ""  --  view  view : string -> html view msg  =   div [] [     h1 [] [text "mailbox3"],     p [] [text msg],     button       [onclick inbox.address "getperf"]       [text "click perf"],  ]  main : signal html main =   signal.map view result.signal  -- task & effects  port fetchreadme : signal (task http.error ()) port fetchreadme =   inbox.signal     |> signal.filter (\sig -> sig == "getperf" ) "boo"     |> signal.map (\_ -> http.getstring "http://localhost:3000/dates" `andthen` report)   report : string -> task x () report html =   signal.send result.address html 

is there way prevent first ajax call on page load ? (or more idiomatic way of doing ?)

the reason you're getting initial ajax request signal.filter still keeping initial value of "boo" (see signal.filter documentation here). value ignored in next signal.map statement use of underscore parameter, http task still getting returned , that's why see initial ajax request on page load.

instead of using signal.filter, write conditional sends ajax request in correct circumstances, when sig "getperf". , if sig not "getperf" (as in page load), can, in essence, nothing returning task.succeed (). here refactored fetchreadme function these changes:

port fetchreadme : signal (task http.error ()) port fetchreadme =   let     fetchandreport sig =       if sig == "getperf"         http.getstring "http://localhost:3000/dates"           `andthen` report       else         task.succeed ()   in     signal.map fetchandreport inbox.signal 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -