Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggested helper function: bindEvent #259

Open
rprije opened this issue Dec 4, 2018 · 1 comment
Open

suggested helper function: bindEvent #259

rprije opened this issue Dec 4, 2018 · 1 comment

Comments

@rprije
Copy link

rprije commented Dec 4, 2018

Hi. I've found this function quite useful. The naming reflects its similarity to monadic bind but I'm open to suggestions for alternative names:

bindEvent :: (MonadFix m, Adjustable t m, MonadHold t m)
=> m (Event t a) -> (a -> m (Event t b)) -> m (Event t b)
bindEvent first secondFun = do
rec
let becomeSecondEv = fmap secondFun firstEv
(firstEv, secondEvEv) <- runWithReplace first becomeSecondEv
switchEvent secondEvEv

where switchEvent is from reflex-frp/reflex#49:
switchEvent :: (Reflex t, MonadHold t m) => Event t (Event t a) -> m (Event t a)
switchEvent = fmap switch . hold never

I've used it for creating login widgets that behave similarly to Google's (username and password entry are two separate widgets where the second's creation is triggered by the first).

The type is convenient for creating long chains of widgets that dynamically update while carrying along the payload from previous widgets' events.

@dfordivam
Copy link
Member

dfordivam commented Dec 21, 2018

@rprije you may want to implement this in reflex using Reflex.Network APIs..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants