@@ -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 #-}
22module Reflex.Dom.Class where
33
44import Prelude hiding (mapM, mapM_, sequence, concat)
@@ -39,13 +39,18 @@ class ( Reflex t, MonadHold t m, MonadIO m, Functor m, MonadReflexCreateTrigger
3939 ) => MonadWidget t m | m -> t where
4040 type WidgetHost m :: * -> *
4141 type GuiAction m :: * -> *
42+ type WidgetOutput t m :: *
43+ type WidgetOutput t m = Event t (WidgetHost m ())
4244 askParent :: m Node
4345 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)
4547 liftWidgetHost :: WidgetHost m a -> m a --TODO: Is this a good idea?
4648 schedulePostBuild :: WidgetHost m () -> m ()
4749 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
4954
5055class Monad m => HasDocument m where
5156 askDocument :: m HTMLDocument
@@ -56,6 +61,9 @@ instance HasDocument m => HasDocument (ReaderT r m) where
5661instance HasDocument m => HasDocument (StateT r m) where
5762 askDocument = lift askDocument
5863
64+instance HasDocument m => HasDocument (Strict.StateT r m) where
65+ askDocument = lift askDocument
66+
5967-- | 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
6068newtype WebViewSingleton x = WebViewSingleton { unWebViewSingleton :: WebView }
6169
@@ -105,6 +113,11 @@ instance HasPostGui t h m => HasPostGui t h (ReaderT r m) where
105113 askRunWithActions = lift askRunWithActions
106114 scheduleFollowup r a = lift $ scheduleFollowup r a
107115
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
120+
108121instance HasPostGui t h m => HasPostGui t h (Strict.StateT s m) where
109122 askPostGui = lift askPostGui
110123 askRunWithActions = lift askRunWithActions
@@ -113,6 +126,7 @@ instance HasPostGui t h m => HasPostGui t h (Strict.StateT s m) where
113126instance MonadWidget t m => MonadWidget t (ReaderT r m) where
114127 type WidgetHost (ReaderT r m) = WidgetHost m
115128 type GuiAction (ReaderT r m) = GuiAction m
129+ type WidgetOutput t (ReaderT r m) = WidgetOutput t m
116130 askParent = lift askParent
117131 subWidget n w = do
118132 r <- ask
@@ -129,6 +143,7 @@ instance MonadWidget t m => MonadWidget t (ReaderT r m) where
129143 return $ \rootElement w -> do
130144 (a, postBuild, voidActions) <- runWidget rootElement $ runReaderT w r
131145 return (a, postBuild, voidActions)
146+ tellWidgetOutput = lift . tellWidgetOutput
132147
133148performEvent_ :: MonadWidget t m => Event t (WidgetHost m ()) -> m ()
134149performEvent_ = addVoidAction