when (c == 13) $ void $ do trigger UI.click bu...">

Press the button on "Enter".

I would like something like this:

on UI.keydown textfield $ \c -> when (c == 13) $ void $ do
    trigger UI.click button

Namely, is there something that acts as a function triggerthat I just inserted?

+4
source share
1 answer

To have the keys pressed Enter, as if they were button presses, you do not need to start the click literally. Rather, you need an event that fires whenever a key is pressed or clicked. The easiest way to do this, especially if you are already using 3penny FRP compilers (which I wholeheartedly recommend), is through unionWith. With this and some other combinators, the Reactive.Threepennycode might look like this:

-- I'm giving separate names to the events for extra clarity.
let eClick = UI.click button
    eEnter = void $ filterE (== 13) (UI.keydown textfield)
    -- This event is fired whenever `eClick` or `eEnter` happen.
    eGo = unionWith const eClick eEnter

eGo, onEvent, , click.

, eGo newEvent, on :

-- Assuming you are in an `UI` do-block, thus the `liftIO`.
(eGo, fireGo) <- liftIO newEvent
on UI.click button $ \_ -> fireGo ()
on UI.keydown textfield $ \c -> when (c == 13) (fireGo ())
-- Alternatively, you might define an `eEnter` with `filterE`,
-- as in the first example, instead of using `on` and `when`. 

, , FRP-. , , , FRP.

+1

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


All Articles