on develop help sign in
Add use-template-haskell flag
0fd331bHamish Mackenzie
reflex-dom.cabal+14−3
@@ -19,6 +19,11 @@ extra-source-files: src-ghc/Reflex/Dom/Xhr/Foreign.hs
19 src/Reflex/Dom/Xhr/ResponseType.hs
19 src/Reflex/Dom/Xhr/ResponseType.hs
20 src/Reflex/Dom/Xhr/Exception.hs
20 src/Reflex/Dom/Xhr/Exception.hs
21
21
22+flag use-template-haskell
23+ description: Use template haskell to generate lenses
24+ default: True
25+ manual: True
26+
22flag use-reflex-optimizer
27flag use-reflex-optimizer
23 description: Use the GHC plugin Reflex.Optimizer on some of the modules in the package. This is still experimental.
28 description: Use the GHC plugin Reflex.Optimizer on some of the modules in the package. This is still experimental.
24 default: False
29 default: False
@@ -37,10 +42,10 @@ library
37 contravariant >= 1.4 && < 1.5,
42 contravariant >= 1.4 && < 1.5,
38 data-default >= 0.5 && < 0.8,
43 data-default >= 0.5 && < 0.8,
39 dependent-map == 0.2.*,
44 dependent-map == 0.2.*,
40− dependent-sum == 0.4.*,
45+ dependent-sum == 0.3.*,
41 directory == 1.2.*,
46 directory == 1.2.*,
42 exception-transformers == 0.4.*,
47 exception-transformers == 0.4.*,
43− ghcjs-dom >= 0.6.0.0 && < 0.7,
48+ ghcjs-dom >= 0.7.0.0 && < 0.8,
44 -- keycode-0.2 has a bug on firefox
49 -- keycode-0.2 has a bug on firefox
45 keycode >= 0.2.1 && < 0.3,
50 keycode >= 0.2.1 && < 0.3,
46 lens >= 4.7 && < 5,
51 lens >= 4.7 && < 5,
@@ -68,7 +73,7 @@ library
68 else
73 else
69 hs-source-dirs: src-ghc
74 hs-source-dirs: src-ghc
70 build-depends:
75 build-depends:
71− jsaddle >=0.6.0.0 && <0.7
76+ jsaddle >=0.7.0.0 && <0.8
72 if !os(windows)
77 if !os(windows)
73 build-depends: unix == 2.7.*
78 build-depends: unix == 2.7.*
74
79
@@ -104,6 +109,12 @@ library
104 if flag(use-reflex-optimizer)
109 if flag(use-reflex-optimizer)
105 ghc-options: -fplugin=Reflex.Optimizer
110 ghc-options: -fplugin=Reflex.Optimizer
106
111
112+ if flag(use-template-haskell)
113+ build-depends:
114+ dependent-sum-template >= 0.0.0.5 && < 0.1
115+ other-extensions: TemplateHaskell
116+ cpp-options: -DUSE_TEMPLATE_HASKELL
117+
107--test-suite hlint
118--test-suite hlint
108-- build-depends: base, hlint == 1.9.*
119-- build-depends: base, hlint == 1.9.*
109-- hs-source-dirs: test
120-- hs-source-dirs: test
src-ghcjs/Reflex/Dom/Internal/Foreign.hs+1−1
@@ -18,7 +18,7 @@ import JavaScript.TypedArray.ArrayBuffer as JS
18data WebView = WebView
18data WebView = WebView
19
19
20runWebGUI :: ((WebView, JSContextRef) -> IO ()) -> IO ()
20runWebGUI :: ((WebView, JSContextRef) -> IO ()) -> IO ()
21−runWebGUI main = run 0 (main (WebView, ()))
21+runWebGUI main = main (WebView, ())
22
22
23quitWebView :: WebView -> IO ()
23quitWebView :: WebView -> IO ()
24quitWebView = error "quitWebView: unimplemented in GHCJS"
24quitWebView = error "quitWebView: unimplemented in GHCJS"
src/Foreign/JavaScript/TH.hs+6−1
@@ -9,6 +9,9 @@
9{-# LANGUAGE MultiParamTypeClasses #-}
9{-# LANGUAGE MultiParamTypeClasses #-}
10{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE StandaloneDeriving #-}
11{-# LANGUAGE StandaloneDeriving #-}
12+#ifdef USE_TEMPLATE_HASKELL
13+{-# LANGUAGE TemplateHaskell #-}
14+#endif
12{-# LANGUAGE TypeFamilies #-}
15{-# LANGUAGE TypeFamilies #-}
13{-# LANGUAGE TypeSynonymInstances #-}
16{-# LANGUAGE TypeSynonymInstances #-}
14{-# LANGUAGE UndecidableInstances #-}
17{-# LANGUAGE UndecidableInstances #-}
@@ -53,6 +56,8 @@ import Data.Word
53import Foreign.C.Types
56import Foreign.C.Types
54import Foreign.Ptr
57import Foreign.Ptr
55import Text.Encoding.Z
58import Text.Encoding.Z
59+
60+import Reflex.Dom.Internal.Foreign (WebView)
56#else
61#else
57import Data.Word (Word8)
62import Data.Word (Word8)
58import Control.Lens.Operators ((^.))
63import Control.Lens.Operators ((^.))
@@ -490,7 +495,7 @@ instance ToJS x Node where
490 withJS = withJSNode
495 withJS = withJSNode
491
496
492
497
493−#if 0
498+#ifdef USE_TEMPLATE_HASKELL
494
499
495importJS :: Safety -> String -> String -> Q Type -> Q [Dec]
500importJS :: Safety -> String -> String -> Q Type -> Q [Dec]
496importJS safety body name qt = do
501importJS safety body name qt = do
src/Reflex/Dom/Builder/Class.hs+30
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DefaultSignatures #-}
4{-# LANGUAGE DefaultSignatures #-}
@@ -12,6 +13,9 @@
12{-# LANGUAGE RankNTypes #-}
13{-# LANGUAGE RankNTypes #-}
13{-# LANGUAGE RecursiveDo #-}
14{-# LANGUAGE RecursiveDo #-}
14{-# LANGUAGE ScopedTypeVariables #-}
15{-# LANGUAGE ScopedTypeVariables #-}
16+#ifdef USE_TEMPLATE_HASKELL
17+{-# LANGUAGE TemplateHaskell #-}
18+#endif
15{-# LANGUAGE TypeFamilies #-}
19{-# LANGUAGE TypeFamilies #-}
16{-# LANGUAGE UndecidableInstances #-}
20{-# LANGUAGE UndecidableInstances #-}
17module Reflex.Dom.Builder.Class
21module Reflex.Dom.Builder.Class
@@ -150,6 +154,7 @@ data TextNodeConfig t
150 , _textNodeConfig_setContents :: Event t Text
154 , _textNodeConfig_setContents :: Event t Text
151 }
155 }
152
156
157+#ifndef USE_TEMPLATE_HASKELL
153textNodeConfig_initialContents :: Lens' (TextNodeConfig t) Text
158textNodeConfig_initialContents :: Lens' (TextNodeConfig t) Text
154textNodeConfig_initialContents f (TextNodeConfig a b) = (\a' -> TextNodeConfig a' b) <$> f a
159textNodeConfig_initialContents f (TextNodeConfig a b) = (\a' -> TextNodeConfig a' b) <$> f a
155{-# INLINE textNodeConfig_initialContents #-}
160{-# INLINE textNodeConfig_initialContents #-}
@@ -160,6 +165,7 @@ textNodeConfig_setContents :: Lens
160 (Event t2 Text)
165 (Event t2 Text)
161textNodeConfig_setContents f (TextNodeConfig a b) = (\b' -> TextNodeConfig a b') <$> f b
166textNodeConfig_setContents f (TextNodeConfig a b) = (\b' -> TextNodeConfig a b') <$> f b
162{-# INLINE textNodeConfig_setContents #-}
167{-# INLINE textNodeConfig_setContents #-}
168+#endif
163
169
164instance (Reflex t) => Default (TextNodeConfig t) where
170instance (Reflex t) => Default (TextNodeConfig t) where
165 {-# INLINABLE def #-}
171 {-# INLINABLE def #-}
@@ -225,6 +231,7 @@ data ElementConfig er t m
225 , _elementConfig_eventSpec :: EventSpec (DomBuilderSpace m) er
231 , _elementConfig_eventSpec :: EventSpec (DomBuilderSpace m) er
226 }
232 }
227
233
234+#ifndef USE_TEMPLATE_HASKELL
228elementConfig_namespace :: Lens' (ElementConfig er t m) (Maybe Namespace)
235elementConfig_namespace :: Lens' (ElementConfig er t m) (Maybe Namespace)
229elementConfig_namespace f (ElementConfig a b c d) = (\a' -> ElementConfig a' b c d) <$> f a
236elementConfig_namespace f (ElementConfig a b c d) = (\a' -> ElementConfig a' b c d) <$> f a
230{-# INLINE elementConfig_namespace #-}
237{-# INLINE elementConfig_namespace #-}
@@ -245,6 +252,7 @@ elementConfig_eventSpec :: Lens
245 (EventSpec (DomBuilderSpace m2) er2)
252 (EventSpec (DomBuilderSpace m2) er2)
246elementConfig_eventSpec f (ElementConfig a b c d) = (\d' -> ElementConfig a b c d') <$> f d
253elementConfig_eventSpec f (ElementConfig a b c d) = (\d' -> ElementConfig a b c d') <$> f d
247{-# INLINE elementConfig_eventSpec #-}
254{-# INLINE elementConfig_eventSpec #-}
255+#endif
248
256
249data Element er d t
257data Element er d t
250 = Element { _element_events :: EventSelector t (WrapArg er EventName) --TODO: EventSelector should have two arguments
258 = Element { _element_events :: EventSelector t (WrapArg er EventName) --TODO: EventSelector should have two arguments
@@ -256,6 +264,7 @@ data PlaceholderConfig above t m
256 , _placeholderConfig_deleteSelf :: Event t ()
264 , _placeholderConfig_deleteSelf :: Event t ()
257 }
265 }
258
266
267+#ifndef USE_TEMPLATE_HASKELL
259placeholderConfig_insertAbove :: Lens
268placeholderConfig_insertAbove :: Lens
260 (PlaceholderConfig above1 t m1)
269 (PlaceholderConfig above1 t m1)
261 (PlaceholderConfig above2 t m2)
270 (PlaceholderConfig above2 t m2)
@@ -266,6 +275,7 @@ placeholderConfig_insertAbove f (PlaceholderConfig a b) = (\a' -> PlaceholderCon
266placeholderConfig_deleteSelf :: Lens' (PlaceholderConfig above t m) (Event t ())
275placeholderConfig_deleteSelf :: Lens' (PlaceholderConfig above t m) (Event t ())
267placeholderConfig_deleteSelf f (PlaceholderConfig a b) = (\b' -> PlaceholderConfig a b') <$> f b
276placeholderConfig_deleteSelf f (PlaceholderConfig a b) = (\b' -> PlaceholderConfig a b') <$> f b
268{-# INLINE placeholderConfig_deleteSelf #-}
277{-# INLINE placeholderConfig_deleteSelf #-}
278+#endif
269
279
270instance Reflex t => Default (PlaceholderConfig above t m) where
280instance Reflex t => Default (PlaceholderConfig above t m) where
271 {-# INLINABLE def #-}
281 {-# INLINABLE def #-}
@@ -287,6 +297,7 @@ data InputElementConfig er t m
287 , _inputElementConfig_elementConfig :: ElementConfig er t m
297 , _inputElementConfig_elementConfig :: ElementConfig er t m
288 }
298 }
289
299
300+#ifndef USE_TEMPLATE_HASKELL
290inputElementConfig_initialValue :: Lens' (InputElementConfig er t m) Text
301inputElementConfig_initialValue :: Lens' (InputElementConfig er t m) Text
291inputElementConfig_initialValue f (InputElementConfig a b c d e) = (\a' -> InputElementConfig a' b c d e) <$> f a
302inputElementConfig_initialValue f (InputElementConfig a b c d e) = (\a' -> InputElementConfig a' b c d e) <$> f a
292{-# INLINE inputElementConfig_initialValue #-}
303{-# INLINE inputElementConfig_initialValue #-}
@@ -306,6 +317,7 @@ inputElementConfig_elementConfig :: Lens
306 (ElementConfig er2 t m2)
317 (ElementConfig er2 t m2)
307inputElementConfig_elementConfig f (InputElementConfig a b c d e) = (\e' -> InputElementConfig a b c d e') <$> f e
318inputElementConfig_elementConfig f (InputElementConfig a b c d e) = (\e' -> InputElementConfig a b c d e') <$> f e
308{-# INLINE inputElementConfig_elementConfig #-}
319{-# INLINE inputElementConfig_elementConfig #-}
320+#endif
309
321
310instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (InputElementConfig er t m) where
322instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (InputElementConfig er t m) where
311 {-# INLINABLE def #-}
323 {-# INLINABLE def #-}
@@ -334,6 +346,7 @@ data TextAreaElementConfig er t m
334 , _textAreaElementConfig_elementConfig :: ElementConfig er t m
346 , _textAreaElementConfig_elementConfig :: ElementConfig er t m
335 }
347 }
336
348
349+#ifndef USE_TEMPLATE_HASKELL
337textAreaElementConfig_initialValue :: Lens' (TextAreaElementConfig er t m) Text
350textAreaElementConfig_initialValue :: Lens' (TextAreaElementConfig er t m) Text
338textAreaElementConfig_initialValue f (TextAreaElementConfig a b c) = (\a' -> TextAreaElementConfig a' b c) <$> f a
351textAreaElementConfig_initialValue f (TextAreaElementConfig a b c) = (\a' -> TextAreaElementConfig a' b c) <$> f a
339{-# INLINE textAreaElementConfig_initialValue #-}
352{-# INLINE textAreaElementConfig_initialValue #-}
@@ -347,6 +360,7 @@ textAreaElementConfig_elementConfig :: Lens
347 (ElementConfig er2 t m2)
360 (ElementConfig er2 t m2)
348textAreaElementConfig_elementConfig f (TextAreaElementConfig a b c) = (\c' -> TextAreaElementConfig a b c') <$> f c
361textAreaElementConfig_elementConfig f (TextAreaElementConfig a b c) = (\c' -> TextAreaElementConfig a b c') <$> f c
349{-# INLINE textAreaElementConfig_elementConfig #-}
362{-# INLINE textAreaElementConfig_elementConfig #-}
363+#endif
350
364
351instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (TextAreaElementConfig er t m) where
365instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (TextAreaElementConfig er t m) where
352 {-# INLINABLE def #-}
366 {-# INLINABLE def #-}
@@ -375,6 +389,7 @@ data RawElementConfig er t m = RawElementConfig
375 , _rawElementConfig_eventSpec :: EventSpec (DomBuilderSpace m) er
389 , _rawElementConfig_eventSpec :: EventSpec (DomBuilderSpace m) er
376 }
390 }
377
391
392+#ifndef USE_TEMPLATE_HASKELL
378rawElementConfig_modifyAttributes :: Lens
393rawElementConfig_modifyAttributes :: Lens
379 (RawElementConfig er t1 m)
394 (RawElementConfig er t1 m)
380 (RawElementConfig er t2 m)
395 (RawElementConfig er t2 m)
@@ -389,6 +404,7 @@ rawElementConfig_eventSpec :: Lens
389 (EventSpec (DomBuilderSpace m2) er2)
404 (EventSpec (DomBuilderSpace m2) er2)
390rawElementConfig_eventSpec f (RawElementConfig a b) = (\b' -> RawElementConfig a b') <$> f b
405rawElementConfig_eventSpec f (RawElementConfig a b) = (\b' -> RawElementConfig a b') <$> f b
391{-# INLINE rawElementConfig_eventSpec #-}
406{-# INLINE rawElementConfig_eventSpec #-}
407+#endif
392
408
393instance (Reflex t, DomSpace (DomBuilderSpace m)) => Default (RawElementConfig EventResult t m) where
409instance (Reflex t, DomSpace (DomBuilderSpace m)) => Default (RawElementConfig EventResult t m) where
394 def = RawElementConfig
410 def = RawElementConfig
@@ -402,6 +418,7 @@ data SelectElementConfig er t m = SelectElementConfig
402 , _selectElementConfig_elementConfig :: ElementConfig er t m
418 , _selectElementConfig_elementConfig :: ElementConfig er t m
403 }
419 }
404
420
421+#ifndef USE_TEMPLATE_HASKELL
405selectElementConfig_initialValue :: Lens' (SelectElementConfig er t m) Text
422selectElementConfig_initialValue :: Lens' (SelectElementConfig er t m) Text
406selectElementConfig_initialValue f (SelectElementConfig a b c) = (\a' -> SelectElementConfig a' b c) <$> f a
423selectElementConfig_initialValue f (SelectElementConfig a b c) = (\a' -> SelectElementConfig a' b c) <$> f a
407{-# INLINE selectElementConfig_initialValue #-}
424{-# INLINE selectElementConfig_initialValue #-}
@@ -415,6 +432,7 @@ selectElementConfig_elementConfig :: Lens
415 (ElementConfig er2 t m2)
432 (ElementConfig er2 t m2)
416selectElementConfig_elementConfig f (SelectElementConfig a b c) = (\c' -> SelectElementConfig a b c') <$> f c
433selectElementConfig_elementConfig f (SelectElementConfig a b c) = (\c' -> SelectElementConfig a b c') <$> f c
417{-# INLINE selectElementConfig_elementConfig #-}
434{-# INLINE selectElementConfig_elementConfig #-}
435+#endif
418
436
419instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (SelectElementConfig er t m) where
437instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (SelectElementConfig er t m) where
420 def = SelectElementConfig
438 def = SelectElementConfig
@@ -431,6 +449,18 @@ data SelectElement er d t = SelectElement
431 , _selectElement_raw :: RawSelectElement d
449 , _selectElement_raw :: RawSelectElement d
432 }
450 }
433
451
452+#ifdef USE_TEMPLATE_HASKELL
453+concat <$> mapM makeLenses
454+ [ ''TextNodeConfig
455+ , ''ElementConfig
456+ , ''PlaceholderConfig
457+ , ''InputElementConfig
458+ , ''TextAreaElementConfig
459+ , ''SelectElementConfig
460+ , ''RawElementConfig
461+ ]
462+#endif
463+
434class CanDeleteSelf t a | a -> t where
464class CanDeleteSelf t a | a -> t where
435 deleteSelf :: Lens' a (Event t ())
465 deleteSelf :: Lens' a (Event t ())
436
466
src/Reflex/Dom/Builder/Class/Events.hs+13−1
@@ -1,13 +1,21 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE GADTs #-}
3{-# LANGUAGE GADTs #-}
3{-# LANGUAGE KindSignatures #-}
4{-# LANGUAGE KindSignatures #-}
4{-# LANGUAGE PolyKinds #-}
5{-# LANGUAGE PolyKinds #-}
6+#ifdef USE_TEMPLATE_HASKELL
7+{-# LANGUAGE TemplateHaskell #-}
8+#endif
5{-# LANGUAGE TypeFamilies #-}
9{-# LANGUAGE TypeFamilies #-}
6module Reflex.Dom.Builder.Class.Events where
10module Reflex.Dom.Builder.Class.Events where
7
11
12+#ifdef USE_TEMPLATE_HASKELL
13+import Data.GADT.Compare.TH
14+#else
8import Data.GADT.Compare
15import Data.GADT.Compare
9 (GOrdering(..), (:~:)(..), GEq(..), GCompare(..))
16 (GOrdering(..), (:~:)(..), GEq(..), GCompare(..))
10import Control.Monad (ap)
17import Control.Monad (ap)
18+#endif
11
19
12data EventTag
20data EventTag
13 = AbortTag
21 = AbortTag
@@ -155,6 +163,10 @@ type family EventResultType (en :: EventTag) :: * where
155 EventResultType 'TouchcancelTag = ()
163 EventResultType 'TouchcancelTag = ()
156 EventResultType 'WheelTag = ()
164 EventResultType 'WheelTag = ()
157
165
166+#ifdef USE_TEMPLATE_HASKELL
167+deriveGEq ''EventName
168+deriveGCompare ''EventName
169+#else
158instance GEq EventName
170instance GEq EventName
159 where geq Abort Abort = return Refl
171 where geq Abort Abort = return Refl
160 geq Blur Blur = return Refl
172 geq Blur Blur = return Refl
@@ -356,4 +368,4 @@ instance GCompare EventName
356 gcompare Touchcancel Touchcancel = runGComparing $ return GEQ
368 gcompare Touchcancel Touchcancel = runGComparing $ return GEQ
357 gcompare Touchcancel _ = GLT
369 gcompare Touchcancel _ = GLT
358 gcompare _ Touchcancel = GGT
370 gcompare _ Touchcancel = GGT
359−
371+#endif
src/Reflex/Dom/Builder/Immediate.hs+10
@@ -12,6 +12,9 @@
12{-# LANGUAGE RankNTypes #-}
12{-# LANGUAGE RankNTypes #-}
13{-# LANGUAGE RecursiveDo #-}
13{-# LANGUAGE RecursiveDo #-}
14{-# LANGUAGE ScopedTypeVariables #-}
14{-# LANGUAGE ScopedTypeVariables #-}
15+#ifdef USE_TEMPLATE_HASKELL
16+{-# LANGUAGE TemplateHaskell #-}
17+#endif
15{-# LANGUAGE TypeFamilies #-}
18{-# LANGUAGE TypeFamilies #-}
16{-# LANGUAGE TypeOperators #-}
19{-# LANGUAGE TypeOperators #-}
17{-# LANGUAGE UndecidableInstances #-}
20{-# LANGUAGE UndecidableInstances #-}
@@ -34,7 +37,9 @@ import Control.Monad.Primitive
34import Control.Monad.Reader
37import Control.Monad.Reader
35import Control.Monad.Ref
38import Control.Monad.Ref
36import Control.Monad.Trans.Control
39import Control.Monad.Trans.Control
40+#ifndef USE_TEMPLATE_HASKELL
37import Data.Functor.Contravariant (phantom)
41import Data.Functor.Contravariant (phantom)
42+#endif
38import Data.Bitraversable
43import Data.Bitraversable
39import Data.Default
44import Data.Default
40import Data.Dependent.Map (DMap)
45import Data.Dependent.Map (DMap)
@@ -283,6 +288,7 @@ data GhcjsEventSpec er = GhcjsEventSpec
283 , _ghcjsEventSpec_handler :: forall en. (EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en))
288 , _ghcjsEventSpec_handler :: forall en. (EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en))
284 }
289 }
285
290
291+#ifndef USE_TEMPLATE_HASKELL
286phantom2 :: (Functor f, Contravariant f) => f a -> f b
292phantom2 :: (Functor f, Contravariant f) => f a -> f b
287phantom2 = phantom
293phantom2 = phantom
288{-# INLINE phantom2 #-}
294{-# INLINE phantom2 #-}
@@ -293,6 +299,7 @@ ghcjsEventSpec_filters f (GhcjsEventSpec a b) = (\a' -> GhcjsEventSpec a' b) <$>
293ghcjsEventSpec_handler :: forall er en . Getter (GhcjsEventSpec er) ((EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en)))
299ghcjsEventSpec_handler :: forall er en . Getter (GhcjsEventSpec er) ((EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en)))
294ghcjsEventSpec_handler f (GhcjsEventSpec _ b) = phantom2 (f b)
300ghcjsEventSpec_handler f (GhcjsEventSpec _ b) = phantom2 (f b)
295{-# INLINE ghcjsEventSpec_handler #-}
301{-# INLINE ghcjsEventSpec_handler #-}
302+#endif
296
303
297instance er ~ EventResult => Default (GhcjsEventSpec er) where
304instance er ~ EventResult => Default (GhcjsEventSpec er) where
298 def = GhcjsEventSpec
305 def = GhcjsEventSpec
@@ -993,3 +1000,6 @@ wrapWindow wv _ = do
993 , _window_raw = wv
1000 , _window_raw = wv
994 }
1001 }
995
1002
1003+#ifdef USE_TEMPLATE_HASKELL
1004+makeLenses ''GhcjsEventSpec
1005+#endif
src/Reflex/Dom/Internal.hs+1−1
@@ -44,7 +44,7 @@ import GHCJS.DOM.Document
44import GHCJS.DOM.Element
44import GHCJS.DOM.Element
45import GHCJS.DOM.Node
45import GHCJS.DOM.Node
46import qualified GHCJS.DOM.Types as DOM
46import qualified GHCJS.DOM.Types as DOM
47−import GHCJS.DOM.Types (MonadJSM(..), runJSM, askJSM, JSM)
47+import GHCJS.DOM.Types (MonadJSM(..), JSM)
48
48
49{-# INLINABLE mainWidget #-}
49{-# INLINABLE mainWidget #-}
50mainWidget :: (forall x. Widget x ()) -> JSM ()
50mainWidget :: (forall x. Widget x ()) -> JSM ()
src/Reflex/Dom/Old.hs+11
@@ -9,6 +9,9 @@
9{-# LANGUAGE TypeFamilies #-}
9{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE UndecidableInstances #-}
10{-# LANGUAGE UndecidableInstances #-}
11{-# LANGUAGE LambdaCase #-}
11{-# LANGUAGE LambdaCase #-}
12+#ifdef USE_TEMPLATE_HASKELL
13+{-# LANGUAGE TemplateHaskell #-}
14+#endif
12module Reflex.Dom.Old
15module Reflex.Dom.Old
13 ( MonadWidget
16 ( MonadWidget
14 , El
17 , El
@@ -43,7 +46,11 @@ module Reflex.Dom.Old
43 ) where
46 ) where
44
47
45import Control.Arrow (first)
48import Control.Arrow (first)
49+#ifdef USE_TEMPLATE_HASKELL
50+import Control.Lens (makeLenses, (%~), (&), (.~), (^.))
51+#else
46import Control.Lens (Lens, Lens', (%~), (&), (.~), (^.))
52import Control.Lens (Lens, Lens', (%~), (&), (.~), (^.))
53+#endif
47import Control.Monad
54import Control.Monad
48import Control.Monad.Fix
55import Control.Monad.Fix
49import Control.Monad.IO.Class
56import Control.Monad.IO.Class
@@ -86,12 +93,16 @@ instance attrs ~ Map Text Text => Default (ElConfig attrs) where
86 , _elConfig_attributes = mempty
93 , _elConfig_attributes = mempty
87 }
94 }
88
95
96+#ifdef USE_TEMPLATE_HASKELL
97+makeLenses ''ElConfig
98+#else
89elConfig_namespace :: Lens' (ElConfig attrs1) (Maybe Text)
99elConfig_namespace :: Lens' (ElConfig attrs1) (Maybe Text)
90elConfig_namespace f (ElConfig a b) = (\a' -> ElConfig a' b) <$> f a
100elConfig_namespace f (ElConfig a b) = (\a' -> ElConfig a' b) <$> f a
91{-# INLINE elConfig_namespace #-}
101{-# INLINE elConfig_namespace #-}
92elConfig_attributes :: Lens (ElConfig attrs1) (ElConfig attrs2) attrs1 attrs2
102elConfig_attributes :: Lens (ElConfig attrs1) (ElConfig attrs2) attrs1 attrs2
93elConfig_attributes f (ElConfig a b) = (\b' -> ElConfig a b') <$> f b
103elConfig_attributes f (ElConfig a b) = (\b' -> ElConfig a b') <$> f b
94{-# INLINE elConfig_attributes #-}
104{-# INLINE elConfig_attributes #-}
105+#endif
95
106
96--TODO: HasDocument is still not accounted for
107--TODO: HasDocument is still not accounted for
97type MonadWidgetConstraints t m =
108type MonadWidgetConstraints t m =
src/Reflex/Dom/Widget/Input.hs+21−14
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
@@ -8,6 +9,9 @@
8{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE RecursiveDo #-}
10{-# LANGUAGE RecursiveDo #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE ScopedTypeVariables #-}
12+#ifdef USE_TEMPLATE_HASKELL
13+{-# LANGUAGE TemplateHaskell #-}
14+#endif
11{-# LANGUAGE TypeFamilies #-}
15{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE UndecidableInstances #-}
16{-# LANGUAGE UndecidableInstances #-}
13module Reflex.Dom.Widget.Input (module Reflex.Dom.Widget.Input, def, (&), (.~)) where
17module Reflex.Dom.Widget.Input (module Reflex.Dom.Widget.Input, def, (&), (.~)) where
@@ -443,20 +447,22 @@ dropdown k0 options (DropdownConfig setK attrs) = do
443 dValue <- fmap (zipDynWith readKey ixKeys) $ holdDyn (Just k0) $ leftmost [eChange, fmap Just setK]
447 dValue <- fmap (zipDynWith readKey ixKeys) $ holdDyn (Just k0) $ leftmost [eChange, fmap Just setK]
444 return $ Dropdown dValue (attachPromptlyDynWith readKey ixKeys eChange)
448 return $ Dropdown dValue (attachPromptlyDynWith readKey ixKeys eChange)
445
449
450+#ifdef USE_TEMPLATE_HASKELL
446−--concat <$> mapM makeLenses
451+concat <$> mapM makeLenses
447−-- [ ''TextAreaConfig
452+ [ ''TextAreaConfig
448−-- , ''TextArea
453+ , ''TextArea
449−-- , ''TextInputConfig
454+ , ''TextInputConfig
450−-- , ''TextInput
455+ , ''TextInput
451−-- , ''RangeInputConfig
456+ , ''RangeInputConfig
452−-- , ''RangeInput
457+ , ''RangeInput
453−-- , ''FileInputConfig
458+ , ''FileInputConfig
454−-- , ''FileInput
459+ , ''FileInput
455−-- , ''DropdownConfig
460+ , ''DropdownConfig
456−-- , ''Dropdown
461+ , ''Dropdown
457−-- , ''CheckboxConfig
462+ , ''CheckboxConfig
458−-- , ''Checkbox
463+ , ''Checkbox
459−-- ]
464+ ]
465+#else
460textAreaConfig_attributes :: Lens' (TextAreaConfig t) (Dynamic t (Map Text Text))
466textAreaConfig_attributes :: Lens' (TextAreaConfig t) (Dynamic t (Map Text Text))
461textAreaConfig_attributes f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig x1 x2 y) <$> f x3
467textAreaConfig_attributes f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig x1 x2 y) <$> f x3
462{-# INLINE textAreaConfig_attributes #-}
468{-# INLINE textAreaConfig_attributes #-}
@@ -587,6 +593,7 @@ checkbox_change f (Checkbox x1 x2) = (\y -> Checkbox x1 y) <$> f x2
587checkbox_value :: Lens' (Checkbox t) (Dynamic t Bool)
593checkbox_value :: Lens' (Checkbox t) (Dynamic t Bool)
588checkbox_value f (Checkbox x1 x2) = (\y -> Checkbox y x2) <$> f x1
594checkbox_value f (Checkbox x1 x2) = (\y -> Checkbox y x2) <$> f x1
589{-# INLINE checkbox_value #-}
595{-# INLINE checkbox_value #-}
596+#endif
590
597
591instance HasAttributes (TextAreaConfig t) where
598instance HasAttributes (TextAreaConfig t) where
592 type Attrs (TextAreaConfig t) = Dynamic t (Map Text Text)
599 type Attrs (TextAreaConfig t) = Dynamic t (Map Text Text)