3 ms·
Reflex is a frontend library for haskell. -- create an input text widget with auto clean on return and return an event firing on return -- containing t
by Tarean 9y ago
Reflex is a frontend library for haskell.
-- create an input text widget with auto clean on return and return an event firing on return
-- containing the string before clean
inputW :: MonadWidget t m => m (Event t T.Text)
inputW = do
rec
-- fire send event when pressing enter
let send = textInputGetEnter input
-- textInput with content reset on send
input <- textInput $ def & setValue .~ ("" <$ send)
-- tag the send signal with the inputText value BEFORE resetting
return $ tag (current $ input ^. textInput_value) send
Ignoring the operator soup for a second (thanks lens) you might notice that the send event depends on the input field and the content of the input field depends on the send event. In, say, java you would first create the field and then mutate it separately. In haskell mutating wouldn't work so instead we usually tie the knot which means making the value dependent on itself and letting laziness figure it out.
However we are creating a text field here so if we make the value recursive on itself we are gonna be spawning text fields all over the place. MonadFix is variant of this that splices the effect out so it is only run once and then allows the value to be recursive.