Reactive Banana User Interface-wx

How do you get the contents of ui elements when using reactive banana? Event 0 returns an event of type Event () , which has a unit type, not a control type. event1 accepts an event of type Event w (a -> IO ()) , but the command is of type Event w (IO ()) . mapAccumE and mapAccumB accepts pure functions as parameters, so get text foo cannot be used with them.

+6
source share
2 answers

Basically, you want to work with functions instead of data. If you think, β€œHow to create a behavior that has the current text in a field,” you don’t. Instead, you write down functions that take the current text as a parameter, and pass it when necessary. Suppose you want to print the contents of a text field when you click a button. Then you would do something like this:

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

If you need to introduce input into the behavior, you can similarly use a function with the Behavior (String -> a) type Behavior (String -> a) (or any other type you need), and then just pass the string to the reactimate call reactimate .

+4
source

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

Today I discovered that I had excluded a very important function from the library: retrieving the contents of a user interface element as Behavior . Offensive!: - D

John describes the current workaround, but the next version of Jet Banana will include the missing feature.

EDIT: I released reactive banana version 0.4 , which now includes functionality as a function

 fromPoll :: IO a -> NetworkDescription (Behavior a) 
+4
source

Source: https://habr.com/ru/post/891793/


All Articles