on develop help sign in
Add HasDocument (StaticDomBuilder t m)
997b032Ryan Trinkle
reflex-dom-core/src/Reflex/Dom/Builder/Class.hs+26
@@ -46,6 +46,7 @@ import Reflex.Requester.Base
46import qualified Control.Category
46import qualified Control.Category
47import Control.Lens hiding (element)
47import Control.Lens hiding (element)
48import Control.Monad.Reader
48import Control.Monad.Reader
49+import qualified Control.Monad.State as Lazy
49import Control.Monad.State.Strict
50import Control.Monad.State.Strict
50import Control.Monad.Trans.Control
51import Control.Monad.Trans.Control
51import Data.Default
52import Data.Default
@@ -62,6 +63,7 @@ import GHCJS.DOM.Types (JSM)
62
63
63class Default (EventSpec d EventResult) => DomSpace d where
64class Default (EventSpec d EventResult) => DomSpace d where
64 type EventSpec d :: (EventTag -> *) -> *
65 type EventSpec d :: (EventTag -> *) -> *
66+ type RawDocument d :: *
65 type RawTextNode d :: *
67 type RawTextNode d :: *
66 type RawElement d :: *
68 type RawElement d :: *
67 type RawFile d :: *
69 type RawFile d :: *
@@ -660,6 +662,11 @@ instance DomRenderHook t m => DomRenderHook t (StateT e m) where
660 requestDomAction = lift . requestDomAction
662 requestDomAction = lift . requestDomAction
661 requestDomAction_ = lift . requestDomAction_
663 requestDomAction_ = lift . requestDomAction_
662
664
665+instance DomRenderHook t m => DomRenderHook t (Lazy.StateT e m) where
666+ withRenderHook hook (Lazy.StateT a) = Lazy.StateT $ \s -> withRenderHook hook $ a s
667+ requestDomAction = lift . requestDomAction
668+ requestDomAction_ = lift . requestDomAction_
669+
663deriving instance DomRenderHook t m => DomRenderHook t (EventWriterT t w m)
670deriving instance DomRenderHook t m => DomRenderHook t (EventWriterT t w m)
664deriving instance DomRenderHook t m => DomRenderHook t (RequesterT t req rsp m)
671deriving instance DomRenderHook t m => DomRenderHook t (RequesterT t req rsp m)
665deriving instance DomRenderHook t m => DomRenderHook t (PostBuildT t m)
672deriving instance DomRenderHook t m => DomRenderHook t (PostBuildT t m)
@@ -668,3 +675,22 @@ deriving instance DomRenderHook t m => DomRenderHook t (QueryT t q m)
668{-# DEPRECATED liftElementConfig "Use 'id' instead; this function is no longer necessary" #-}
675{-# DEPRECATED liftElementConfig "Use 'id' instead; this function is no longer necessary" #-}
669liftElementConfig :: ElementConfig er t s -> ElementConfig er t s
676liftElementConfig :: ElementConfig er t s -> ElementConfig er t s
670liftElementConfig = id
677liftElementConfig = id
678+
679+class Monad m => HasDocument m where
680+ askDocument :: m (RawDocument (DomBuilderSpace m))
681+ default askDocument
682+ :: ( m ~ f m'
683+ , RawDocument (DomBuilderSpace m) ~ RawDocument (DomBuilderSpace m')
684+ , MonadTrans f
685+ , Monad m'
686+ , HasDocument m'
687+ )
688+ => m (RawDocument (DomBuilderSpace m))
689+ askDocument = lift askDocument
690+
691+instance HasDocument m => HasDocument (ReaderT r m)
692+instance HasDocument m => HasDocument (EventWriterT t w m)
693+instance HasDocument m => HasDocument (DynamicWriterT t w m)
694+instance HasDocument m => HasDocument (PostBuildT t m)
695+instance HasDocument m => HasDocument (RequesterT t request response m)
696+instance HasDocument m => HasDocument (QueryT t q m)
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+1−14
@@ -234,20 +234,6 @@ runImmediateDomBuilderT (ImmediateDomBuilderT a) env eventChan =
234 v <- synchronously x
234 v <- synchronously x
235 void . liftIO $ f v
235 void . liftIO $ f v
236
236
237−class Monad m => HasDocument m where
238− askDocument :: m Document
239− default askDocument :: (m ~ f m', MonadTrans f, Monad m', HasDocument m') => m Document
240− askDocument = lift askDocument
241−
242−instance HasDocument m => HasDocument (ReaderT r m)
243−instance HasDocument m => HasDocument (StateT s m)
244−instance HasDocument m => HasDocument (Lazy.StateT s m)
245−instance HasDocument m => HasDocument (EventWriterT t w m)
246−instance HasDocument m => HasDocument (DynamicWriterT t w m)
247−instance HasDocument m => HasDocument (PostBuildT t m)
248−instance HasDocument m => HasDocument (RequesterT t request response m)
249−instance HasDocument m => HasDocument (QueryT t q m)
250−
251instance Monad m => HasDocument (ImmediateDomBuilderT t m) where
237instance Monad m => HasDocument (ImmediateDomBuilderT t m) where
252 {-# INLINABLE askDocument #-}
238 {-# INLINABLE askDocument #-}
253 askDocument = ImmediateDomBuilderT $ asks _immediateDomBuilderEnv_document
239 askDocument = ImmediateDomBuilderT $ asks _immediateDomBuilderEnv_document
@@ -403,6 +389,7 @@ data GhcjsDomSpace
403
389
404instance DomSpace GhcjsDomSpace where
390instance DomSpace GhcjsDomSpace where
405 type EventSpec GhcjsDomSpace = GhcjsEventSpec
391 type EventSpec GhcjsDomSpace = GhcjsEventSpec
392+ type RawDocument GhcjsDomSpace = DOM.Document
406 type RawTextNode GhcjsDomSpace = DOM.Text
393 type RawTextNode GhcjsDomSpace = DOM.Text
407 type RawElement GhcjsDomSpace = DOM.Element
394 type RawElement GhcjsDomSpace = DOM.Element
408 type RawFile GhcjsDomSpace = DOM.File
395 type RawFile GhcjsDomSpace = DOM.File
reflex-dom-core/src/Reflex/Dom/Builder/Static.hs+4
@@ -138,6 +138,7 @@ instance Default (StaticEventSpec er)
138
138
139instance DomSpace StaticDomSpace where
139instance DomSpace StaticDomSpace where
140 type EventSpec StaticDomSpace = StaticEventSpec
140 type EventSpec StaticDomSpace = StaticEventSpec
141+ type RawDocument StaticDomSpace = ()
141 type RawTextNode StaticDomSpace = ()
142 type RawTextNode StaticDomSpace = ()
142 type RawElement StaticDomSpace = ()
143 type RawElement StaticDomSpace = ()
143 type RawFile StaticDomSpace = ()
144 type RawFile StaticDomSpace = ()
@@ -146,6 +147,9 @@ instance DomSpace StaticDomSpace where
146 type RawSelectElement StaticDomSpace = ()
147 type RawSelectElement StaticDomSpace = ()
147 addEventSpecFlags _ _ _ _ = StaticEventSpec
148 addEventSpecFlags _ _ _ _ = StaticEventSpec
148
149
150+instance Monad m => HasDocument (StaticDomBuilderT t m) where
151+ askDocument = pure ()
152+
149instance (Reflex t, Adjustable t m, MonadHold t m) => Adjustable t (StaticDomBuilderT t m) where
153instance (Reflex t, Adjustable t m, MonadHold t m) => Adjustable t (StaticDomBuilderT t m) where
150 runWithReplace a0 a' = do
154 runWithReplace a0 a' = do
151 e <- StaticDomBuilderT ask
155 e <- StaticDomBuilderT ask