on develop help sign in
Make HasAttributes more polymorphic
commitc24dbf065cfd18de88fd0131649916086ea430bd authorRyan Trinkle <ryan.trinkle@gmail.com> dateFri 4 Sep 2015, 18:38 (11 years ago) parentf2406eb
2 files changed+12−18
src/Reflex/Dom/Widget/Basic.hs+7−9 src/Reflex/Dom/Widget/Input.hs+5−9
src/Reflex/Dom/Widget/Basic.hs+7−9
@@ -1,4 +1,4 @@
1−{-# LANGUAGE ScopedTypeVariables, LambdaCase, ConstraintKinds, TypeFamilies, FlexibleContexts, MultiParamTypeClasses, FlexibleInstances, RecursiveDo, GADTs, DataKinds, RankNTypes, TemplateHaskell #-}
1+{-# LANGUAGE ScopedTypeVariables, LambdaCase, ConstraintKinds, TypeFamilies, FlexibleContexts, MultiParamTypeClasses, FlexibleInstances, RecursiveDo, GADTs, DataKinds, RankNTypes, TemplateHaskell, FunctionalDependencies #-}
22
33module Reflex.Dom.Widget.Basic where
44
@@ -636,11 +636,11 @@ emptyElWith' elementTag cfg = do
636636elDynAttrNS' :: forall t m a. MonadWidget t m => Maybe String -> String -> Dynamic t (Map String String) -> m a -> m (El t, a)
637637elDynAttrNS' mns elementTag attrs = elWith' elementTag $
638638 def & namespace .~ mns
639− & elConfig_attributes .~ attrs
639+ & attributes .~ attrs
640640
641641{-# INLINABLE elDynAttr' #-}
642642elDynAttr' :: forall t m a. MonadWidget t m => String -> Dynamic t (Map String String) -> m a -> m (El t, a)
643−elDynAttr' elementTag attrs = elWith' elementTag $ def & elConfig_attributes .~ attrs
643+elDynAttr' elementTag attrs = elWith' elementTag $ def & attributes .~ attrs
644644
645645{-# INLINABLE elAttr #-}
646646elAttr :: forall t m a. MonadWidget t m => String -> Map String String -> m a -> m a
@@ -656,7 +656,7 @@ elAttr' elementTag attrs = elWith' elementTag $ def & attributes .~ attrs
656656
657657{-# INLINABLE elDynAttr #-}
658658elDynAttr :: forall t m a. MonadWidget t m => String -> Dynamic t (Map String String) -> m a -> m a
659−elDynAttr elementTag attrs = elWith elementTag $ def & elConfig_attributes .~ attrs
659+elDynAttr elementTag attrs = elWith elementTag $ def & attributes .~ attrs
660660
661661{-# INLINABLE el #-}
662662el :: forall t m a. MonadWidget t m => String -> m a -> m a
@@ -698,12 +698,10 @@ data Link t
698698 = Link { _link_clicked :: Event t ()
699699 }
700700
701−class HasAttributes a where
702− type Attrs a :: *
703− attributes :: Lens' a (Attrs a)
701+class HasAttributes s t a b | s -> a, t -> b, s b -> t, t a -> s where
702+ attributes :: Lens s t a b
704703
705−instance HasAttributes (ElConfig attrs) where
706− type Attrs (ElConfig attrs) = attrs
704+instance HasAttributes (ElConfig attrs) (ElConfig attrs') attrs attrs' where
707705 attributes = elConfig_attributes
708706
709707class HasNamespace a where
src/Reflex/Dom/Widget/Input.hs+5−9
@@ -1,4 +1,4 @@
1−{-# LANGUAGE ConstraintKinds, TypeFamilies, FlexibleContexts, DataKinds, GADTs, ScopedTypeVariables, FlexibleInstances, RecursiveDo, TemplateHaskell #-}
1+{-# LANGUAGE ConstraintKinds, TypeFamilies, FlexibleContexts, DataKinds, GADTs, ScopedTypeVariables, FlexibleInstances, RecursiveDo, TemplateHaskell, MultiParamTypeClasses #-}
22module Reflex.Dom.Widget.Input (module Reflex.Dom.Widget.Input, def, (&), (.~)) where
33
44import Prelude
@@ -225,20 +225,16 @@ liftM concat $ mapM makeLenses
225225 , ''Checkbox
226226 ]
227227
228−instance HasAttributes (TextAreaConfig t) where
229− type Attrs (TextAreaConfig t) = Dynamic t (Map String String)
228+instance HasAttributes (TextAreaConfig t) (TextAreaConfig t) (Dynamic t (Map String String)) (Dynamic t (Map String String)) where
230229 attributes = textAreaConfig_attributes
231230
232−instance HasAttributes (TextInputConfig t) where
233− type Attrs (TextInputConfig t) = Dynamic t (Map String String)
231+instance HasAttributes (TextInputConfig t) (TextInputConfig t) (Dynamic t (Map String String)) (Dynamic t (Map String String)) where
234232 attributes = textInputConfig_attributes
235233
236−instance HasAttributes (DropdownConfig t k) where
237− type Attrs (DropdownConfig t k) = Dynamic t (Map String String)
234+instance HasAttributes (DropdownConfig t k) (DropdownConfig t k) (Dynamic t (Map String String)) (Dynamic t (Map String String)) where
238235 attributes = dropdownConfig_attributes
239236
240−instance HasAttributes (CheckboxConfig t) where
241− type Attrs (CheckboxConfig t) = Dynamic t (Map String String)
237+instance HasAttributes (CheckboxConfig t) (CheckboxConfig t) (Dynamic t (Map String String)) (Dynamic t (Map String String)) where
242238 attributes = checkboxConfig_attributes
243239
244240class HasSetValue a where