使用reactive-banana-wx进行UI输入

发布于 2024-11-18 12:29:58 字数 266 浏览 2 评论 0原文

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

How do you get the content of ui elements when using reactive-banana? The event0 returns an event of type Event (), which has unit type instead of the type of the control. event1 takes an event of type Event w (a -> IO ()), but command is of type Event w (IO ()). mapAccumE and mapAccumB takes pure functions as parameters, so get text foo can't be used with them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情感失落者 2024-11-25 12:29:58

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

eButton :: NetworkDescription (Event ())
eButton = event0 button command

network = do
  pressButton <- eButton
  reactimate $ (\() -> get text foo >>= print) <
gt; pressButton

如果你需要将输入输入到行为中,你可以类似地使用类型为 Behavior (String -> a) 的函数(或你需要的任何类型),并且然后只需在 reactimate 调用处传入字符串即可。

Basically, you want to work with functions instead of data. If you're thinking "How do I create a behavior which has the current text in a box", you don't. Instead you write functions that take the current text as a parameter, and pass it in when necessary. Suppose you want to print the contents of a textbox when a button is pressed. Then you would do something like this:

eButton :: NetworkDescription (Event ())
eButton = event0 button command

network = do
  pressButton <- eButton
  reactimate $ (\() -> get text foo >>= print) <
gt; pressButton

If you need to get input into a Behavior, you can similarly use a function with type Behavior (String -> a) (or whatever type you need), and then just pass the string in at the point of the reactimate call.

晌融 2024-11-25 12:29:58

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

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

John 描述了当前的解决方法,但下一个反应式香蕉的版本将包括缺失的功能。

编辑:我已经发布了reactive-banana 版本0.4 现在包含函数形式的功能

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

(Author of reactive-banana speaking. Sorry for the late reply, the possibility of questions being asked here didn't even cross my mind. :-) )

I discovered today that I omitted a very crucial feature from the library: getting the content of a UI element as a Behavior. Embarassing! :-D

John describes the current workaround, but the next version of reactive-banana will include the missing feature.

EDIT: I have released reactive-banana version 0.4 which now includes the functionality in form of a function

fromPoll :: IO a -> NetworkDescription (Behavior a)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文