@@ -47,6 +47,12 @@ import Data.Functor.Compose
4747import Data.Functor.Misc
4848import Data.IntMap.Strict (IntMap)
4949import qualified Data.IntMap.Strict as IntMap
50+import Data.List.NonEmpty (NonEmpty (..))
51+import Data.List.NonEmpty.Deferred (NonEmptyDeferred)
52+import qualified Data.List.NonEmpty.Deferred as NonEmptyDeferred
53+import Data.Map (Map)
54+import qualified Data.Map as Map
55+import Data.Semigroup (Semigroup (sconcat))
5056import qualified Data.Semigroup as S
5157import Data.Unique.Tag.Local
5258import Data.Sequence (Seq)
@@ -86,7 +92,7 @@ instance (ReflexHost t, Ref m ~ Ref IO, PrimMonad (HostFrame t)) => PerformEvent
8692instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT t m) where
8793 runWithReplace a0 a' = PerformEventT $ RequesterT $ do
8894 env@(_, _ :: TagGen (PrimState (HostFrame t)) s) <- RequesterInternalT ask
89− let runA :: forall a. PerformEventT t m a -> HostFrame t (a, Event t (Seq (RequestEnvelope s (HostFrame t))))
95+ let runA :: forall a. PerformEventT t m a -> HostFrame t (a, Event t (NonEmptyDeferred (RequestEnvelope s (HostFrame t))))
9096 runA (PerformEventT (RequesterT a)) = runEventWriterT $ runReaderT (unRequesterInternalT a) env
9197 (result0, requests0) <- lift $ runA a0
9298 newA <- requestingIdentity $ traceEventWith (const "running new widget") $ runA <$> a'
@@ -96,7 +102,7 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
96102 pure (result0, fmapCheap fst newA)
97103 traverseIntMapWithKeyWithAdjust f a0 a' = PerformEventT $ RequesterT $ do
98104 env@(_, _ :: TagGen (PrimState (HostFrame t)) s) <- RequesterInternalT ask
99− let runA :: forall a. PerformEventT t m a -> HostFrame t (a, Event t (Seq (RequestEnvelope s (HostFrame t))))
105+ let runA :: forall a. PerformEventT t m a -> HostFrame t (a, Event t (NonEmptyDeferred (RequestEnvelope s (HostFrame t))))
100106 runA (PerformEventT (RequesterT a)) = runEventWriterT $ runReaderT (unRequesterInternalT a) env
101107 children' <- requestingIdentity $ itraverse (\k -> runA . f k) <$> a'
102108 children0 <- lift $ itraverse (\k -> runA . f k) a0
@@ -106,11 +112,11 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
106112 requests' = fmap snd `fmapCheap` children'
107113 requests <- switchHoldPromptOnlyIncremental mergeIntIncremental coincidencePatchIntMap requests0 $ requests'
108114 --TODO: promptly *prevent* events, then sign up the new ones; this is a serious breaking change to PerformEvent
109− RequesterInternalT $ tellEvent $ fforMaybeCheap requests $ \m -> if null m then Nothing else Just $ fold m
115+ RequesterInternalT $ tellEvent $ fforMaybeCheap requests concatIntMapMaybe
110116 pure (results0, results')
111117 traverseDMapWithKeyWithAdjust (f :: forall a. k a -> v a -> PerformEventT t m (v' a)) (a0 :: DMap k v) a' = PerformEventT $ RequesterT $ do
112118 env@(_, _ :: TagGen (PrimState (HostFrame t)) s) <- RequesterInternalT ask
113− let runA :: forall a. k a -> v a -> HostFrame t (Compose ((,) (Event t (Seq (RequestEnvelope s (HostFrame t))))) v' a)
119+ let runA :: forall a. k a -> v a -> HostFrame t (Compose ((,) (Event t (NonEmptyDeferred (RequestEnvelope s (HostFrame t))))) v' a)
114120 runA k v = fmap (Compose . swap) $ runEventWriterT $ runReaderT (unRequesterInternalT a) env
115121 where (PerformEventT (RequesterT a)) = f k v
116122 children' <- requestingIdentity $ traversePatchDMapWithKey runA <$> a'
@@ -121,11 +127,11 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
121127 requests' = weakenPatchDMapWith (fst . getCompose) `fmapCheap` children'
122128 requests <- switchHoldPromptOnlyIncremental mergeMapIncremental coincidencePatchMap requests0 $ requests'
123129 --TODO: promptly *prevent* events, then sign up the new ones; this is a serious breaking change to PerformEvent
124− RequesterInternalT $ tellEvent $ fforMaybeCheap requests $ \m -> if null m then Nothing else Just $ fold m
130+ RequesterInternalT $ tellEvent $ fforMaybeCheap requests concatMapMaybe
125131 pure (results0, results')
126132 traverseDMapWithKeyWithAdjustWithMove (f :: forall a. k a -> v a -> PerformEventT t m (v' a)) (a0 :: DMap k v) a' = PerformEventT $ RequesterT $ do
127133 env@(_, _ :: TagGen (PrimState (HostFrame t)) s) <- RequesterInternalT ask
128− let runA :: forall a. k a -> v a -> HostFrame t (Compose ((,) (Event t (Seq (RequestEnvelope s (HostFrame t))))) v' a)
134+ let runA :: forall a. k a -> v a -> HostFrame t (Compose ((,) (Event t (NonEmptyDeferred (RequestEnvelope s (HostFrame t))))) v' a)
129135 runA k v = fmap (Compose . swap) $ runEventWriterT $ runReaderT (unRequesterInternalT a) env
130136 where (PerformEventT (RequesterT a)) = f k v
131137 children' <- requestingIdentity $ traversePatchDMapWithMoveWithKey runA <$> a'
@@ -136,9 +142,19 @@ instance (ReflexHost t, PrimMonad (HostFrame t)) => Adjustable t (PerformEventT
136142 requests' = weakenPatchDMapWithMoveWith (fst . getCompose) `fmapCheap` children'
137143 requests <- switchHoldPromptOnlyIncremental mergeMapIncrementalWithMove coincidencePatchMapWithMove requests0 $ requests'
138144 --TODO: promptly *prevent* events, then sign up the new ones; this is a serious breaking change to PerformEvent
139− RequesterInternalT $ tellEvent $ fforMaybeCheap requests $ \m -> if null m then Nothing else Just $ fold m
145+ RequesterInternalT $ tellEvent $ fforMaybeCheap requests concatMapMaybe
140146 pure (results0, results')
141147
148+concatIntMapMaybe :: Semigroup a => IntMap a -> Maybe a
149+concatIntMapMaybe m = case IntMap.elems m of
150+ [] -> Nothing
151+ h : t -> Just $ sconcat $ h :| t
152+
153+concatMapMaybe :: Semigroup a => Map k a -> Maybe a
154+concatMapMaybe m = case Map.elems m of
155+ [] -> Nothing
156+ h : t -> Just $ sconcat $ h :| t
157+
142158defaultAdjustBase :: forall t v v2 k' p. (Monad (HostFrame t), PrimMonad (HostFrame t), Reflex t)
143159 => ((forall a. k' a -> v a -> HostFrame t (v2 a)) -> p k' v -> HostFrame t (p k' v2))
144160 -> (forall a. k' a -> v a -> HostFrame t (v2 a))