on develop help sign in
Add buildElementNS, buildEmptyElement, and buildEmptyElementNS
commit15aab524406737a51597785e0a2f746499b4efe0 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSat 6 Aug 2016, 18:35 (10 years ago) parent0b68017
1 file changed+19−3
src/Reflex/Dom/Old.hs+19−3
src/Reflex/Dom/Old.hs+19−3
@@ -11,6 +11,9 @@ module Reflex.Dom.Old
1111 , addVoidAction
1212 , AttributeMap
1313 , Attributes (..)
14+ , buildElement
15+ , buildEmptyElement
16+ , buildEmptyElementNS
1417 ) where
1518
1619import Control.Arrow ((***))
@@ -68,11 +71,22 @@ addVoidAction = performEvent_
6871
6972type AttributeMap = Map String String
7073
74+buildElement :: Attributes m attrs => String -> attrs -> m a -> m (DOM.Element, a)
75+buildElement = buildElementNS Nothing
76+
77+buildEmptyElement :: Monad m => Attributes m attrs => String -> attrs -> m DOM.Element
78+buildEmptyElement elementTag attrs = fst <$> buildElementNS Nothing elementTag attrs blank
79+
80+buildEmptyElementNS :: Monad m => Attributes m attrs => Maybe String -> String -> attrs -> m DOM.Element
81+buildEmptyElementNS ns elementTag attrs = fst <$> buildElementNS ns elementTag attrs blank
82+
7183class Attributes m attrs where
72− buildElement :: String -> attrs -> m a -> m (DOM.Element, a)
84+ buildElementNS :: Maybe String -> String -> attrs -> m a -> m (DOM.Element, a)
7385
7486instance MonadWidget t m => Attributes m (Map String String) where
75− buildElement elementTag attrs child = buildElementInternal elementTag child =<< addStaticAttributes attrs def
87+ buildElementNS ns elementTag attrs child = do
88+ let cfg = def & elementConfig_namespace .~ fmap T.pack ns
89+ buildElementInternal elementTag child =<< addStaticAttributes attrs cfg
7690
7791addStaticAttributes :: Applicative m => Map String String -> ElementConfig er t m -> m (ElementConfig er t m)
7892addStaticAttributes attrs cfg = do
@@ -80,7 +94,9 @@ addStaticAttributes attrs cfg = do
8094 pure $ cfg & elementConfig_initialAttributes .~ initialAttrs
8195
8296instance MonadWidget t m => Attributes m (Dynamic t (Map String String)) where
83− buildElement elementTag attrs child = buildElementInternal elementTag child =<< addDynamicAttributes attrs def
97+ buildElementNS ns elementTag attrs child = do
98+ let cfg = def & elementConfig_namespace .~ fmap T.pack ns
99+ buildElementInternal elementTag child =<< addDynamicAttributes attrs cfg
84100
85101addDynamicAttributes :: PostBuild t m => Dynamic t (Map String String) -> ElementConfig er t m -> m (ElementConfig er t m)
86102addDynamicAttributes attrs cfg = do