4

I would like to retrieve the widget value.

In the following, pressing the button b retrieve s_in and print it , in native wxhaskell.

b <- button f [text:= "print text in console", 
               on command := textCtrlGetValue s_in >>= putStrLn]

I like to do the same on reactive-banana , but in the following, I get "ff" and not the textCtrlGetValue of s_in2

s_in  <- textCtrl f  []
s_in2 <- textCtrl f  []

b <- button f [text:= "print text in console", 
               on command := textCtrlGetValue s_in >>= putStrLn]



let networkDescription :: forall t. Frameworks t => Moment t ()
    networkDescription = do

    b_in  <- behaviorText s_in "init"
    b_in2 <- behaviorText s_in2 "ff"
    e_butt <- event0 b command


    -- I need an event, triggered by the button, and filled by the b_in2, 

    sink s_in2 [text :== id <$> b_in]     

    reactimate $   (\x -> putStrLn x)  <$> b_in2 <@ e_butt

the sink updates well sin_2 after s_in . but the following reactimate line does not get me the textCtrlGetValue of s_in/ b_in I wish to get . how can I "get" it ?

Luc Taesch
  • 193
  • 6

1 Answers1

3

The behavior obtained with the behaviorText function will only react to changes that the user made to the edit box. It does not include programmatic changes, like those performed with the sink function.

Distinguishing between user events and programmatic events is essential for writing responsive UI elements that have bidirectional data flow. See the CurrencyConverter example for a demonstration.

If you want to keep track of programmatic changes, I recommend to stay "within the FRP world", i.e. to use the behavior b_out = id <$> b_in instead of trying to read the text from the widget.

(By the way, id <$> x = x.)

Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67
  • First thanks for the quick answer. I did noticed the bidirectional dataflow, and wondered why it did not loop, at that time ! Now, I know, thanks ! I did not noticed this important separation of concepts before. Now another topic I crossed ( [documented here](http://stackoverflow.com/questions/15758975/separating-state-for-a-model-and-gui-io-wx-stack-or-frp) ) is how can I have a Model and a GUI interact, bearing in mind the model is not GUI or WX specific ( _ the graph in the example is not the graph of widget dependencies (typical in FRP) , but the graph of the diagram to represent_ ) – Luc Taesch Apr 02 '13 at 12:20