@@ -240,34 +240,26 @@ emptyElWith' elementTag cfg = do
240240 wrapElement defaultDomEventHandler =<< buildEmptyElementNS (cfg ^. namespace) elementTag (cfg ^. attributes)
241241-}
242242
243−dynamicAttributesToModifyAttributes :: PostBuild t m => Dynamic t (Map Text Text) -> m (Event t (Map AttributeName (Maybe Text)))
244−dynamicAttributesToModifyAttributes d = do
245− postBuild <- getPostBuild
246− let modificationsNeeded = flip pushAlways (align postBuild $ updated d) $ \case
247− This () -> fmap (fmap Just) $ sample $ current d
248− These () new -> return $ fmap Just new
249− That new -> do
250− old <- sample $ current d
251− return $ diffMap old new
252− return $ Map.fromList . fmap (\(k, v) -> ((Nothing, k), v)) . Map.toList <$> modificationsNeeded
253−
254−{-# INLINABLE elDynAttrNS' #-}
255−elDynAttrNS' :: forall t m a. (DomBuilder t m, PostBuild t m) => Maybe Text -> Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
256−elDynAttrNS' mns elementTag attrs child = do
257− modifyAttrs <- dynamicAttributesToModifyAttributes attrs
258− let cfg = def
259− & elementConfig_namespace .~ mns
260− & modifyAttributes .~ modifyAttrs
261− element elementTag cfg child
262−
263−{-# INLINABLE elDynAttr' #-}
264−elDynAttr' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
265−elDynAttr' = elDynAttrNS' Nothing
243+{-# INLINABLE el #-}
244+el :: forall t m a. DomBuilder t m => Text -> m a -> m a
245+el elementTag child = snd <$> el' elementTag child
266246
267247{-# INLINABLE elAttr #-}
268248elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
269249elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
270250
251+{-# INLINABLE elClass #-}
252+elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
253+elClass elementTag c child = snd <$> elClass' elementTag c child
254+
255+{-# INLINABLE elDynAttr #-}
256+elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
257+elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
258+
259+{-# INLINABLE elDynClass #-}
260+elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
261+elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
262+
271263{-# INLINABLE el' #-}
272264el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
273265el' elementTag = element elementTag def
@@ -277,16 +269,37 @@ elAttr' :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m (El
277269elAttr' elementTag attrs = element elementTag $ def
278270 & initialAttributes .~ Map.mapKeys (\k -> (Nothing, k)) attrs
279271
280−{-# INLINABLE elDynAttr #-}
281−elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
282−elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
272+{-# INLINABLE elClass' #-}
273+elClass' :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
274+elClass' elementTag c = elAttr' elementTag ("class" =: c)
283275
284−{-# INLINABLE el #-}
285−el :: forall t m a. DomBuilder t m => Text -> m a -> m a
286−el elementTag child = snd <$> el' elementTag child
276+{-# INLINABLE elDynAttr' #-}
277+elDynAttr' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
278+elDynAttr' = elDynAttrNS' Nothing
287279
288−elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
289−elClass elementTag c child = snd <$> element elementTag (def & initialAttributes .~ (Nothing, "class") =: c) child
280+{-# INLINABLE elDynClass' #-}
281+elDynClass' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
282+elDynClass' elementTag c = elDynAttr' elementTag (fmap ("class" =:) c)
283+
284+{-# INLINABLE elDynAttrNS' #-}
285+elDynAttrNS' :: forall t m a. (DomBuilder t m, PostBuild t m) => Maybe Text -> Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
286+elDynAttrNS' mns elementTag attrs child = do
287+ modifyAttrs <- dynamicAttributesToModifyAttributes attrs
288+ let cfg = def
289+ & elementConfig_namespace .~ mns
290+ & modifyAttributes .~ modifyAttrs
291+ element elementTag cfg child
292+
293+dynamicAttributesToModifyAttributes :: PostBuild t m => Dynamic t (Map Text Text) -> m (Event t (Map AttributeName (Maybe Text)))
294+dynamicAttributesToModifyAttributes d = do
295+ postBuild <- getPostBuild
296+ let modificationsNeeded = flip pushAlways (align postBuild $ updated d) $ \case
297+ This () -> fmap (fmap Just) $ sample $ current d
298+ These () new -> return $ fmap Just new
299+ That new -> do
300+ old <- sample $ current d
301+ return $ diffMap old new
302+ return $ Map.fromList . fmap (\(k, v) -> ((Nothing, k), v)) . Map.toList <$> modificationsNeeded
290303
291304--------------------------------------------------------------------------------
292305-- Copied and pasted from Reflex.Widget.Class