on develop help sign in
Get rid of specialize-to-spidertimeline-global flag
commit1782d8a7da795fb8738b74d03c5737dabdfcce9e authorRyan Trinkle <ryan.trinkle@gmail.com> dateFri 13 Jul 2018, 22:38 (8 years ago) parentec878b8
7 files changed+203−402
reflex.cabal+9−24 src/Reflex/Class.hs−127 src/Reflex/Host/Class.hs−13 src/Reflex/Spider.hs−5 src/Reflex/Spider/Internal.hs+194−21 src/Reflex/Spider/SpiderTimeline.include.hs−155 src/Reflex/Spider/SpiderTimelineHost.include.hs−57
reflex.cabal+9−24
@@ -13,11 +13,6 @@ Cabal-version: >=1.9.2
1313homepage: https://github.com/reflex-frp/reflex
1414bug-reports: https://github.com/reflex-frp/reflex/issues
1515
16−flag specialize-to-spidertimeline-global
17− description: Specialize all Reflex functions to the SpiderTimeline Global implementation. This may improve performance, but will disable all other implementations.
18− default: False
19− manual: True
20−
2116flag use-reflex-optimizer
2217 description: Use the GHC plugin Reflex.Optimizer on some of the modules in the package. This is still experimental.
2318 default: False
@@ -69,22 +64,22 @@ library
6964
7065 exposed-modules:
7166 Data.AppendMap,
72− Data.Map.Misc,
67+ Data.FastMutableIntMap,
68+ Data.FastWeakBag,
7369 Data.Functor.Misc,
70+ Data.Map.Misc,
7471 Data.WeakBag,
75− Data.FastWeakBag,
76− Data.FastMutableIntMap,
7772 Reflex,
7873 Reflex.Class,
7974 Reflex.Collection,
80− Reflex.EventWriter,
81− Reflex.EventWriter.Base,
82− Reflex.EventWriter.Class,
8375 Reflex.Dynamic,
8476 Reflex.Dynamic.Uniq,
8577 Reflex.DynamicWriter,
8678 Reflex.DynamicWriter.Base,
8779 Reflex.DynamicWriter.Class,
80+ Reflex.EventWriter,
81+ Reflex.EventWriter.Base,
82+ Reflex.EventWriter.Class,
8883 Reflex.FastWeak,
8984 Reflex.FunctorMaybe,
9085 Reflex.Host.Class,
@@ -97,13 +92,12 @@ library
9792 Reflex.Patch.IntMap,
9893 Reflex.Patch.Map,
9994 Reflex.Patch.MapWithMove,
100− Reflex.TriggerEvent.Base,
101− Reflex.TriggerEvent.Class,
10295 Reflex.PerformEvent.Base,
10396 Reflex.PerformEvent.Class,
10497 Reflex.PostBuild.Base,
10598 Reflex.PostBuild.Class,
10699 Reflex.Profiled,
100+ Reflex.Pure,
107101 Reflex.Query.Base,
108102 Reflex.Query.Class,
109103 Reflex.Requester.Base,
@@ -111,17 +105,14 @@ library
111105 Reflex.Spider,
112106 Reflex.Spider.Internal,
113107 Reflex.Time,
108+ Reflex.TriggerEvent.Base,
109+ Reflex.TriggerEvent.Class,
114110 Reflex.Widget.Basic,
115111 Reflex.Workflow
116112
117113 ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -fspecialise-aggressively -ddump-simpl -ddump-to-file -dsuppress-coercions -dsuppress-idinfo
118114 ghc-prof-options: -fprof-auto
119115
120− if flag(specialize-to-spidertimeline-global)
121− cpp-options: -DSPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
122− else
123− exposed-modules: Reflex.Pure
124−
125116 if flag(debug-trace-events)
126117 cpp-options: -DDEBUG_TRACE_EVENTS
127118 build-depends: bytestring
@@ -168,8 +159,6 @@ test-suite semantics
168159 reflex,
169160 split,
170161 transformers >= 0.3
171− if flag(specialize-to-spidertimeline-global)
172− buildable: False
173162
174163test-suite CrossImpl
175164 type: exitcode-stdio-1.0
@@ -183,8 +172,6 @@ test-suite CrossImpl
183172 mtl,
184173 ref-tf,
185174 reflex
186− if flag(specialize-to-spidertimeline-global)
187− buildable: False
188175
189176test-suite hlint
190177 type: exitcode-stdio-1.0
@@ -244,8 +231,6 @@ test-suite GC-Semantics
244231 type: exitcode-stdio-1.0
245232 main-is: GC.hs
246233 hs-source-dirs: test
247− if flag(specialize-to-spidertimeline-global)
248− buildable: False
249234 build-depends: base
250235 , dependent-sum
251236 , dependent-map
src/Reflex/Class.hs−127
@@ -19,10 +19,6 @@
1919#ifdef USE_REFLEX_OPTIMIZER
2020{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
2121#endif
22−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
23−{-# LANGUAGE EmptyDataDecls #-}
24−{-# OPTIONS_GHC -Wno-redundant-constraints #-}
25−#endif
2622
2723-- | This module contains the Reflex interface, as well as a variety of
2824-- convenience functions for working with 'Event's, 'Behavior's, and other
@@ -148,37 +144,6 @@ module Reflex.Class
148144 , switchPromptOnly
149145 -- * Slow, but general, implementations
150146 , slowHeadE
151−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
152− , Spider
153− , SpiderEnv
154− , SpiderTimeline
155− , Global
156− , Behavior (..)
157− , Event (..)
158− , Dynamic (..)
159− , Incremental (..)
160− , never
161− , constant
162− , push
163− , pushCheap
164− , pull
165− , merge
166− , fan
167− , switch
168− , coincidence
169− , current
170− , updated
171− , unsafeBuildDynamic
172− , unsafeBuildIncremental
173− , mergeIncremental
174− , mergeIncrementalWithMove
175− , currentIncremental
176− , updatedIncremental
177− , incrementalToDynamic
178− , behaviorCoercion
179− , eventCoercion
180− , dynamicCoercion
181−#endif
182147 ) where
183148
184149import Control.Applicative
@@ -217,26 +182,11 @@ import Reflex.FunctorMaybe
217182import Reflex.Patch
218183import Data.FastMutableIntMap (PatchIntMap)
219184
220−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
221−import Reflex.Spider.Internal (EventM, Global, HasSpiderTimeline, SpiderHost (..), SpiderHostFrame (..),
222− SpiderPullM, SpiderPushM (..), behaviorHoldIdentity, dynamicConst,
223− dynamicCurrent, dynamicDynIdentity, dynamicHold, dynamicHoldIdentity,
224− dynamicUpdated, newMapDyn, readBehaviorTracked, readBehaviorUntracked,
225− runFrame, runSpiderHostFrame)
226−import qualified Reflex.Spider.Internal
227−import qualified Reflex.Spider.Internal as S
228−import Unsafe.Coerce
229−#endif
230−
231185-- Note: must come last to silence warnings due to AMP on GHC < 7.10
232186import Prelude hiding (foldl, mapM, mapM_, sequence, sequence_)
233187
234188import Debug.Trace (trace)
235189
236−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
237−#include "Spider/SpiderTimeline.include.hs"
238−#endif
239−
240190-- | The 'Reflex' class contains all the primitive functionality needed for
241191-- Functional Reactive Programming (FRP). The @t@ type parameter indicates
242192-- which "timeline" is in use. Timelines are fully-independent FRP contexts,
@@ -248,9 +198,6 @@ class ( MonadHold t (PushM t)
248198 , Functor (Dynamic t)
249199 , Applicative (Dynamic t) -- Necessary for GHC <= 7.8
250200 , Monad (Dynamic t)
251−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
252− , t ~ SpiderTimeline Global
253−#endif
254201 ) => Reflex t where
255202 -- | A container for a value that can change over time. 'Behavior's can be
256203 -- sampled at will, but it is not possible to be notified when they change
@@ -273,7 +220,6 @@ class ( MonadHold t (PushM t)
273220 type PushM t :: * -> *
274221 -- | A monad for doing complex pull-based calculations efficiently
275222 type PullM t :: * -> *
276−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
277223 -- | An 'Event' with no occurrences
278224 never :: Event t a
279225 -- | Create a 'Behavior' that always has the given value
@@ -333,84 +279,11 @@ class ( MonadHold t (PushM t)
333279 dynamicCoercion :: Coercion a b -> Coercion (Dynamic t a) (Dynamic t b)
334280 mergeIntIncremental :: Incremental t (PatchIntMap (Event t a)) -> Event t (IntMap a)
335281 fanInt :: Event t (IntMap a) -> EventSelectorInt t a
336−#endif
337282
338283--TODO: Specialize this so that we can take advantage of knowing that there's no changing going on
339284mergeInt :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
340285mergeInt m = mergeIntIncremental $ unsafeBuildIncremental (return m) never
341286
342−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
343−instance t ~ SpiderTimeline Global => Reflex t where
344− newtype Behavior t a = SpiderBehavior { unSpiderBehavior :: Reflex.Spider.Internal.Behavior Global a }
345− newtype Event t a = SpiderEvent { unSpiderEvent :: Reflex.Spider.Internal.Event Global a }
346− newtype Dynamic t a = SpiderDynamic { unSpiderDynamic :: Reflex.Spider.Internal.Dynamic Global (Identity a) } -- deriving (Functor, Applicative, Monad)
347− newtype Incremental t p = SpiderIncremental { unSpiderIncremental :: Reflex.Spider.Internal.Dynamic Global p }
348− type PullM t = SpiderPullM Global
349− type PushM t = SpiderPushM Global
350−never :: Reflex t => Event t a
351−constant :: Reflex t => a -> Behavior t a
352−push :: Reflex t => (a -> PushM t (Maybe b)) -> Event t a -> Event t b
353−pushCheap :: Reflex t => (a -> PushM t (Maybe b)) -> Event t a -> Event t b
354−pull :: Reflex t => PullM t a -> Behavior t a
355−merge :: (Reflex t, GCompare k) => DMap k (Event t) -> Event t (DMap k Identity)
356−fan :: (Reflex t, GCompare k) => Event t (DMap k Identity) -> EventSelector t k
357−switch :: Reflex t => Behavior t (Event t a) -> Event t a
358−coincidence :: Reflex t => Event t (Event t a) -> Event t a
359−current :: Reflex t => Dynamic t a -> Behavior t a
360−updated :: Reflex t => Dynamic t a -> Event t a
361−unsafeBuildDynamic :: Reflex t => PullM t a -> Event t a -> Dynamic t a
362−unsafeBuildIncremental :: (Reflex t, Patch p) => PullM t (PatchTarget p) -> Event t p -> Incremental t p
363−mergeIncremental :: (Reflex t, GCompare k) => Incremental t (PatchDMap k (Event t)) -> Event t (DMap k Identity)
364−mergeIncrementalWithMove :: (Reflex t, GCompare k) => Incremental t (PatchDMapWithMove k (Event t)) -> Event t (DMap k Identity)
365−currentIncremental :: (Reflex t, Patch p) => Incremental t p -> Behavior t (PatchTarget p)
366−updatedIncremental :: (Reflex t, Patch p) => Incremental t p -> Event t p
367−incrementalToDynamic :: (Reflex t, Patch p) => Incremental t p -> Dynamic t (PatchTarget p)
368−behaviorCoercion :: Reflex t => Coercion a b -> Coercion (Behavior t a) (Behavior t b)
369−eventCoercion :: Reflex t => Coercion a b -> Coercion (Event t a) (Event t b)
370−dynamicCoercion :: Reflex t => Coercion a b -> Coercion (Dynamic t a) (Dynamic t b)
371−{-# INLINE never #-}
372−never = SpiderEvent S.eventNever
373−{-# INLINE constant #-}
374−constant = SpiderBehavior . S.behaviorConst
375−{-# INLINE push #-}
376−push f = SpiderEvent . S.push (coerce f) . unSpiderEvent
377−{-# INLINE pushCheap #-}
378−pushCheap f = SpiderEvent . S.pushCheap (coerce f) . unSpiderEvent
379−{-# INLINE pull #-}
380−pull = SpiderBehavior . S.pull . coerce
381−{-# INLINE merge #-}
382−merge = SpiderEvent . S.merge . S.dynamicConst . (coerce :: DMap k (Event (SpiderTimeline x)) -> DMap k (S.Event x))
383−{-# INLINE fan #-}
384−fan e = EventSelector $ SpiderEvent . S.select (S.fan (unSpiderEvent e))
385−{-# INLINE switch #-}
386−switch = SpiderEvent . S.switch . (coerce :: S.Behavior x (Event (SpiderTimeline x) a) -> S.Behavior x (S.Event x a)) . unSpiderBehavior
387−{-# INLINE coincidence #-}
388−coincidence = SpiderEvent . S.coincidence . (coerce :: S.Event x (Event (SpiderTimeline x) a) -> S.Event x (S.Event x a)) . unSpiderEvent
389−{-# INLINE current #-}
390−current = SpiderBehavior . S.dynamicCurrent . unSpiderDynamic
391−{-# INLINE updated #-}
392−updated = coerceEvent . SpiderEvent . dynamicUpdated . unSpiderDynamic
393−{-# INLINE unsafeBuildDynamic #-}
394−unsafeBuildDynamic readV0 v' = SpiderDynamic $ dynamicDynIdentity $ S.unsafeBuildDynamic (coerce readV0) $ coerce $ unSpiderEvent v'
395−{-# INLINE unsafeBuildIncremental #-}
396−unsafeBuildIncremental readV0 dv = SpiderIncremental $ S.dynamicDyn $ S.unsafeBuildDynamic (coerce readV0) $ unSpiderEvent dv
397−{-# INLINE mergeIncremental #-}
398−mergeIncremental = SpiderEvent . S.merge . (unsafeCoerce :: S.Dynamic x (PatchDMap k (Event (SpiderTimeline x))) -> S.Dynamic x (PatchDMap k (S.Event x))) . unSpiderIncremental
399−{-# INLINE mergeIncrementalWithMove #-}
400−mergeIncrementalWithMove = SpiderEvent . S.mergeWithMove . (unsafeCoerce :: S.Dynamic x (PatchDMapWithMove k (Event (SpiderTimeline x))) -> S.Dynamic x (PatchDMapWithMove k (S.Event x))) . unSpiderIncremental
401−{-# INLINE currentIncremental #-}
402−currentIncremental = SpiderBehavior . dynamicCurrent . unSpiderIncremental
403−{-# INLINE updatedIncremental #-}
404−updatedIncremental = SpiderEvent . dynamicUpdated . unSpiderIncremental
405−{-# INLINE incrementalToDynamic #-}
406−incrementalToDynamic (SpiderIncremental i) = SpiderDynamic $ dynamicDynIdentity $ S.unsafeBuildDynamic (readBehaviorUntracked $ dynamicCurrent i) $ flip S.push (dynamicUpdated i) $ \p -> do
407− c <- readBehaviorUntracked $ dynamicCurrent i
408− return $ Identity <$> apply p c
409−eventCoercion Coercion = Coercion
410−behaviorCoercion Coercion = Coercion
411−dynamicCoercion = unsafeCoerce
412−#endif
413−
414287-- | Coerce a 'Behavior' between representationally-equivalent value types
415288coerceBehavior :: (Reflex t, Coercible a b) => Behavior t a -> Behavior t b
416289coerceBehavior = coerceWith $ behaviorCoercion Coercion
src/Reflex/Host/Class.hs−13
@@ -47,22 +47,9 @@ import Data.Dependent.Sum (DSum (..))
4747import Data.GADT.Compare
4848import Data.Monoid
4949
50−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
51−import Control.Monad.Primitive (touch)
52−import Data.IORef
53−import Reflex.Spider.Internal (EventM (..), HasSpiderTimeline, RootTrigger, SpiderEventHandle (..),
54− SpiderHost (..), SpiderHostFrame (..), Subscriber (..), newEventWithTriggerIO,
55− newFanEventWithTriggerIO, run, runFrame, scheduleClear, subscribe)
56−import qualified Reflex.Spider.Internal
57−#endif
58−
5950-- Note: this import must come last to silence warnings from AMP
6051import Prelude hiding (foldl, mapM, mapM_, sequence, sequence_)
6152
62−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
63−#include "../Spider/SpiderTimelineHost.include.hs"
64−#endif
65−
6653-- | Framework implementation support class for the reflex implementation
6754-- represented by @t@.
6855class ( Reflex t
src/Reflex/Spider.hs−5
@@ -7,16 +7,11 @@ module Reflex.Spider
77 , Global
88 , SpiderHost
99 , runSpiderHost
10−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
1110 , runSpiderHostForTimeline
1211 , newSpiderTimeline
1312 , withSpiderTimeline
14−#endif
1513 -- * Deprecated
1614 , SpiderEnv
1715 ) where
1816
19−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
20−import Reflex.Class
21−#endif
2217import Reflex.Spider.Internal
src/Reflex/Spider/Internal.hs+194−21
@@ -21,9 +21,6 @@
2121#ifdef USE_REFLEX_OPTIMIZER
2222{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
2323#endif
24−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
25−{-# OPTIONS_GHC -fno-warn-orphans #-}
26−#endif
2724-- | This module is the implementation of the 'Spider' 'Reflex' engine. It uses
2825-- a graph traversal algorithm to propagate 'Event's and 'Behavior's.
2926module Reflex.Spider.Internal (module Reflex.Spider.Internal) where
@@ -80,7 +77,6 @@ import Data.FastWeakBag (FastWeakBag)
8077import qualified Data.FastWeakBag as FastWeakBag
8178import Data.WeakBag (WeakBag, WeakBagTicket, _weakBag_children)
8279import qualified Data.WeakBag as WeakBag
83−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
8480import Data.Reflection
8581import Data.Some (Some)
8682import qualified Data.Some as Some
@@ -88,7 +84,6 @@ import Data.Type.Coercion
8884import qualified Reflex.Class
8985import qualified Reflex.Class as R
9086import qualified Reflex.Host.Class
91−#endif
9287import Reflex.NotReady.Class
9388import Reflex.Patch
9489import qualified Reflex.Patch.DMapWithMove as PatchDMapWithMove
@@ -760,9 +755,7 @@ data Hold x p
760755#endif
761756 }
762757
763−-- | A statically allocated 'SpiderTimeline'; this is the only instance of
764−-- 'SpiderTimeline' that can used when using
765−-- -fspecialize-to-spidertimeline-global.
758+-- | A statically allocated 'SpiderTimeline'
766759data Global
767760
768761{-# NOINLINE globalSpiderTimelineEnv #-}
@@ -856,11 +849,7 @@ instance HasSpiderTimeline x => HasCurrentHeight x (EventM x) where
856849 delayedRef <- asksEventEnv eventEnvDelayedMerges
857850 liftIO $ modifyIORef' delayedRef $ IntMap.insertWith (++) (unHeight height) [subscribed]
858851
859−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
860−class x ~ Global => HasSpiderTimeline x where
861−#else
862852class HasSpiderTimeline x where
863−#endif
864853 -- | Retrieve the current SpiderTimelineEnv
865854 spiderTimeline :: SpiderTimelineEnv x
866855
@@ -2246,13 +2235,203 @@ invalidate toReconnectRef wis = do
22462235-- Reflex integration
22472236--------------------------------------------------------------------------------
22482237
2249−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
22502238-- When we're specializing, we include this from Reflex.Class instead, because
22512239-- it needs access to these types; when we're not, we want them here, so our
22522240-- instance isn't an orphan instance.
2253−#include "SpiderTimeline.include.hs"
2254−#include "SpiderTimelineHost.include.hs"
2241+-- | Designates the default, global Spider timeline
2242+data SpiderTimeline x
2243+type role SpiderTimeline nominal
2244+
2245+-- | The default, global Spider environment
2246+type Spider = SpiderTimeline Global
2247+
2248+instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (EventM x) where
2249+ {-# INLINABLE sample #-}
2250+ sample (SpiderBehavior b) = readBehaviorUntracked b
2251+
2252+instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (EventM x) where
2253+ {-# INLINABLE hold #-}
2254+ hold = holdSpiderEventM
2255+ {-# INLINABLE holdDyn #-}
2256+ holdDyn = holdDynSpiderEventM
2257+ {-# INLINABLE holdIncremental #-}
2258+ holdIncremental = holdIncrementalSpiderEventM
2259+ {-# INLINABLE buildDynamic #-}
2260+ buildDynamic = buildDynamicSpiderEventM
2261+ {-# INLINABLE headE #-}
2262+ headE = R.slowHeadE
2263+-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
2264+
2265+instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
2266+ {-# INLINABLE sample #-}
2267+ sample = coerce . readBehaviorTracked . unSpiderBehavior
2268+
2269+instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPushM x) where
2270+ {-# INLINABLE sample #-}
2271+ sample (SpiderBehavior b) = SpiderPushM $ readBehaviorUntracked b
2272+
2273+instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (SpiderPushM x) where
2274+ {-# INLINABLE hold #-}
2275+ hold v0 e = Reflex.Class.current <$> Reflex.Class.holdDyn v0 e
2276+ {-# INLINABLE holdDyn #-}
2277+ holdDyn v0 (SpiderEvent e) = SpiderPushM $ fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce e
2278+ {-# INLINABLE holdIncremental #-}
2279+ holdIncremental v0 (SpiderEvent e) = SpiderPushM $ SpiderIncremental . dynamicHold <$> Reflex.Spider.Internal.hold v0 e
2280+ {-# INLINABLE buildDynamic #-}
2281+ buildDynamic getV0 (SpiderEvent e) = SpiderPushM $ fmap (SpiderDynamic . dynamicDynIdentity) $ Reflex.Spider.Internal.buildDynamic (coerce getV0) $ coerce e
2282+ {-# INLINABLE headE #-}
2283+ headE = R.slowHeadE
2284+-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2285+
2286+instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
2287+ {-# INLINE return #-}
2288+ return = pure
2289+ {-# INLINE (>>=) #-}
2290+ x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
2291+ {-# INLINE (>>) #-}
2292+ (>>) = (*>)
2293+ {-# INLINE fail #-}
2294+ fail _ = error "Dynamic does not support 'fail'"
2295+
2296+{-# INLINABLE newJoinDyn #-}
2297+newJoinDyn :: HasSpiderTimeline x => Reflex.Spider.Internal.Dynamic x (Identity (Reflex.Spider.Internal.Dynamic x (Identity a))) -> Reflex.Spider.Internal.Dyn x (Identity a)
2298+newJoinDyn d =
2299+ let readV0 = readBehaviorTracked . dynamicCurrent =<< readBehaviorTracked (dynamicCurrent d)
2300+ eOuter = Reflex.Spider.Internal.push (fmap (Just . Identity) . readBehaviorUntracked . dynamicCurrent . runIdentity) $ dynamicUpdated d
2301+ eInner = Reflex.Spider.Internal.switch $ dynamicUpdated <$> dynamicCurrent d
2302+ eBoth = Reflex.Spider.Internal.coincidence $ dynamicUpdated . runIdentity <$> dynamicUpdated d
2303+ v' = unSpiderEvent $ Reflex.Class.leftmost $ map SpiderEvent [eBoth, eOuter, eInner]
2304+ in Reflex.Spider.Internal.unsafeBuildDynamic readV0 v'
2305+
2306+instance HasSpiderTimeline x => Functor (Reflex.Class.Dynamic (SpiderTimeline x)) where
2307+ fmap f = SpiderDynamic . newMapDyn f . unSpiderDynamic
2308+ x <$ d = R.unsafeBuildDynamic (return x) $ x <$ R.updated d
2309+
2310+instance HasSpiderTimeline x => Applicative (Reflex.Class.Dynamic (SpiderTimeline x)) where
2311+ pure = SpiderDynamic . dynamicConst
2312+#if MIN_VERSION_base(4,10,0)
2313+ liftA2 f a b = SpiderDynamic $ Reflex.Spider.Internal.zipDynWith f (unSpiderDynamic a) (unSpiderDynamic b)
22552314#endif
2315+ SpiderDynamic a <*> SpiderDynamic b = SpiderDynamic $ Reflex.Spider.Internal.zipDynWith ($) a b
2316+ a *> b = R.unsafeBuildDynamic (R.sample $ R.current b) $ R.leftmost [R.updated b, R.tag (R.current b) $ R.updated a]
2317+ (<*) = flip (*>) -- There are no effects, so order doesn't matter
2318+
2319+holdSpiderEventM :: HasSpiderTimeline x => a -> Reflex.Class.Event (SpiderTimeline x) a -> EventM x (Reflex.Class.Behavior (SpiderTimeline x) a)
2320+holdSpiderEventM v0 e = fmap (SpiderBehavior . behaviorHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
2321+
2322+holdDynSpiderEventM :: HasSpiderTimeline x => a -> Reflex.Class.Event (SpiderTimeline x) a -> EventM x (Reflex.Class.Dynamic (SpiderTimeline x) a)
2323+holdDynSpiderEventM v0 e = fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
2324+
2325+holdIncrementalSpiderEventM :: (HasSpiderTimeline x, Patch p) => PatchTarget p -> Reflex.Class.Event (SpiderTimeline x) p -> EventM x (Reflex.Class.Incremental (SpiderTimeline x) p)
2326+holdIncrementalSpiderEventM v0 e = fmap (SpiderIncremental . dynamicHold) $ Reflex.Spider.Internal.hold v0 $ unSpiderEvent e
2327+
2328+buildDynamicSpiderEventM :: HasSpiderTimeline x => SpiderPullM x a -> Reflex.Class.Event (SpiderTimeline x) a -> EventM x (Reflex.Class.Dynamic (SpiderTimeline x) a)
2329+buildDynamicSpiderEventM getV0 e = fmap (SpiderDynamic . dynamicDynIdentity) $ Reflex.Spider.Internal.buildDynamic (coerce getV0) $ coerce $ unSpiderEvent e
2330+
2331+instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (SpiderHost x) where
2332+ {-# INLINABLE hold #-}
2333+ hold v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.hold v0 e
2334+ {-# INLINABLE holdDyn #-}
2335+ holdDyn v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.holdDyn v0 e
2336+ {-# INLINABLE holdIncremental #-}
2337+ holdIncremental v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.holdIncremental v0 e
2338+ {-# INLINABLE buildDynamic #-}
2339+ buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
2340+ {-# INLINABLE headE #-}
2341+ headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
2342+
2343+instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
2344+ sample = SpiderHostFrame . readBehaviorUntracked . unSpiderBehavior --TODO: This can cause problems with laziness, so we should get rid of it if we can
2345+
2346+instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (SpiderHostFrame x) where
2347+ {-# INLINABLE hold #-}
2348+ hold v0 e = SpiderHostFrame $ fmap (SpiderBehavior . behaviorHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
2349+ {-# INLINABLE holdDyn #-}
2350+ holdDyn v0 e = SpiderHostFrame $ fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
2351+ {-# INLINABLE holdIncremental #-}
2352+ holdIncremental v0 e = SpiderHostFrame $ fmap (SpiderIncremental . dynamicHold) $ Reflex.Spider.Internal.hold v0 $ unSpiderEvent e
2353+ {-# INLINABLE buildDynamic #-}
2354+ buildDynamic getV0 e = SpiderHostFrame $ fmap (SpiderDynamic . dynamicDynIdentity) $ Reflex.Spider.Internal.buildDynamic (coerce getV0) $ coerce $ unSpiderEvent e
2355+ {-# INLINABLE headE #-}
2356+ headE = R.slowHeadE
2357+-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
2358+
2359+instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
2360+ {-# INLINABLE sample #-}
2361+ sample = runFrame . readBehaviorUntracked . unSpiderBehavior
2362+
2363+instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (Reflex.Spider.Internal.ReadPhase x) where
2364+ {-# INLINABLE sample #-}
2365+ sample = Reflex.Spider.Internal.ReadPhase . Reflex.Class.sample
2366+
2367+instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Reflex.Spider.Internal.ReadPhase x) where
2368+ {-# INLINABLE hold #-}
2369+ hold v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.hold v0 e
2370+ {-# INLINABLE holdDyn #-}
2371+ holdDyn v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.holdDyn v0 e
2372+ {-# INLINABLE holdIncremental #-}
2373+ holdIncremental v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.holdIncremental v0 e
2374+ {-# INLINABLE buildDynamic #-}
2375+ buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
2376+ {-# INLINABLE headE #-}
2377+ headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
2378+
2379+--------------------------------------------------------------------------------
2380+-- Deprecated items
2381+--------------------------------------------------------------------------------
2382+
2383+-- | 'SpiderEnv' is the old name for 'SpiderTimeline'
2384+{-# DEPRECATED SpiderEnv "Use 'SpiderTimelineEnv' instead" #-}
2385+type SpiderEnv = SpiderTimeline
2386+instance HasSpiderTimeline x => Reflex.Host.Class.MonadSubscribeEvent (SpiderTimeline x) (SpiderHostFrame x) where
2387+ {-# INLINABLE subscribeEvent #-}
2388+ subscribeEvent e = SpiderHostFrame $ do
2389+ --TODO: Unsubscribe eventually (manually and/or with weak ref)
2390+ val <- liftIO $ newIORef Nothing
2391+ subscription <- subscribe (unSpiderEvent e) $ Subscriber
2392+ { subscriberPropagate = \a -> do
2393+ liftIO $ writeIORef val $ Just a
2394+ scheduleClear val
2395+ , subscriberInvalidateHeight = \_ -> return ()
2396+ , subscriberRecalculateHeight = \_ -> return ()
2397+ }
2398+ return $ SpiderEventHandle
2399+ { spiderEventHandleSubscription = subscription
2400+ , spiderEventHandleValue = val
2401+ }
2402+
2403+instance HasSpiderTimeline x => Reflex.Host.Class.ReflexHost (SpiderTimeline x) where
2404+ type EventTrigger (SpiderTimeline x) = RootTrigger x
2405+ type EventHandle (SpiderTimeline x) = SpiderEventHandle x
2406+ type HostFrame (SpiderTimeline x) = SpiderHostFrame x
2407+
2408+instance HasSpiderTimeline x => Reflex.Host.Class.MonadReadEvent (SpiderTimeline x) (Reflex.Spider.Internal.ReadPhase x) where
2409+ {-# NOINLINE readEvent #-}
2410+ readEvent h = Reflex.Spider.Internal.ReadPhase $ fmap (fmap return) $ liftIO $ do
2411+ result <- readIORef $ spiderEventHandleValue h
2412+ touch h
2413+ return result
2414+
2415+instance Reflex.Host.Class.MonadReflexCreateTrigger (SpiderTimeline x) (SpiderHost x) where
2416+ newEventWithTrigger = SpiderHost . lift . fmap SpiderEvent . newEventWithTriggerIO
2417+ newFanEventWithTrigger f = SpiderHost $ lift $ do
2418+ es <- newFanEventWithTriggerIO f
2419+ return $ Reflex.Class.EventSelector $ SpiderEvent . Reflex.Spider.Internal.select es
2420+
2421+instance Reflex.Host.Class.MonadReflexCreateTrigger (SpiderTimeline x) (SpiderHostFrame x) where
2422+ newEventWithTrigger = SpiderHostFrame . EventM . liftIO . fmap SpiderEvent . newEventWithTriggerIO
2423+ newFanEventWithTrigger f = SpiderHostFrame $ EventM $ liftIO $ do
2424+ es <- newFanEventWithTriggerIO f
2425+ return $ Reflex.Class.EventSelector $ SpiderEvent . Reflex.Spider.Internal.select es
2426+
2427+instance HasSpiderTimeline x => Reflex.Host.Class.MonadSubscribeEvent (SpiderTimeline x) (SpiderHost x) where
2428+ {-# INLINABLE subscribeEvent #-}
2429+ subscribeEvent = runFrame . runSpiderHostFrame . Reflex.Host.Class.subscribeEvent
2430+
2431+instance HasSpiderTimeline x => Reflex.Host.Class.MonadReflexHost (SpiderTimeline x) (SpiderHost x) where
2432+ type ReadPhase (SpiderHost x) = Reflex.Spider.Internal.ReadPhase x
2433+ fireEventsAndRead es (Reflex.Spider.Internal.ReadPhase a) = run es a
2434+ runHostFrame = runFrame . runSpiderHostFrame
22562435
22572436unsafeNewSpiderTimelineEnv :: forall x. IO (SpiderTimelineEnv x)
22582437unsafeNewSpiderTimelineEnv = do
@@ -2269,7 +2448,6 @@ unsafeNewSpiderTimelineEnv = do
22692448#endif
22702449 }
22712450
2272−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
22732451-- | Create a new SpiderTimelineEnv
22742452newSpiderTimeline :: IO (Some SpiderTimelineEnv)
22752453newSpiderTimeline = withSpiderTimeline (pure . Some.This)
@@ -2291,7 +2469,6 @@ withSpiderTimeline :: (forall x. HasSpiderTimeline x => SpiderTimelineEnv x -> I
22912469withSpiderTimeline k = do
22922470 env <- unsafeNewSpiderTimelineEnv
22932471 reify env $ \s -> k $ localSpiderTimeline s env
2294−#endif
22952472
22962473newtype SpiderPullM x a = SpiderPullM (BehaviorM x a) deriving (Functor, Applicative, Monad, MonadIO, MonadFix)
22972474
@@ -2299,7 +2476,6 @@ type ComputeM = EventM
22992476
23002477newtype SpiderPushM x a = SpiderPushM (ComputeM x a) deriving (Functor, Applicative, Monad, MonadIO, MonadFix)
23012478
2302−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
23032479instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
23042480 {-# SPECIALIZE instance R.Reflex (SpiderTimeline Global) #-}
23052481 newtype Behavior (SpiderTimeline x) a = SpiderBehavior { unSpiderBehavior :: Behavior x a }
@@ -2353,7 +2529,6 @@ instance HasSpiderTimeline x => R.Reflex (SpiderTimeline x) where
23532529 mergeIntIncremental = SpiderEvent . mergeInt . (unsafeCoerce :: Dynamic x (PatchIntMap (R.Event (SpiderTimeline x) a)) -> Dynamic x (PatchIntMap (Event x a))) . unSpiderIncremental
23542530 {-# INLINABLE fanInt #-}
23552531 fanInt e = R.EventSelectorInt $ SpiderEvent . selectInt (fanInt (unSpiderEvent e))
2356−#endif
23572532
23582533data RootTrigger x a = forall k. GCompare k => RootTrigger (WeakBag (Subscriber x a), IORef (DMap k Identity), k a)
23592534
@@ -2393,12 +2568,10 @@ instance Monad (SpiderHost x) where
23932568runSpiderHost :: SpiderHost Global a -> IO a
23942569runSpiderHost (SpiderHost a) = runReaderT a globalSpiderTimelineEnv
23952570
2396−#ifndef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
23972571-- | Run an action affecting a given Spider timeline; this will be guarded by a
23982572-- mutex for that timeline
23992573runSpiderHostForTimeline :: SpiderHost x a -> SpiderTimelineEnv x -> IO a
24002574runSpiderHostForTimeline (SpiderHost a) = runReaderT a
2401−#endif
24022575
24032576newtype SpiderHostFrame x a = SpiderHostFrame { runSpiderHostFrame :: EventM x a } deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)
24042577
src/Reflex/Spider/SpiderTimeline.include.hsdeleted−155
@@ -1,155 +0,0 @@
1−-- | Designates the default, global Spider timeline
2−data SpiderTimeline x
3−type role SpiderTimeline nominal
4−
5−-- | The default, global Spider environment
6−type Spider = SpiderTimeline Global
7−
8−instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (EventM x) where
9− {-# INLINABLE sample #-}
10− sample (SpiderBehavior b) = readBehaviorUntracked b
11−
12−instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (EventM x) where
13− {-# INLINABLE hold #-}
14− hold = holdSpiderEventM
15− {-# INLINABLE holdDyn #-}
16− holdDyn = holdDynSpiderEventM
17− {-# INLINABLE holdIncremental #-}
18− holdIncremental = holdIncrementalSpiderEventM
19− {-# INLINABLE buildDynamic #-}
20− buildDynamic = buildDynamicSpiderEventM
21− {-# INLINABLE headE #-}
22− headE = R.slowHeadE
23−-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
24−
25−instance (
26−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
27− x ~ Global
28−#endif
29− ) => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
30− {-# INLINABLE sample #-}
31− sample = coerce . readBehaviorTracked . unSpiderBehavior
32−
33−instance (
34−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
35− x ~ Global
36−#else
37− HasSpiderTimeline x
38−#endif
39− ) => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPushM x) where
40− {-# INLINABLE sample #-}
41− sample (SpiderBehavior b) = SpiderPushM $ readBehaviorUntracked b
42−
43−instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (SpiderPushM x) where
44− {-# INLINABLE hold #-}
45− hold v0 e = Reflex.Class.current <$> Reflex.Class.holdDyn v0 e
46− {-# INLINABLE holdDyn #-}
47− holdDyn v0 (SpiderEvent e) = SpiderPushM $ fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce e
48− {-# INLINABLE holdIncremental #-}
49− holdIncremental v0 (SpiderEvent e) = SpiderPushM $ SpiderIncremental . dynamicHold <$> Reflex.Spider.Internal.hold v0 e
50− {-# INLINABLE buildDynamic #-}
51− buildDynamic getV0 (SpiderEvent e) = SpiderPushM $ fmap (SpiderDynamic . dynamicDynIdentity) $ Reflex.Spider.Internal.buildDynamic (coerce getV0) $ coerce e
52− {-# INLINABLE headE #-}
53− headE = R.slowHeadE
54−-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
55−
56−instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
57− {-# INLINE return #-}
58− return = pure
59− {-# INLINE (>>=) #-}
60− x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
61− {-# INLINE (>>) #-}
62− (>>) = (*>)
63− {-# INLINE fail #-}
64− fail _ = error "Dynamic does not support 'fail'"
65−
66−{-# INLINABLE newJoinDyn #-}
67−newJoinDyn :: HasSpiderTimeline x => Reflex.Spider.Internal.Dynamic x (Identity (Reflex.Spider.Internal.Dynamic x (Identity a))) -> Reflex.Spider.Internal.Dyn x (Identity a)
68−newJoinDyn d =
69− let readV0 = readBehaviorTracked . dynamicCurrent =<< readBehaviorTracked (dynamicCurrent d)
70− eOuter = Reflex.Spider.Internal.push (fmap (Just . Identity) . readBehaviorUntracked . dynamicCurrent . runIdentity) $ dynamicUpdated d
71− eInner = Reflex.Spider.Internal.switch $ dynamicUpdated <$> dynamicCurrent d
72− eBoth = Reflex.Spider.Internal.coincidence $ dynamicUpdated . runIdentity <$> dynamicUpdated d
73− v' = unSpiderEvent $ Reflex.Class.leftmost $ map SpiderEvent [eBoth, eOuter, eInner]
74− in Reflex.Spider.Internal.unsafeBuildDynamic readV0 v'
75−
76−instance HasSpiderTimeline x => Functor (Reflex.Class.Dynamic (SpiderTimeline x)) where
77− fmap f = SpiderDynamic . newMapDyn f . unSpiderDynamic
78− x <$ d = R.unsafeBuildDynamic (return x) $ x <$ R.updated d
79−
80−instance HasSpiderTimeline x => Applicative (Reflex.Class.Dynamic (SpiderTimeline x)) where
81− pure = SpiderDynamic . dynamicConst
82−#if MIN_VERSION_base(4,10,0)
83− liftA2 f a b = SpiderDynamic $ Reflex.Spider.Internal.zipDynWith f (unSpiderDynamic a) (unSpiderDynamic b)
84−#endif
85− SpiderDynamic a <*> SpiderDynamic b = SpiderDynamic $ Reflex.Spider.Internal.zipDynWith ($) a b
86− a *> b = R.unsafeBuildDynamic (R.sample $ R.current b) $ R.leftmost [R.updated b, R.tag (R.current b) $ R.updated a]
87− (<*) = flip (*>) -- There are no effects, so order doesn't matter
88−
89−holdSpiderEventM :: HasSpiderTimeline x => a -> Reflex.Class.Event (SpiderTimeline x) a -> EventM x (Reflex.Class.Behavior (SpiderTimeline x) a)
90−holdSpiderEventM v0 e = fmap (SpiderBehavior . behaviorHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
91−
92−holdDynSpiderEventM :: HasSpiderTimeline x => a -> Reflex.Class.Event (SpiderTimeline x) a -> EventM x (Reflex.Class.Dynamic (SpiderTimeline x) a)
93−holdDynSpiderEventM v0 e = fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
94−
95−holdIncrementalSpiderEventM :: (HasSpiderTimeline x, Patch p) => PatchTarget p -> Reflex.Class.Event (SpiderTimeline x) p -> EventM x (Reflex.Class.Incremental (SpiderTimeline x) p)
96−holdIncrementalSpiderEventM v0 e = fmap (SpiderIncremental . dynamicHold) $ Reflex.Spider.Internal.hold v0 $ unSpiderEvent e
97−
98−buildDynamicSpiderEventM :: HasSpiderTimeline x => SpiderPullM x a -> Reflex.Class.Event (SpiderTimeline x) a -> EventM x (Reflex.Class.Dynamic (SpiderTimeline x) a)
99−buildDynamicSpiderEventM getV0 e = fmap (SpiderDynamic . dynamicDynIdentity) $ Reflex.Spider.Internal.buildDynamic (coerce getV0) $ coerce $ unSpiderEvent e
100−
101−instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (SpiderHost x) where
102− {-# INLINABLE hold #-}
103− hold v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.hold v0 e
104− {-# INLINABLE holdDyn #-}
105− holdDyn v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.holdDyn v0 e
106− {-# INLINABLE holdIncremental #-}
107− holdIncremental v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.holdIncremental v0 e
108− {-# INLINABLE buildDynamic #-}
109− buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
110− {-# INLINABLE headE #-}
111− headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
112−
113−instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
114− sample = SpiderHostFrame . readBehaviorUntracked . unSpiderBehavior --TODO: This can cause problems with laziness, so we should get rid of it if we can
115−
116−instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (SpiderHostFrame x) where
117− {-# INLINABLE hold #-}
118− hold v0 e = SpiderHostFrame $ fmap (SpiderBehavior . behaviorHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
119− {-# INLINABLE holdDyn #-}
120− holdDyn v0 e = SpiderHostFrame $ fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
121− {-# INLINABLE holdIncremental #-}
122− holdIncremental v0 e = SpiderHostFrame $ fmap (SpiderIncremental . dynamicHold) $ Reflex.Spider.Internal.hold v0 $ unSpiderEvent e
123− {-# INLINABLE buildDynamic #-}
124− buildDynamic getV0 e = SpiderHostFrame $ fmap (SpiderDynamic . dynamicDynIdentity) $ Reflex.Spider.Internal.buildDynamic (coerce getV0) $ coerce $ unSpiderEvent e
125− {-# INLINABLE headE #-}
126− headE = R.slowHeadE
127−-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
128−
129−instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
130− {-# INLINABLE sample #-}
131− sample = runFrame . readBehaviorUntracked . unSpiderBehavior
132−
133−instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (Reflex.Spider.Internal.ReadPhase x) where
134− {-# INLINABLE sample #-}
135− sample = Reflex.Spider.Internal.ReadPhase . Reflex.Class.sample
136−
137−instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Reflex.Spider.Internal.ReadPhase x) where
138− {-# INLINABLE hold #-}
139− hold v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.hold v0 e
140− {-# INLINABLE holdDyn #-}
141− holdDyn v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.holdDyn v0 e
142− {-# INLINABLE holdIncremental #-}
143− holdIncremental v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.holdIncremental v0 e
144− {-# INLINABLE buildDynamic #-}
145− buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
146− {-# INLINABLE headE #-}
147− headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
148−
149−--------------------------------------------------------------------------------
150−-- Deprecated items
151−--------------------------------------------------------------------------------
152−
153−-- | 'SpiderEnv' is the old name for 'SpiderTimeline'
154−{-# DEPRECATED SpiderEnv "Use 'SpiderTimelineEnv' instead" #-}
155−type SpiderEnv = SpiderTimeline
src/Reflex/Spider/SpiderTimelineHost.include.hsdeleted−57
@@ -1,57 +0,0 @@
1−instance HasSpiderTimeline x => Reflex.Host.Class.MonadSubscribeEvent (SpiderTimeline x) (SpiderHostFrame x) where
2− {-# INLINABLE subscribeEvent #-}
3− subscribeEvent e = SpiderHostFrame $ do
4− --TODO: Unsubscribe eventually (manually and/or with weak ref)
5− val <- liftIO $ newIORef Nothing
6− subscription <- subscribe (unSpiderEvent e) $ Subscriber
7− { subscriberPropagate = \a -> do
8− liftIO $ writeIORef val $ Just a
9− scheduleClear val
10− , subscriberInvalidateHeight = \_ -> return ()
11− , subscriberRecalculateHeight = \_ -> return ()
12− }
13− return $ SpiderEventHandle
14− { spiderEventHandleSubscription = subscription
15− , spiderEventHandleValue = val
16− }
17−
18−instance HasSpiderTimeline x => Reflex.Host.Class.ReflexHost (SpiderTimeline x) where
19− type EventTrigger (SpiderTimeline x) = RootTrigger x
20− type EventHandle (SpiderTimeline x) = SpiderEventHandle x
21− type HostFrame (SpiderTimeline x) = SpiderHostFrame x
22−
23−instance HasSpiderTimeline x => Reflex.Host.Class.MonadReadEvent (SpiderTimeline x) (Reflex.Spider.Internal.ReadPhase x) where
24− {-# NOINLINE readEvent #-}
25− readEvent h = Reflex.Spider.Internal.ReadPhase $ fmap (fmap return) $ liftIO $ do
26− result <- readIORef $ spiderEventHandleValue h
27− touch h
28− return result
29−
30−instance (
31−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
32− x ~ Global
33−#endif
34− ) => Reflex.Host.Class.MonadReflexCreateTrigger (SpiderTimeline x) (SpiderHost x) where
35− newEventWithTrigger = SpiderHost . lift . fmap SpiderEvent . newEventWithTriggerIO
36− newFanEventWithTrigger f = SpiderHost $ lift $ do
37− es <- newFanEventWithTriggerIO f
38− return $ Reflex.Class.EventSelector $ SpiderEvent . Reflex.Spider.Internal.select es
39−
40−instance (
41−#ifdef SPECIALIZE_TO_SPIDERTIMELINE_GLOBAL
42− x ~ Global
43−#endif
44− ) => Reflex.Host.Class.MonadReflexCreateTrigger (SpiderTimeline x) (SpiderHostFrame x) where
45− newEventWithTrigger = SpiderHostFrame . EventM . liftIO . fmap SpiderEvent . newEventWithTriggerIO
46− newFanEventWithTrigger f = SpiderHostFrame $ EventM $ liftIO $ do
47− es <- newFanEventWithTriggerIO f
48− return $ Reflex.Class.EventSelector $ SpiderEvent . Reflex.Spider.Internal.select es
49−
50−instance HasSpiderTimeline x => Reflex.Host.Class.MonadSubscribeEvent (SpiderTimeline x) (SpiderHost x) where
51− {-# INLINABLE subscribeEvent #-}
52− subscribeEvent = runFrame . runSpiderHostFrame . Reflex.Host.Class.subscribeEvent
53−
54−instance HasSpiderTimeline x => Reflex.Host.Class.MonadReflexHost (SpiderTimeline x) (SpiderHost x) where
55− type ReadPhase (SpiderHost x) = Reflex.Spider.Internal.ReadPhase x
56− fireEventsAndRead es (Reflex.Spider.Internal.ReadPhase a) = run es a
57− runHostFrame = runFrame . runSpiderHostFrame