【问题标题】:reactive-banana reactimate to retrieve the widget textCtrl Value like textCtrlGetValuereactive-banana reactimate 检索小部件 textCtrl 值,如 textCtrlGetValue
【发布时间】:2013-03-24 21:26:30
【问题描述】:

我想检索小部件值。

在下面,按下按钮 b 检索 s_in 并在原生 wxhaskell 中打印它。

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

我喜欢对 reactive-banana 做同样的事情,但在下面,我得到的是 "ff" 而不是 s_in2 的 textCtrlGetValue

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

接收器在 s_in 之后会很好地更新 sin_2。 但下面的反应行没有让我得到我希望得到的 s_in/b_in 的 textCtrlGetValue。我怎么才能得到它 ?

【问题讨论】:

    标签: haskell reactive-programming reactive-banana


    【解决方案1】:

    使用behaviorText 函数获得的行为只会对用户 对编辑框所做的更改作出反应。它确实包括程序化更改,例如使用sink 函数执行的更改。

    区分用户事件和编程事件对于编写具有bidirectional data flow 的响应式 UI 元素至关重要。请参阅CurrencyConverter example 进行演示。

    如果您想跟踪程序更改,我建议您留在“FRP 世界中”,即使用行为b_out = id &lt;$&gt; b_in 而不是尝试从小部件中读取文本。

    (顺便说一句,id &lt;$&gt; x = x。)

    【讨论】:

    • 首先感谢您的快速回答。我确实注意到了双向数据流,并想知道为什么它当时没有循环!现在,我知道了,谢谢!我以前没有注意到这种重要的概念分离。现在我跨过的另一个主题(documented here)是如何让模型和 GUI 交互,记住模型不是 GUI 或 WX 特定的(_ 示例中的图不是小部件依赖关系图(典型于FRP) , 而是用图表来表示_)
    猜你喜欢
    • 1970-01-01
    • 2015-11-25
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多