@@ -1,4 +1,4 @@
1−{-# LANGUAGE TypeFamilies, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, RankNTypes, GADTs, ScopedTypeVariables, FunctionalDependencies, RecursiveDo, UndecidableInstances, GeneralizedNewtypeDeriving, StandaloneDeriving, EmptyDataDecls, NoMonomorphismRestriction, TemplateHaskell, PolyKinds, TypeOperators, DeriveFunctor, LambdaCase, CPP, ForeignFunctionInterface, DeriveDataTypeable, ConstraintKinds #-}
1+{-# LANGUAGE TypeFamilies, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, RankNTypes, GADTs, ScopedTypeVariables, FunctionalDependencies, RecursiveDo, UndecidableInstances, GeneralizedNewtypeDeriving, StandaloneDeriving, EmptyDataDecls, NoMonomorphismRestriction, TemplateHaskell, PolyKinds, TypeOperators, DeriveFunctor, LambdaCase, CPP, ForeignFunctionInterface, DeriveDataTypeable, ConstraintKinds, DefaultSignatures #-}
2module Reflex.Dom.Class where
2module Reflex.Dom.Class where
4import Prelude hiding (mapM, mapM_, sequence, concat)
4import Prelude hiding (mapM, mapM_, sequence, concat)
@@ -39,13 +39,18 @@ class ( Reflex t, MonadHold t m, MonadIO m, Functor m, MonadReflexCreateTrigger
39 ) => MonadWidget t m | m -> t where
39 ) => MonadWidget t m | m -> t where
40 type WidgetHost m :: * -> *
40 type WidgetHost m :: * -> *
41 type GuiAction m :: * -> *
41 type GuiAction m :: * -> *
42+ type WidgetOutput t m :: *
43+ type WidgetOutput t m = Event t (WidgetHost m ())
42 askParent :: m Node
44 askParent :: m Node
43 subWidget :: Node -> m a -> m a
45 subWidget :: Node -> m a -> m a
44− subWidgetWithVoidActions :: Node -> m a -> m (a, Event t (WidgetHost m ()))
46+ subWidgetWithVoidActions :: Node -> m a -> m (a, WidgetOutput t m)
45 liftWidgetHost :: WidgetHost m a -> m a --TODO: Is this a good idea?
47 liftWidgetHost :: WidgetHost m a -> m a --TODO: Is this a good idea?
46 schedulePostBuild :: WidgetHost m () -> m ()
48 schedulePostBuild :: WidgetHost m () -> m ()
47 addVoidAction :: Event t (WidgetHost m ()) -> m ()
49 addVoidAction :: Event t (WidgetHost m ()) -> m ()
48− getRunWidget :: IsNode n => m (n -> m a -> WidgetHost m (a, WidgetHost m (), Event t (WidgetHost m ())))
50+ getRunWidget :: IsNode n => m (n -> m a -> WidgetHost m (a, WidgetHost m (), WidgetOutput t m))
51+ tellWidgetOutput :: Ord k => Dynamic t (Map k (WidgetOutput t m)) -> m ()
52+ default tellWidgetOutput :: (WidgetOutput t m ~ Event t (WidgetHost m ()), Ord k) => Dynamic t (Map k (WidgetOutput t m)) -> m ()
53+ tellWidgetOutput = addVoidAction . switch . fmap (mergeWith (>>) . toList) . current
50class Monad m => HasDocument m where
55class Monad m => HasDocument m where
51 askDocument :: m HTMLDocument
56 askDocument :: m HTMLDocument
@@ -56,6 +61,9 @@ instance HasDocument m => HasDocument (ReaderT r m) where
56instance HasDocument m => HasDocument (StateT r m) where
61instance HasDocument m => HasDocument (StateT r m) where
57 askDocument = lift askDocument
62 askDocument = lift askDocument
64+instance HasDocument m => HasDocument (Strict.StateT r m) where
65+ askDocument = lift askDocument
59-- | A singleton type for a given WebView; we use this to statically guarantee that different WebViews (and thus different javscript contexts) don't get mixed up
67-- | A singleton type for a given WebView; we use this to statically guarantee that different WebViews (and thus different javscript contexts) don't get mixed up
60newtype WebViewSingleton x = WebViewSingleton { unWebViewSingleton :: WebView }
68newtype WebViewSingleton x = WebViewSingleton { unWebViewSingleton :: WebView }
@@ -105,6 +113,11 @@ instance HasPostGui t h m => HasPostGui t h (ReaderT r m) where
105 askRunWithActions = lift askRunWithActions
113 askRunWithActions = lift askRunWithActions
106 scheduleFollowup r a = lift $ scheduleFollowup r a
114 scheduleFollowup r a = lift $ scheduleFollowup r a
116+instance HasPostGui t h m => HasPostGui t h (StateT s m) where
117+ askPostGui = lift askPostGui
118+ askRunWithActions = lift askRunWithActions
119+ scheduleFollowup r a = lift $ scheduleFollowup r a
108instance HasPostGui t h m => HasPostGui t h (Strict.StateT s m) where
121instance HasPostGui t h m => HasPostGui t h (Strict.StateT s m) where
109 askPostGui = lift askPostGui
122 askPostGui = lift askPostGui
110 askRunWithActions = lift askRunWithActions
123 askRunWithActions = lift askRunWithActions
@@ -113,6 +126,7 @@ instance HasPostGui t h m => HasPostGui t h (Strict.StateT s m) where
113instance MonadWidget t m => MonadWidget t (ReaderT r m) where
126instance MonadWidget t m => MonadWidget t (ReaderT r m) where
114 type WidgetHost (ReaderT r m) = WidgetHost m
127 type WidgetHost (ReaderT r m) = WidgetHost m
115 type GuiAction (ReaderT r m) = GuiAction m
128 type GuiAction (ReaderT r m) = GuiAction m
129+ type WidgetOutput t (ReaderT r m) = WidgetOutput t m
116 askParent = lift askParent
130 askParent = lift askParent
117 subWidget n w = do
131 subWidget n w = do
@@ -129,6 +143,7 @@ instance MonadWidget t m => MonadWidget t (ReaderT r m) where
129 return $ \rootElement w -> do
143 return $ \rootElement w -> do
130 (a, postBuild, voidActions) <- runWidget rootElement $ runReaderT w r
144 (a, postBuild, voidActions) <- runWidget rootElement $ runReaderT w r
131 return (a, postBuild, voidActions)
145 return (a, postBuild, voidActions)
146+ tellWidgetOutput = lift . tellWidgetOutput
133performEvent_ :: MonadWidget t m => Event t (WidgetHost m ()) -> m ()
148performEvent_ :: MonadWidget t m => Event t (WidgetHost m ()) -> m ()
134performEvent_ = addVoidAction
149performEvent_ = addVoidAction