@@ -20,7 +20,6 @@
20{-# LANGUAGE DeriveFunctor #-}
20{-# LANGUAGE DeriveFunctor #-}
21{-# LANGUAGE StandaloneDeriving #-}
21{-# LANGUAGE StandaloneDeriving #-}
22{-# LANGUAGE InstanceSigs #-}
22{-# LANGUAGE InstanceSigs #-}
24#ifdef USE_REFLEX_OPTIMIZER
23#ifdef USE_REFLEX_OPTIMIZER
25{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
24{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
@@ -211,6 +210,12 @@ nextNodeIdRef = unsafePerformIO $ newIORef 1
212newNodeId :: IO Int
211newNodeId :: IO Int
213newNodeId = atomicModifyIORef' nextNodeIdRef $ \n -> (succ n, n)
212newNodeId = atomicModifyIORef' nextNodeIdRef $ \n -> (succ n, n)
214+{-# NOINLINE unsafeNodeId #-}
215+unsafeNodeId :: a -> Int
216+unsafeNodeId a = unsafePerformIO $ do
216--------------------------------------------------------------------------------
221--------------------------------------------------------------------------------
@@ -314,10 +319,9 @@ cacheEvent e =
317− unsafePerformIO $ do
318− mSubscribedRef :: IORef (FastWeak (CacheSubscribed x a))
322+ let mSubscribedRef :: IORef (FastWeak (CacheSubscribed x a))
319− <- newIORef emptyFastWeak
323+ !mSubscribedRef = unsafeNewIORef e emptyFastWeak
320− pure $ \sub -> {-# SCC "cacheEvent" #-} do
324+ in \sub -> {-# SCC "cacheEvent" #-} do
321#ifdef DEBUG_TRACE_EVENTS
325#ifdef DEBUG_TRACE_EVENTS
322 unless (BS8.null callSite) $ liftIO $ BS8.hPutStrLn stderr callSite
326 unless (BS8.null callSite) $ liftIO $ BS8.hPutStrLn stderr callSite
@@ -383,7 +387,7 @@ eventRoot !k !r = Event $ wrap eventSubscribedRoot $ liftIO . getRootSubscribed
383eventNever :: Event x a
387eventNever :: Event x a
384eventNever = Event $ \_ -> return (EventSubscription (return ()) eventSubscribedNever, Nothing)
388eventNever = Event $ \_ -> return (EventSubscription (return ()) eventSubscribedNever, Nothing)
386−eventFan :: (GCompare k, HasSpiderTimeline x) => k a -> Fan x k v -> Event x (v a)
390+eventFan :: (GCompare k, HasSpiderTimeline x) => k a -> Fan x k -> Event x a
387eventFan !k !f = Event $ wrap eventSubscribedFan $ getFanSubscribed k f
391eventFan !k !f = Event $ wrap eventSubscribedFan $ getFanSubscribed k f
389eventSwitch :: HasSpiderTimeline x => Switch x a -> Event x a
393eventSwitch :: HasSpiderTimeline x => Switch x a -> Event x a
@@ -435,14 +439,14 @@ newSubscriberHold h = return $ Subscriber
435 , subscriberRecalculateHeight = \_ -> return ()
439 , subscriberRecalculateHeight = \_ -> return ()
438−newSubscriberFan :: forall x k v. (HasSpiderTimeline x, GCompare k) => FanSubscribed x k v -> IO (Subscriber x (DMap k v))
442+newSubscriberFan :: forall x k. (HasSpiderTimeline x, GCompare k) => FanSubscribed x k -> IO (Subscriber x (DMap k Identity))
439newSubscriberFan subscribed = return $ Subscriber
443newSubscriberFan subscribed = return $ Subscriber
440 { subscriberPropagate = \a -> {-# SCC "traverseFan" #-} do
444 { subscriberPropagate = \a -> {-# SCC "traverseFan" #-} do
441 subs <- liftIO $ readIORef $ fanSubscribedSubscribers subscribed
445 subs <- liftIO $ readIORef $ fanSubscribedSubscribers subscribed
442 tracePropagate (Proxy :: Proxy x) $ "SubscriberFan" <> showNodeId subscribed <> ": " ++ show (DMap.size subs) ++ " keys subscribed, " ++ show (DMap.size a) ++ " keys firing"
446 tracePropagate (Proxy :: Proxy x) $ "SubscriberFan" <> showNodeId subscribed <> ": " ++ show (DMap.size subs) ++ " keys subscribed, " ++ show (DMap.size a) ++ " keys firing"
443 liftIO $ writeIORef (fanSubscribedOccurrence subscribed) $ Just a
447 liftIO $ writeIORef (fanSubscribedOccurrence subscribed) $ Just a
444 scheduleClear $ fanSubscribedOccurrence subscribed
448 scheduleClear $ fanSubscribedOccurrence subscribed
445− let f _ (Pair v subsubs) = do
449+ let f _ (Pair (Identity v) subsubs) = do
446 propagate v $ _fanSubscribedChildren_list subsubs
450 propagate v $ _fanSubscribedChildren_list subsubs
447 return $ Constant ()
451 return $ Constant ()
448 _ <- DMap.traverseWithKey f $ DMap.intersectionWithKey (\_ -> Pair) a subs --TODO: Would be nice to have DMap.traverse_
452 _ <- DMap.traverseWithKey f $ DMap.intersectionWithKey (\_ -> Pair) a subs --TODO: Would be nice to have DMap.traverse_
@@ -595,7 +599,7 @@ eventSubscribedNever = EventSubscribed
598−eventSubscribedFan :: FanSubscribed x k v -> EventSubscribed x
602+eventSubscribedFan :: FanSubscribed x k -> EventSubscribed x
599eventSubscribedFan !subscribed = EventSubscribed
603eventSubscribedFan !subscribed = EventSubscribed
600 { eventSubscribedHeightRef = eventSubscribedHeightRef $ _eventSubscription_subscribed $ fanSubscribedParent subscribed
604 { eventSubscribedHeightRef = eventSubscribedHeightRef $ _eventSubscription_subscribed $ fanSubscribedParent subscribed
601 , eventSubscribedRetained = toAny subscribed
605 , eventSubscribedRetained = toAny subscribed
@@ -1013,7 +1017,7 @@ data RootSubscribed x a = forall k. GCompare k => RootSubscribed
1016−data Root x k
1020+data Root x (k :: * -> *)
1017 = Root { rootOccurrence :: !(IORef (DMap k Identity)) -- The currently-firing occurrence of this event
1021 = Root { rootOccurrence :: !(IORef (DMap k Identity)) -- The currently-firing occurrence of this event
1018 , rootSubscribed :: !(IORef (DMap k (RootSubscribed x)))
1022 , rootSubscribed :: !(IORef (DMap k (RootSubscribed x)))
1019 , rootInit :: !(forall a. k a -> RootTrigger x a -> IO (IO ()))
1023 , rootInit :: !(forall a. k a -> RootTrigger x a -> IO (IO ()))
@@ -1083,25 +1087,25 @@ heightBagVerify b@(HeightBag s c) = if
1083heightBagVerify = id
1087heightBagVerify = id
1086−data FanSubscribedChildren x k v a = FanSubscribedChildren
1090+data FanSubscribedChildren (x :: *) k a = FanSubscribedChildren
1087− { _fanSubscribedChildren_list :: !(WeakBag (Subscriber x (v a)))
1091+ { _fanSubscribedChildren_list :: !(WeakBag (Subscriber x a))
1088− , _fanSubscribedChildren_self :: {-# NOUNPACK #-} !(k a, FanSubscribed x k v)
1092+ , _fanSubscribedChildren_self :: {-# NOUNPACK #-} !(k a, FanSubscribed x k)
1089− , _fanSubscribedChildren_weakSelf :: !(IORef (Weak (k a, FanSubscribed x k v)))
1093+ , _fanSubscribedChildren_weakSelf :: !(IORef (Weak (k a, FanSubscribed x k)))
1092−data FanSubscribed x k v
1096+data FanSubscribed (x :: *) k
1093− = FanSubscribed { fanSubscribedCachedSubscribed :: !(IORef (Maybe (FanSubscribed x k v)))
1097+ = FanSubscribed { fanSubscribedCachedSubscribed :: !(IORef (Maybe (FanSubscribed x k)))
1094− , fanSubscribedOccurrence :: !(IORef (Maybe (DMap k v)))
1098+ , fanSubscribedOccurrence :: !(IORef (Maybe (DMap k Identity)))
1095− , fanSubscribedSubscribers :: !(IORef (DMap k (FanSubscribedChildren x k v))) -- This DMap should never be empty
1099+ , fanSubscribedSubscribers :: !(IORef (DMap k (FanSubscribedChildren x k))) -- This DMap should never be empty
1096 , fanSubscribedParent :: !(EventSubscription x)
1100 , fanSubscribedParent :: !(EventSubscription x)
1097#ifdef DEBUG_NODEIDS
1101#ifdef DEBUG_NODEIDS
1098 , fanSubscribedNodeId :: Int
1102 , fanSubscribedNodeId :: Int
1102−data Fan x k v
1106+data Fan x k
1103− = Fan { fanParent :: !(Event x (DMap k v))
1107+ = Fan { fanParent :: !(Event x (DMap k Identity))
1104− , fanSubscribed :: !(IORef (Maybe (FanSubscribed x k v)))
1108+ , fanSubscribed :: !(IORef (Maybe (FanSubscribed x k)))
1107data SwitchSubscribed x a
1111data SwitchSubscribed x a
@@ -1206,12 +1210,18 @@ buildDynamic readV0 v' = do
1206 return d
1210 return d
1208unsafeBuildDynamic :: BehaviorM x (PatchTarget p) -> Event x p -> Dyn x p
1212unsafeBuildDynamic :: BehaviorM x (PatchTarget p) -> Event x p -> Dyn x p
1209−unsafeBuildDynamic readV0 v' =
1213+unsafeBuildDynamic readV0 v' = Dyn $ unsafeNewIORef x $ UnsafeDyn x
1210− Dyn $ unsafePerformIO $ newIORef $ UnsafeDyn (readV0, v')
1214+ where x = (readV0, v')
1212-- ResultM can read behaviors and events
1216-- ResultM can read behaviors and events
1213type ResultM = EventM
1217type ResultM = EventM
1219+{-# NOINLINE unsafeNewIORef #-}
1220+unsafeNewIORef :: a -> b -> IORef b
1221+unsafeNewIORef a b = unsafePerformIO $ do
1215instance HasSpiderTimeline x => Functor (Event x) where
1225instance HasSpiderTimeline x => Functor (Event x) where
1216 fmap f = push $ return . Just . f
1226 fmap f = push $ return . Just . f
@@ -1224,35 +1234,26 @@ push f e = cacheEvent (pushCheap f e)
1225{-# INLINABLE pull #-}
1235{-# INLINABLE pull #-}
1226pull :: BehaviorM x a -> Behavior x a
1236pull :: BehaviorM x a -> Behavior x a
1227−pull a = unsafePerformIO $ do
1228− ref <- newIORef Nothing
1229−#ifdef DEBUG_NODEIDS
1232− pure $ behaviorPull $ Pull
1237+pull a = behaviorPull $ Pull
1233− { pullCompute = a
1238+ { pullCompute = a
1234− , pullValue = ref
1239+ , pullValue = unsafeNewIORef a Nothing
1235#ifdef DEBUG_NODEIDS
1240#ifdef DEBUG_NODEIDS
1236− , pullNodeId = nid
1241+ , pullNodeId = unsafeNodeId a
1240{-# INLINABLE switch #-}
1245{-# INLINABLE switch #-}
1241switch :: HasSpiderTimeline x => Behavior x (Event x a) -> Event x a
1246switch :: HasSpiderTimeline x => Behavior x (Event x a) -> Event x a
1242−switch a = unsafePerformIO $ do
1243− ref <- newIORef Nothing
1244− pure $ eventSwitch $ Switch
1247+switch a = eventSwitch $ Switch
1245− { switchParent = a
1248+ { switchParent = a
1246− , switchSubscribed = ref
1249+ , switchSubscribed = unsafeNewIORef a Nothing
1249coincidence :: HasSpiderTimeline x => Event x (Event x a) -> Event x a
1252coincidence :: HasSpiderTimeline x => Event x (Event x a) -> Event x a
1250−coincidence a = unsafePerformIO $ do
1251− ref <- newIORef Nothing
1252− pure $ eventCoincidence $ Coincidence
1253+coincidence a = eventCoincidence $ Coincidence
1253− { coincidenceParent = a
1254+ { coincidenceParent = a
1254− , coincidenceSubscribed = ref
1255+ , coincidenceSubscribed = unsafeNewIORef a Nothing
1257-- Propagate the given event occurrence; before cleaning up, run the given action, which may read the state of events and behaviors
1258-- Propagate the given event occurrence; before cleaning up, run the given action, which may read the state of events and behaviors
1258run :: forall x b. HasSpiderTimeline x => [DSum (RootTrigger x) Identity] -> ResultM x b -> SpiderHost x b
1259run :: forall x b. HasSpiderTimeline x => [DSum (RootTrigger x) Identity] -> ResultM x b -> SpiderHost x b
@@ -1456,9 +1457,6 @@ getRootSubscribed k r sub = do
1456 when debugPropagate $ putStrLn $ "getRootSubscribed: calling rootInit"
1457 when debugPropagate $ putStrLn $ "getRootSubscribed: calling rootInit"
1457 uninit <- rootInit r k $ RootTrigger (subs, rootOccurrence r, k)
1458 uninit <- rootInit r k $ RootTrigger (subs, rootOccurrence r, k)
1458 writeIORef uninitRef $! uninit
1459 writeIORef uninitRef $! uninit
1459−#ifdef DEBUG_NODEIDS
1462 let !subscribed = RootSubscribed
1460 let !subscribed = RootSubscribed
1463 { rootSubscribedKey = k
1461 { rootSubscribedKey = k
1464 , rootSubscribedCachedSubscribed = cached
1462 , rootSubscribedCachedSubscribed = cached
@@ -1467,7 +1465,7 @@ getRootSubscribed k r sub = do
1467 , rootSubscribedUninit = uninit
1465 , rootSubscribedUninit = uninit
1468 , rootSubscribedWeakSelf = weakSelf
1466 , rootSubscribedWeakSelf = weakSelf
1469#ifdef DEBUG_NODEIDS
1467#ifdef DEBUG_NODEIDS
1470− , rootSubscribedNodeId = nid
1468+ , rootSubscribedNodeId = unsafeNodeId (k, r, subs)
1473 -- If we die at the same moment that all our children die, they will
1471 -- If we die at the same moment that all our children die, they will
@@ -1516,10 +1514,16 @@ newFanInt = do
1516 , _fanInt_occRef = occRef
1514 , _fanInt_occRef = occRef
1517+{-# NOINLINE unsafeNewFanInt #-}
1518+unsafeNewFanInt :: b -> FanInt x a
1519+unsafeNewFanInt b = unsafePerformIO $ do
1519fanInt :: HasSpiderTimeline x => Event x (IntMap a) -> EventSelectorInt x a
1523fanInt :: HasSpiderTimeline x => Event x (IntMap a) -> EventSelectorInt x a
1520−fanInt p = unsafePerformIO $ do
1524+fanInt p =
1521− self <- newFanInt
1525+ let self = unsafeNewFanInt p
1522− pure $ EventSelectorInt $ \k -> Event $ \sub -> do
1526+ in EventSelectorInt $ \k -> Event $ \sub -> do
1523 isEmpty <- liftIO $ FastMutableIntMap.isEmpty (_fanInt_subscribers self)
1527 isEmpty <- liftIO $ FastMutableIntMap.isEmpty (_fanInt_subscribers self)
1524 when isEmpty $ do -- This is the first subscriber, so we need to subscribe to our input
1528 when isEmpty $ do -- This is the first subscriber, so we need to subscribe to our input
1525 (subscription, parentOcc) <- subscribeAndRead p $ Subscriber
1529 (subscription, parentOcc) <- subscribeAndRead p $ Subscriber
@@ -1555,7 +1559,7 @@ fanInt p = unsafePerformIO $ do
1555 return (EventSubscription (FastWeakBag.remove t) $! EventSubscribed heightRef $! toAny (_fanInt_subscriptionRef self, t), IntMap.lookup k currentOcc)
1559 return (EventSubscription (FastWeakBag.remove t) $! EventSubscribed heightRef $! toAny (_fanInt_subscriptionRef self, t), IntMap.lookup k currentOcc)
1557{-# INLINABLE getFanSubscribed #-}
1561{-# INLINABLE getFanSubscribed #-}
1558−getFanSubscribed :: (HasSpiderTimeline x, GCompare k) => k a -> Fan x k v -> Subscriber x (v a) -> EventM x (WeakBagTicket, FanSubscribed x k v, Maybe (v a))
1562+getFanSubscribed :: (HasSpiderTimeline x, GCompare k) => k a -> Fan x k -> Subscriber x a -> EventM x (WeakBagTicket, FanSubscribed x k, Maybe a)
1559getFanSubscribed k f sub = do
1563getFanSubscribed k f sub = do
1560 mSubscribed <- liftIO $ readIORef $ fanSubscribed f
1564 mSubscribed <- liftIO $ readIORef $ fanSubscribed f
1561 case mSubscribed of
1565 case mSubscribed of
@@ -1573,16 +1577,13 @@ getFanSubscribed k f sub = do
1573 subscribersRef <- liftIO $ newIORef $ error "getFanSubscribed: subscribersRef not yet initialized"
1577 subscribersRef <- liftIO $ newIORef $ error "getFanSubscribed: subscribersRef not yet initialized"
1574 occRef <- liftIO $ newIORef parentOcc
1578 occRef <- liftIO $ newIORef parentOcc
1575 when (isJust parentOcc) $ scheduleClear occRef
1579 when (isJust parentOcc) $ scheduleClear occRef
1576−#ifdef DEBUG_NODEIDS
1577− nid <- liftIO newNodeId
1579 let subscribed = FanSubscribed
1580 let subscribed = FanSubscribed
1580 { fanSubscribedCachedSubscribed = fanSubscribed f
1581 { fanSubscribedCachedSubscribed = fanSubscribed f
1581 , fanSubscribedOccurrence = occRef
1582 , fanSubscribedOccurrence = occRef
1582 , fanSubscribedParent = subscription
1583 , fanSubscribedParent = subscription
1583 , fanSubscribedSubscribers = subscribersRef
1584 , fanSubscribedSubscribers = subscribersRef
1584#ifdef DEBUG_NODEIDS
1585#ifdef DEBUG_NODEIDS
1585− , fanSubscribedNodeId = nid
1586+ , fanSubscribedNodeId = unsafeNodeId f
1588 let !self = (k, subscribed)
1589 let !self = (k, subscribed)
@@ -1592,7 +1593,7 @@ getFanSubscribed k f sub = do
1592 liftIO $ writeIORef (fanSubscribed f) $ Just subscribed
1593 liftIO $ writeIORef (fanSubscribed f) $ Just subscribed
1593 return (slnForSub, subscribed, coerce $ DMap.lookup k =<< parentOcc)
1594 return (slnForSub, subscribed, coerce $ DMap.lookup k =<< parentOcc)
1595−cleanupFanSubscribed :: GCompare k => (k a, FanSubscribed x k v) -> IO ()
1596+cleanupFanSubscribed :: GCompare k => (k a, FanSubscribed x k) -> IO ()
1596cleanupFanSubscribed (k, subscribed) = do
1597cleanupFanSubscribed (k, subscribed) = do
1597 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
1598 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
1598 let reducedSubscribers = DMap.delete k subscribers
1599 let reducedSubscribers = DMap.delete k subscribers
@@ -1604,7 +1605,7 @@ cleanupFanSubscribed (k, subscribed) = do
1604 else writeIORef (fanSubscribedSubscribers subscribed) $! reducedSubscribers
1605 else writeIORef (fanSubscribedSubscribers subscribed) $! reducedSubscribers
1606{-# INLINE subscribeFanSubscribed #-}
1607{-# INLINE subscribeFanSubscribed #-}
1607−subscribeFanSubscribed :: GCompare k => k a -> FanSubscribed x k v -> Subscriber x (v a) -> IO WeakBagTicket
1608+subscribeFanSubscribed :: GCompare k => k a -> FanSubscribed x k -> Subscriber x a -> IO WeakBagTicket
1608subscribeFanSubscribed k subscribed sub = do
1609subscribeFanSubscribed k subscribed sub = do
1609 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
1610 subscribers <- readIORef $ fanSubscribedSubscribers subscribed
1610 case DMap.lookup k subscribers of
1611 case DMap.lookup k subscribers of
@@ -1642,9 +1643,6 @@ getSwitchSubscribed s sub = do
1642 when (isJust parentOcc) $ scheduleClear occRef
1643 when (isJust parentOcc) $ scheduleClear occRef
1643 weakSelf <- liftIO $ newIORef $ error "getSwitchSubscribed: weakSelf not yet initialized"
1644 weakSelf <- liftIO $ newIORef $ error "getSwitchSubscribed: weakSelf not yet initialized"
1644 (subs, slnForSub) <- liftIO $ WeakBag.singleton sub weakSelf cleanupSwitchSubscribed
1645 (subs, slnForSub) <- liftIO $ WeakBag.singleton sub weakSelf cleanupSwitchSubscribed
1645−#ifdef DEBUG_NODEIDS
1646− nid <- liftIO newNodeId
1648 let !subscribed = SwitchSubscribed
1646 let !subscribed = SwitchSubscribed
1649 { switchSubscribedCachedSubscribed = switchSubscribed s
1647 { switchSubscribedCachedSubscribed = switchSubscribed s
1650 , switchSubscribedOccurrence = occRef
1648 , switchSubscribedOccurrence = occRef
@@ -1657,7 +1655,7 @@ getSwitchSubscribed s sub = do
1657 , switchSubscribedCurrentParent = subscriptionRef
1655 , switchSubscribedCurrentParent = subscriptionRef
1658 , switchSubscribedWeakSelf = weakSelf
1656 , switchSubscribedWeakSelf = weakSelf
1659#ifdef DEBUG_NODEIDS
1657#ifdef DEBUG_NODEIDS
1660− , switchSubscribedNodeId = nid
1658+ , switchSubscribedNodeId = unsafeNodeId s
1663 liftIO $ writeIORef weakSelf =<< evaluate =<< mkWeakPtrWithDebug subscribed "switchSubscribedWeakSelf"
1661 liftIO $ writeIORef weakSelf =<< evaluate =<< mkWeakPtrWithDebug subscribed "switchSubscribedWeakSelf"
@@ -1702,9 +1700,6 @@ getCoincidenceSubscribed c sub = do
1702 scheduleClear innerSubdRef
1700 scheduleClear innerSubdRef
1703 weakSelf <- liftIO $ newIORef $ error "getCoincidenceSubscribed: weakSelf not yet implemented"
1701 weakSelf <- liftIO $ newIORef $ error "getCoincidenceSubscribed: weakSelf not yet implemented"
1704 (subs, slnForSub) <- liftIO $ WeakBag.singleton sub weakSelf cleanupCoincidenceSubscribed
1702 (subs, slnForSub) <- liftIO $ WeakBag.singleton sub weakSelf cleanupCoincidenceSubscribed
1705−#ifdef DEBUG_NODEIDS
1706− nid <- liftIO newNodeId
1708 let subscribed = CoincidenceSubscribed
1703 let subscribed = CoincidenceSubscribed
1709 { coincidenceSubscribedCachedSubscribed = coincidenceSubscribed c
1704 { coincidenceSubscribedCachedSubscribed = coincidenceSubscribed c
1710 , coincidenceSubscribedOccurrence = occRef
1705 , coincidenceSubscribedOccurrence = occRef
@@ -1715,7 +1710,7 @@ getCoincidenceSubscribed c sub = do
1715 , coincidenceSubscribedInnerParent = innerSubdRef
1710 , coincidenceSubscribedInnerParent = innerSubdRef
1716 , coincidenceSubscribedWeakSelf = weakSelf
1711 , coincidenceSubscribedWeakSelf = weakSelf
1717#ifdef DEBUG_NODEIDS
1712#ifdef DEBUG_NODEIDS
1718− , coincidenceSubscribedNodeId = nid
1713+ , coincidenceSubscribedNodeId = unsafeNodeId c
1721 liftIO $ writeIORef weakSelf =<< evaluate =<< mkWeakPtrWithDebug subscribed "CoincidenceSubscribed"
1716 liftIO $ writeIORef weakSelf =<< evaluate =<< mkWeakPtrWithDebug subscribed "CoincidenceSubscribed"
@@ -2086,16 +2081,14 @@ mergeIntCheap d = Event $ \sub -> do
2088newtype EventSelector x k = EventSelector { select :: forall a. k a -> Event x a }
2083newtype EventSelector x k = EventSelector { select :: forall a. k a -> Event x a }
2089−newtype EventSelectorG x k v = EventSelectorG { selectG :: forall a. k a -> Event x (v a) }
2091−fanG :: (HasSpiderTimeline x, GCompare k) => Event x (DMap k v) -> EventSelectorG x k v
2085+fan :: (HasSpiderTimeline x, GCompare k) => Event x (DMap k Identity) -> EventSelector x k
2092−fanG e = unsafePerformIO $ do
2086+fan e =
2093− ref <- newIORef Nothing
2094 let f = Fan
2087 let f = Fan
2095 { fanParent = e
2088 { fanParent = e
2096− , fanSubscribed = ref
2089+ , fanSubscribed = unsafeNewIORef e Nothing
2098− pure $ EventSelectorG $ \k -> eventFan k f
2091+ in EventSelector $ \k -> eventFan k f
2100runHoldInits :: HasSpiderTimeline x => IORef [SomeHoldInit x] -> IORef [SomeDynInit x] -> IORef [SomeMergeInit x] -> EventM x ()
2093runHoldInits :: HasSpiderTimeline x => IORef [SomeHoldInit x] -> IORef [SomeDynInit x] -> IORef [SomeMergeInit x] -> EventM x ()
2101runHoldInits holdInitRef dynInitRef mergeInitRef = do
2094runHoldInits holdInitRef dynInitRef mergeInitRef = do
@@ -2564,8 +2557,6 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
2564 pushCheap f = SpiderEvent . pushCheap (coerce f) . unSpiderEvent
2557 pushCheap f = SpiderEvent . pushCheap (coerce f) . unSpiderEvent
2565 {-# INLINABLE pull #-}
2558 {-# INLINABLE pull #-}
2566 pull = SpiderBehavior . pull . coerce
2559 pull = SpiderBehavior . pull . coerce
2567− {-# INLINABLE fanG #-}
2568− fanG e = R.EventSelectorG $ SpiderEvent . selectG (fanG (unSpiderEvent e))
2569 {-# INLINABLE mergeG #-}
2560 {-# INLINABLE mergeG #-}
2571 :: forall (k :: k2 -> *) q (v :: k2 -> *). GCompare k
2562 :: forall (k :: k2 -> *) q (v :: k2 -> *). GCompare k
@@ -2573,6 +2564,8 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
2573 -> DMap k q
2564 -> DMap k q
2574 -> R.Event (SpiderTimeline x) (DMap k v)
2565 -> R.Event (SpiderTimeline x) (DMap k v)
2575 mergeG nt = SpiderEvent . mergeG (unSpiderEvent #. nt) . dynamicConst
2566 mergeG nt = SpiderEvent . mergeG (unSpiderEvent #. nt) . dynamicConst
2567+ {-# INLINABLE fan #-}
2568+ fan e = R.EventSelector $ SpiderEvent . select (fan (unSpiderEvent e))
2576 {-# INLINABLE switch #-}
2569 {-# INLINABLE switch #-}
2577 switch = SpiderEvent . switch . (coerce :: Behavior x (R.Event (SpiderTimeline x) a) -> Behavior x (Event x a)) . unSpiderBehavior
2570 switch = SpiderEvent . switch . (coerce :: Behavior x (R.Event (SpiderTimeline x) a) -> Behavior x (Event x a)) . unSpiderBehavior
2578 {-# INLINABLE coincidence #-}
2571 {-# INLINABLE coincidence #-}