merge and signal detection

72 views
Skip to first unread message

Rolland Bryan

unread,
Dec 11, 2014, 4:03:53 AM12/11/14
to elm-d...@googlegroups.com
I am just starting out with FRP and Elm, so please forgive any stupid questions.

The documentation for merge says 

" ... If an update comes on both signals at the same time, the left update wins. ..."

Does this mean that it's possible to miss signal values such as mouse down transitions?

type Update = MouseDown Bool | TimeDelta Float

updates
: Signal Update
updates
=
    merge
       
(map TimeDelta (fps 1000)) -- One would never do this
       
(map MouseDown Mouse.isDown)
       

Thank you

Jeff Smits

unread,
Dec 11, 2014, 6:03:31 AM12/11/14
to elm-discuss
In the example you give, there would be no missed mouse values. That's because mouse and time are two distinct input sources to the Elm runtime, therefore the events get queued sequentially. 
If you took two things that are both dependent on mouse, it's more likely that the two signals would fire simultaneously and merge would then drop the update from the second argument. 

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Janis Voigtländer

unread,
Dec 11, 2014, 6:03:41 AM12/11/14
to elm-d...@googlegroups.com
Events from two different sources (like Time.fps and Mouse.isDown) do never occur at the same time. The only chance to "miss" something would be if you merge over a combination like (map f Mouse.isDown) and (map g Mouse.isDown), because these both will have an event at the same time, namely whenever Mouse.isDown has an event.

--

Janis Voigtländer

unread,
Dec 11, 2014, 6:06:33 AM12/11/14
to elm-d...@googlegroups.com
Ah, almost the answer I gave as well. However, I assume that "both dependent on mouse" is not enough for a potential conflict. As far as I know, no two "primitive" signals can lead to an event at the same time. So even Mouse.isDown and Mouse.clicks and Mouse.position are guaranteed to not influence each other. Only if two signals are derived from the very same original event source, will they have concurrent events.

Jeff Smits

unread,
Dec 11, 2014, 6:07:53 AM12/11/14
to elm-discuss
I'm not completely sure what the current JS runtime considers primitives, you might be right. 

Rolland Bryan

unread,
Dec 11, 2014, 9:12:51 AM12/11/14
to elm-d...@googlegroups.com
So, it seems that the following would be fine?

type Update = MouseDown Bool | MouseMove (Int, Int)


updates
: Signal Update
updates
=

    merge
       
(map Mouse.position)
       
(map MouseDown Mouse.isDown)

Jeff Smits

unread,
Dec 11, 2014, 9:18:24 AM12/11/14
to elm-discuss
probably ;)

Though you might want to do:


updates : Signal Update
updates =

    merge
        (map MouseMove Mouse.position)
        (map MouseDown Mouse.isDown)

Janis Voigtländer

unread,
Dec 11, 2014, 9:24:31 AM12/11/14
to elm-d...@googlegroups.com
According to all I know (and I did check that a while ago in the runtime for my own use, specifically for the mouse events), yes. Modulo the map-fixing mentioned by Jeff.

Rolland Bryan

unread,
Dec 12, 2014, 2:33:55 AM12/12/14
to elm-d...@googlegroups.com
Thank you Janis and Jeff for the input.
Reply all
Reply to author
Forward
0 new messages