on develop help sign in
feedback updates
commit453d4273c4b9f8f7a72d7c0e2535cbf32ce13109 authorLuigy Leon <luigy@outlook.com> dateThu 16 Jun 2016, 15:50 (10 years ago) parent316314b
3 files changed+16−23
src/Reflex/Dom.hs+2 src/Reflex/Dom/Builder/Static.hs+13−22 src/Reflex/Dom/Internal.hs+1−1
src/Reflex/Dom.hs+2
@@ -1,6 +1,7 @@
11module Reflex.Dom ( module Reflex
22 , module Reflex.Dom.Builder.Class
33 , module Reflex.Dom.Builder.Immediate
4+ , module Reflex.Dom.Builder.Static
45 , module Reflex.Dom.Class
56 , module Reflex.Dom.DynamicWriter
67 , module Reflex.Dom.Internal
@@ -17,6 +18,7 @@ module Reflex.Dom ( module Reflex
1718import Reflex
1819import Reflex.Dom.Builder.Class
1920import Reflex.Dom.Builder.Immediate
21+import Reflex.Dom.Builder.Static
2022import Reflex.Dom.Class
2123import Reflex.Dom.DynamicWriter
2224import Reflex.Dom.Internal
src/Reflex/Dom/Builder/Static.hs+13−22
@@ -13,7 +13,6 @@ import Data.Dependent.Sum (DSum (..))
1313
1414import Data.Monoid
1515import Data.Text (Text)
16−-- import Foreign.JavaScript.TH
1716import qualified Data.Map as Map
1817import Data.Map (Map)
1918import Control.Lens hiding (element)
@@ -98,34 +97,28 @@ instance SupportsStaticDomBuilder t m => DomBuilder t (StaticDomBuilderT t m) wh
9897 type DomBuilderSpace (StaticDomBuilderT t m) = StaticDomSpace
9998 {-# INLINABLE textNode #-}
10099 textNode (TextNodeConfig contents) = StaticDomBuilderT $ do
101− modify . (:) $ constant $ BL.toStrict $ toLazyByteString $ fromHtmlEscapedText contents
100+ modify $ (:) $ constant $ BL.toStrict $ toLazyByteString $ fromHtmlEscapedText contents
102101 return TextNode
103102
104103 {-# INLINABLE element #-}
105104 element elementTag cfg child = do
106− let toAttr (_mns,k) v = let key = encodeUtf8 k; val = BL.toStrict $ toLazyByteString $ fromHtmlEscapedText v in [key <> "=\"" <> val <> "\""]
107− let attrs0 = Map.foldMapWithKey toAttr $ cfg ^. initialAttributes
108− let attrs1 = if null attrs0 then "" else " " <> B8.intercalate " " attrs0
105+ let toAttr (_mns, k) v = encodeUtf8 k <> "=\"" <> (BL.toStrict $ toLazyByteString $ fromHtmlEscapedText v) <> "\""
106+ let attrs = B8.intercalate " " $ Map.foldMapWithKey (\k v -> [toAttr k v]) $ cfg ^. initialAttributes
109107
110108 let tag' = encodeUtf8 elementTag
111− let open' more = constant ("<" <> tag' <> attrs1 <> " ") <> more <> constant ">"
109+ let open' more = constant ("<" <> tag' <> " " <> attrs <> " ") <> more <> constant ">"
112110 let close' = constant $ "</" <> tag' <> ">"
113111
114112 es <- newFanEventWithTrigger $ \_ _ -> return (return ())
115113 StaticDomBuilderT $ do
116114 (result, innerHtml) <- lift $ runStaticDomBuilderT child
117115 initial <- lift $ performEvent $ ffor (cfg ^. modifyAttributes) $ ifoldrM (\r@(mAttrNamespace, n) mv acc -> case mAttrNamespace of
118− Nothing -> do
119− case mv of
120− Just v -> do
121− let [attr'] = toAttr r v
122− return $ " " <> attr'
123− Nothing -> return acc
124− Just ns -> do
125− error $ "modifyAttributes Just " ++ show ns) ""
116+ Nothing -> return $ maybe acc ((" " <>) . toAttr r) mv
117+ Just ns -> error $ "modifyAttributes Just " ++ show ns) ""
126118
127119 -- attributes that were not available till PostBuild was fired
128− -- TODO use map and merge with initial attributes?
120+ -- TODO use Map and merge with initial attributes?
121+ -- also ensure any removed attributes after postbuild are not passed on
129122 extraAttrs <- hold "" initial
130123 modify (open' extraAttrs <> innerHtml <> close' :)
131124 return (Element es (error "Static.element RawElement was used"), result)
@@ -134,7 +127,7 @@ instance SupportsStaticDomBuilder t m => DomBuilder t (StaticDomBuilderT t m) wh
134127 placeholder (PlaceholderConfig toInsertAbove _delete) = StaticDomBuilderT $ do
135128 result <- lift $ performEvent (fmap runStaticDomBuilderT toInsertAbove)
136129 acc <- foldDyn (:) [] (fmap snd result)
137− modify . (:) $ join $ fmap (mconcat . reverse) $ current acc
130+ modify $ (:) $ join $ fmap (mconcat . reverse) $ current acc
138131 return $ Placeholder (fmap fst result) never
139132
140133 {-# INLINABLE inputElement #-}
@@ -142,17 +135,15 @@ instance SupportsStaticDomBuilder t m => DomBuilder t (StaticDomBuilderT t m) wh
142135 (e, _result) <- element "input" (cfg ^. inputElementConfig_elementConfig) $ return ()
143136 let v0 = constDyn $ cfg ^. inputElementConfig_initialValue
144137 let c0 = constDyn $ cfg ^. inputElementConfig_initialChecked
145− let valueChangedByUI = never
146− let hasFocus = constDyn False -- XXX should this coming from initialAtttributes
147− return $ InputElement v0 c0 valueChangedByUI hasFocus e
138+ let hasFocus = constDyn False -- TODO should this be coming from initialAtttributes
139+ return $ InputElement v0 c0 never hasFocus e
148140
149141 {-# INLINABLE textAreaElement #-}
150142 textAreaElement cfg = do
151143 (e, _domElement) <- element "textarea" (cfg ^. textAreaElementConfig_elementConfig) $ return ()
152144 let v0 = constDyn $ cfg ^. textAreaElementConfig_initialValue
153− let valueChangedByUI = never
154− let hasFocus = constDyn False -- XXX should this be coming from initialAtttributes
155− return $ TextAreaElement v0 valueChangedByUI hasFocus e
145+ let hasFocus = constDyn False -- TODO should this be coming from initialAtttributes
146+ return $ TextAreaElement v0 never hasFocus e
156147
157148--TODO: Make this more abstract --TODO: Put the WithWebView underneath PerformEventT - I think this would perform better
158149type StaticWidget x = PostBuildT Spider (StaticDomBuilderT Spider (PerformEventT Spider (SpiderHost Global)))
src/Reflex/Dom/Internal.hs+1−1
@@ -129,7 +129,7 @@ attachWidgetFragment' rootElement wv w = do
129129 liftIO $ forM_ ers $ \(_ :=> TriggerInvocation _ cb) -> cb
130130 return ()
131131 setInnerHTML rootElement $ Just (""::String)
132− appendChild rootElement (Just df)
132+ appendChild rootElement $ Just df
133133 return (result, fc)
134134
135135data AppInput t = AppInput