on master help sign in
Add 'eitherRoute'
2aba793Alexandre Esteves
lib/route/src/Obelisk/Route/Frontend.hs+21
@@ -37,6 +37,9 @@ module Obelisk.Route.Frontend
37 , maybeRoute
37 , maybeRoute
38 , maybeRoute_
38 , maybeRoute_
39 , maybeRouted
39 , maybeRouted
40+ , eitherRoute
41+ , eitherRoute_
42+ , eitherRouted
40 , runRouteViewT
43 , runRouteViewT
41 , SetRouteT(..)
44 , SetRouteT(..)
42 , SetRoute(..)
45 , SetRoute(..)
@@ -56,6 +59,7 @@ import Obelisk.Route
56import Control.Category (Category (..), (.))
59import Control.Category (Category (..), (.))
57import Control.Category.Cartesian
60import Control.Category.Cartesian
58import Control.Lens hiding (Bifunctor, bimap, universe, element)
61import Control.Lens hiding (Bifunctor, bimap, universe, element)
62+import Control.Monad ((<=<))
59import Control.Monad.Fix
63import Control.Monad.Fix
60import Control.Monad.Primitive
64import Control.Monad.Primitive
61import Control.Monad.Ref
65import Control.Monad.Ref
@@ -204,6 +208,20 @@ maybeRoute f = factorRouted $ strictDynWidget $ \(c :=> r') -> do
204 runRoutedT (f c) r'
208 runRoutedT (f c) r'
205-}
209-}
206
210
211+eitherRoute_
212+ :: (MonadFix m, MonadHold t m, Adjustable t m)
213+ => RoutedT t l m ()
214+ -> RoutedT t r m ()
215+ -> RoutedT t (Either l r) m ()
216+eitherRoute_ l r = eitherRouted $ strictDynWidget_ $ either (runRoutedT l) (runRoutedT r)
217+
218+eitherRoute
219+ :: (MonadFix m, MonadHold t m, Adjustable t m)
220+ => RoutedT t l m a
221+ -> RoutedT t r m a
222+ -> RoutedT t (Either l r) m (Dynamic t a)
223+eitherRoute l r = eitherRouted $ strictDynWidget $ either (runRoutedT l) (runRoutedT r)
224+
207dsumValueCoercion :: Coercion f g -> Coercion (DSum k f) (DSum k g)
225dsumValueCoercion :: Coercion f g -> Coercion (DSum k f) (DSum k g)
208dsumValueCoercion Coercion = Coercion
226dsumValueCoercion Coercion = Coercion
209
227
@@ -220,6 +238,9 @@ maybeRouted r = RoutedT $ ReaderT $ \d -> do
220 d' <- maybeDyn d
238 d' <- maybeDyn d
221 runRoutedT r d'
239 runRoutedT r d'
222
240
241+eitherRouted :: (Reflex t, MonadFix m, MonadHold t m) => RoutedT t (Either (Dynamic t a) (Dynamic t b)) m c -> RoutedT t (Either a b) m c
242+eitherRouted r = RoutedT $ ReaderT $ runRoutedT r <=< eitherDyn
243+
223-- | WARNING: The input 'Dynamic' must be fully constructed when this is run
244-- | WARNING: The input 'Dynamic' must be fully constructed when this is run
224strictDynWidget :: (MonadSample t m, MonadHold t m, Adjustable t m) => (a -> m b) -> RoutedT t a m (Dynamic t b)
245strictDynWidget :: (MonadSample t m, MonadHold t m, Adjustable t m) => (a -> m b) -> RoutedT t a m (Dynamic t b)
225strictDynWidget f = RoutedT $ ReaderT $ \r -> do
246strictDynWidget f = RoutedT $ ReaderT $ \r -> do