-
-
Save luigy/b49ce04de8462e594c9c2b5b455ae5a5 to your computer and use it in GitHub Desktop.
Stop propagation thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Control.Lens hiding (element) | |
import Control.Monad.IO.Class | |
import Data.Map (Map) | |
import Data.Monoid | |
import Data.Proxy | |
import Data.Text (Text) | |
import Reflex.Dom | |
main :: IO () | |
main = mainWidget app | |
app :: forall t m. MonadWidget t m => m () | |
app = do | |
(e, submit) <- elDynAttrWithModifyConfig' | |
(\elCfg -> elCfg & elementConfig_eventSpec %~ | |
addEventSpecFlags (Proxy :: Proxy (DomBuilderSpace m)) Submit (\_ -> preventDefault)) | |
"form" | |
(pure mempty) | |
(button "SUBMIT") | |
performEvent_ $ ffor submit $ \_ -> | |
liftIO $ putStrLn "SUBMIT WAS CLICKED" | |
return () | |
elDynAttrWithModifyConfig' | |
:: (DomBuilder t m, PostBuild t m) | |
=> (ElementConfig EventResult t (DomBuilderSpace m) -> ElementConfig EventResult t (DomBuilderSpace m)) | |
-> Text | |
-> Dynamic t (Map Text Text) | |
-> m a | |
-> m (Element EventResult (DomBuilderSpace m) t, a) | |
elDynAttrWithModifyConfig' f elementTag attrs child = do | |
modifyAttrs <- dynamicAttributesToModifyAttributes attrs | |
let cfg = def & modifyAttributes .~ fmapCheap mapKeysToAttributeName modifyAttrs | |
result <- element elementTag (f cfg) child | |
postBuild <- getPostBuild | |
notReadyUntil postBuild | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment