2

I'm trying to introduce a new signal into my program which main function looks like this:

main : Signal Html
main =
  Signal.map2 view Window.dimensions model

(more context here)

To design my new signal I'd like to start from this one:

clicks : Signal (Int, Int)
clicks =
  Signal.sampleOn Mouse.clicks Mouse.position

I can get this signal:

Signal.map (Debug.log "click") clicks

But, I'm not sure how to integrate this signal into my program such that it will print a debug message on every click.

What's the simplest way to Debug.log a new signal in an existing Elm program?

glennsl
  • 28,186
  • 12
  • 57
  • 75
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • Note that if you do not use ports, it's more practical to use Debug.watch and elm-reactor instead of logging because you can view the values in temporal context and replay them. – thSoft Nov 02 '15 at 16:40
  • @thSoft I tried to replace `Debug.log` with `Debug.watch`, and rerun `elm reactor`, but I can't see the printouts in reactor's output. What am I missing? – Misha Moroshko Nov 03 '15 at 06:36
  • Please ask a separate question with sharing the whole code and the exact steps you tried. – thSoft Nov 03 '15 at 09:31

1 Answers1

3

Wherever you want to use this clicks signal, you can use (Signal.map (Debug.log "click") clicks) instead.

Since this seems to be another input, you can add a MouseClick action, and Signal.merge the mouse click actions into the general input signal that you have. If that's the place where you want to add your mouse clicks, then that's the place where you add the logging.

Apanatshka
  • 5,958
  • 27
  • 38