on develop help sign in
Tweak rules a bit
f69a1c8Ryan Trinkle
src/Reflex/Spider/Internal.hs+8−5
@@ -194,8 +194,11 @@ newtype Event x a = Event { unEvent :: Subscriber x a -> EventM x (EventSubscrip
194subscribeAndRead :: Event x a -> Subscriber x a -> EventM x (EventSubscription x, Maybe a)
194subscribeAndRead :: Event x a -> Subscriber x a -> EventM x (EventSubscription x, Maybe a)
195subscribeAndRead = unEvent
195subscribeAndRead = unEvent
196
196
197+{-# RULES
198+"cacheEvent/cacheEvent" forall e. cacheEvent (cacheEvent e) = cacheEvent e
197−{-# RULES "pushCheap/cacheEvent" forall f e. pushCheap f (cacheEvent e) = pushCheap f e #-}
199+"cacheEvent/pushCheap" forall f e. pushCheap f (cacheEvent e) = cacheEvent (pushCheap f e)
198−{-# RULES "hold/cacheEvent" forall f e. hold f (cacheEvent e) = hold f e #-}
200+"hold/cacheEvent" forall f e. hold f (cacheEvent e) = hold f e
201+ #-}
199{- RULES
202{- RULES
200 "subscribeAndRead/cacheEvent" forall e. subscribeAndRead (cacheEvent e) = subscribeAndRead e
203 "subscribeAndRead/cacheEvent" forall e. subscribeAndRead (cacheEvent e) = subscribeAndRead e
201 #-}
204 #-}
@@ -203,8 +206,8 @@ subscribeAndRead = unEvent
203-- | Construct an 'Event' equivalent to that constructed by 'push', but with no
206-- | Construct an 'Event' equivalent to that constructed by 'push', but with no
204-- caching; if the computation function is very cheap, this is (much) more
207-- caching; if the computation function is very cheap, this is (much) more
205-- efficient than 'push'
208-- efficient than 'push'
206−{- INLINABLE pushCheap #-}
207−{-# INLINE [1] pushCheap #-}
209+{- INLINE [1] pushCheap #-}
210+{-# NOINLINE pushCheap #-}
208pushCheap :: HasSpiderTimeline x => (a -> ComputeM x (Maybe b)) -> Event x a -> Event x b
211pushCheap :: HasSpiderTimeline x => (a -> ComputeM x (Maybe b)) -> Event x a -> Event x b
209pushCheap f e = Event $ \sub -> do
212pushCheap f e = Event $ \sub -> do
210 (subscription, occ) <- subscribeAndRead e $ sub
213 (subscription, occ) <- subscribeAndRead e $ sub
@@ -229,7 +232,7 @@ data CacheSubscribed x a
229--TODO: Try a caching strategy where we subscribe directly to the parent when
232--TODO: Try a caching strategy where we subscribe directly to the parent when
230--there's only one subscriber, and then build our own WeakBag only when a second
233--there's only one subscriber, and then build our own WeakBag only when a second
231--subscriber joins
234--subscriber joins
232−{-# NOINLINE [1] cacheEvent #-}
235+{-# NOINLINE cacheEvent #-}
233cacheEvent :: HasSpiderTimeline x => Event x a -> Event x a
236cacheEvent :: HasSpiderTimeline x => Event x a -> Event x a
234cacheEvent e = Event $ \sub -> {-# SCC "cacheEvent" #-} do
237cacheEvent e = Event $ \sub -> {-# SCC "cacheEvent" #-} do
235 let !mSubscribedRef = unsafeNewIORef e Nothing
238 let !mSubscribedRef = unsafeNewIORef e Nothing