HeinrichApfelmus/reactive-banana — Issue #29: fromPoll IO action activates on any event tied to any sink function.
Author: EvgenijM86
Created: 2012-02-18 15:55:47+00:00
State: open

This is very annoying, because my fileOpenDialog opens on any button press. Is this correct behavior?

Here is a modified example from Arithmetic.hs to illustrate this issue:

```
import Data.Maybe
import Graphics.UI.WX hiding (Event)
import Reactive.Banana
import Reactive.Banana.WX

main = do
gui

gui = start $ do
f <- frame [text := "Arithmetic"]
calculate <- button f [text := "="]
input1 <- entry f [processEnter := True]
input2 <- entry f [processEnter := True]
output <- staticText f [size := sz 40 20]

of1Btn <- button f [text := "Open"]
of2Btn <- button f [text := "Open"]
of1Inp <- entry f []
of2Inp <- entry f []

set f [layout := margin 10 $ column 20
[row 10 [label "Open first torrent", widget of1Inp, widget of1Btn],
row 10 [label "Open second torrent", widget of2Inp, widget of2Btn],
row 10 [widget input1, label "+", widget input2, widget calculate, widget output]]]

network <- compile $ do
eenter1 <- event0 input1 command
eenter2 <- event0 input2 command
ebutton <- event0 calculate command
eof1Btn <- event0 of1Btn command
eof2Btn <- event0 of2Btn command

binput1 <- behavior input1 text
binput2 <- behavior input2 text

bofd <- fromPoll $ fileOpenDialog f True True "Open torrent file"
[("Any file",["*.*"]),("Torrents",["*.torrent"])] "" ""

let
ecalculate :: Event ()
ecalculate = ebutton `union` eenter1 `union` eenter2

result :: Discrete (Maybe Int)
result = stepperD Nothing $
(f <$> binput1 <*> binput2) <@ ecalculate
where
f x y = liftA2 (+) (readNumber x) (readNumber y)
readNumber s = listToMaybe [x | (x,"") <- reads s]
showNumber = maybe "--" show

rOpenFile z = stepperD Nothing (bofd <@ z)
showDir = maybe "--" show

sink output [text :== showNumber <$> result]
sink of1Inp [text :== showDir <$> (rOpenFile eof1Btn)]
sink of2Inp [text :== showDir <$> (rOpenFile eof2Btn)]

actuate network
```

As I understand fromPoll function should only activate on "sink of1Inp" and "sink of2Inp", but it also activates on "sink output".