【问题标题】:UI input with reactive-banana-wx使用 reactive-banana-wx 的 UI 输入
【发布时间】:2011-07-01 06:52:21
【问题描述】:

使用reactive-banana时如何获取ui元素的内容? event0 返回一个Event () 类型的事件,它具有单元类型而不是控件的类型。 event1 接受Event w (a -> IO ()) 类型的事件,但命令的类型为Event w (IO ())。 mapAccumE 和 mapAccumB 将纯函数作为参数,因此get text foo 不能与它们一起使用。

【问题讨论】:

    标签: haskell reactive-programming reactive-banana


    【解决方案1】:

    基本上,您希望使用函数而不是数据。如果您正在考虑“我如何创建一个在框中包含当前文本的行为”,那么您不会。相反,您编写将当前文本作为参数的函数,并在必要时将其传入。假设您想在按下按钮时打印文本框的内容。然后你会做这样的事情:

    eButton :: NetworkDescription (Event ())
    eButton = event0 button command
    
    network = do
      pressButton <- eButton
      reactimate $ (\() -> get text foo >>= print) <$> pressButton
    

    如果您需要输入行为,您可以类似地使用类型为Behavior (String -&gt; a)(或您需要的任何类型)的函数,然后只需在reactimate 调用点传递字符串。

    【讨论】:

      【解决方案2】:

      reactive-banana 的作者发言。抱歉回复晚了,我什至没有想到这里提出问题的可能性。:-))

      我今天发现我从库中遗漏了一个非常重要的功能:将 UI 元素的内容作为 Behavior 获取。尴尬! :-D

      John 描述了当前的解决方法,但是下一个版本的 reactive-banana 将包含缺失的功能。

      编辑:我已经发布了响应式香蕉 version 0.4,它现在包含函数形式的功能

      fromPoll :: IO a -> NetworkDescription (Behavior a)
      

      【讨论】:

        猜你喜欢
        • 2012-11-14
        • 2015-11-25
        • 1970-01-01
        • 2018-11-02
        • 2012-06-03
        • 2015-12-31
        • 2013-02-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多