Skip to content

Instantly share code, notes, and snippets.

@luigy

luigy/Foo.hs Secret

Last active October 15, 2017 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luigy/b49ce04de8462e594c9c2b5b455ae5a5 to your computer and use it in GitHub Desktop.
Save luigy/b49ce04de8462e594c9c2b5b455ae5a5 to your computer and use it in GitHub Desktop.
Stop propagation thing
{-# 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