使用reactive-banana-wx进行UI输入
使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您希望使用函数而不是数据。如果您在想“如何创建一个在框中包含当前文本的行为”,那么您不会。相反,您可以编写将当前文本作为参数的函数,并在必要时将其传入。假设您想在按下按钮时打印文本框的内容。然后你会做这样的事情:
如果你需要将输入输入到行为中,你可以类似地使用类型为 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:
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 thereactimate
call.(reactive-banana 的作者发言。很抱歉回复晚了,可能会提出问题我什至没有想到。:-) )
今天我发现我忽略了库中的一个非常重要的功能:将 UI 元素的内容作为
行为
获取。尴尬! :-DJohn 描述了当前的解决方法,但下一个反应式香蕉的版本将包括缺失的功能。
编辑:我已经发布了reactive-banana 版本0.4 现在包含函数形式的功能
(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! :-DJohn 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