on develop help sign in
Merge branch 'develop' into now-event
commitb97c8f70b954f65599ac571693c4f376739a6d62 authorRyan Trinkle <ryan@trinkle.org> dateSun 10 May 2020, 21:46 (6 years ago) parent063b6cb2fb7cfd
5 files changed+32−7
ChangeLog.md+7 reflex.cabal+1−1 src/Reflex/Class.hs+7−1 src/Reflex/Dynamic.hs+14 src/Reflex/Host/Headless.hs+3−5
ChangeLog.md+7
@@ -1,5 +1,12 @@
11# Revision history for reflex
22
3+## 0.7.1.0
4+
5+* ([#413](https://github.com/reflex-frp/reflex/pull/413), [#417](https://github.com/reflex-frp/reflex/pull/417)) Add `Reflex.Host.Headless` module which provides `runHeadlessApp` as an easy way to run a Reflex network in a "headless" environment.
6+* ([#420](https://github.com/reflex-frp/reflex/pull/420)) Add a [`Data.Zip.Unzip`](https://hackage.haskell.org/package/semialign-1.1/docs/Data-Zip.html#t:Unzip) instance for `Event`.
7+* ([#419](https://github.com/reflex-frp/reflex/pull/419)) Add `distributeIntMapOverDynPure` and `joinDynThroughIntMap` as convenience functions for working with `Dynamic` `IntMap`s.
8+
9+
310## 0.7.0.0
411
512* Add lifting instances for most classes to `Reflex.Profiled.Profiled`. ([#398](https://github.com/reflex-frp/reflex/pull/398))
reflex.cabal+1−1
@@ -1,5 +1,5 @@
11Name: reflex
2−Version: 0.7.0.0
2+Version: 0.7.1.0
33Synopsis: Higher-order Functional Reactive Programming
44Description: Reflex is a high-performance, deterministic, higher-order Functional Reactive Programming system
55License: BSD3
src/Reflex/Class.hs+7−1
@@ -180,7 +180,7 @@ import Prelude hiding (zip, zipWith)
180180import Data.These.Combinators (justThese)
181181#endif
182182#if MIN_VERSION_semialign(1,1,0)
183−import Data.Zip (Zip (..))
183+import Data.Zip (Zip (..), Unzip (..))
184184#endif
185185#endif
186186
@@ -1093,6 +1093,12 @@ instance Reflex t => Zip (Event t) where
10931093 zip x y = mapMaybe justThese $ align x y
10941094#endif
10951095
1096+#ifdef MIN_VERSION_semialign
1097+#if MIN_VERSION_semialign(1,1,0)
1098+instance Reflex t => Unzip (Event t) where
1099+ unzip = splitE
1100+#endif
1101+#endif
10961102
10971103-- | Create a new 'Event' that only occurs if the supplied 'Event' occurs and
10981104-- the 'Behavior' is true at the time of occurrence.
src/Reflex/Dynamic.hs+14
@@ -53,10 +53,12 @@ module Reflex.Dynamic
5353 , foldDynMaybe
5454 , foldDynMaybeM
5555 , joinDynThroughMap
56+ , joinDynThroughIntMap
5657 , traceDyn
5758 , traceDynWith
5859 , splitDynPure
5960 , distributeMapOverDynPure
61+ , distributeIntMapOverDynPure
6062 , distributeDMapOverDynPure
6163 , distributeListOverDynPure
6264 , Demux
@@ -88,6 +90,8 @@ import Data.Dependent.Map (DMap)
8890import qualified Data.Dependent.Map as DMap
8991import Data.Dependent.Sum (DSum (..))
9092import Data.GADT.Compare (GCompare (..), GEq (..), GOrdering (..))
93+import Data.IntMap (IntMap)
94+import qualified Data.IntMap as IntMap
9195import Data.Map (Map)
9296import Data.Maybe
9397import Data.Monoid ((<>))
@@ -202,6 +206,11 @@ splitDynPure d = (fmap fst d, fmap snd d)
202206distributeMapOverDynPure :: (Reflex t, Ord k) => Map k (Dynamic t v) -> Dynamic t (Map k v)
203207distributeMapOverDynPure = fmap dmapToMap . distributeDMapOverDynPure . mapWithFunctorToDMap
204208
209+-- | Convert an 'IntMap' with 'Dynamic' elements into a 'Dynamic' of an 'IntMap' with
210+-- non-'Dynamic' elements.
211+distributeIntMapOverDynPure :: (Reflex t) => IntMap (Dynamic t v) -> Dynamic t (IntMap v)
212+distributeIntMapOverDynPure = fmap dmapToIntMap . distributeDMapOverDynPure . intMapWithFunctorToDMap
213+
205214-- | Convert a list with 'Dynamic' elements into a 'Dynamic' of a list with
206215-- non-'Dynamic' elements, preserving the order of the elements.
207216{-# DEPRECATED distributeListOverDynPure "Use 'distributeListOverDyn' instead" #-}
@@ -214,6 +223,11 @@ distributeListOverDynPure = distributeListOverDyn
214223joinDynThroughMap :: forall t k a. (Reflex t, Ord k) => Dynamic t (Map k (Dynamic t a)) -> Dynamic t (Map k a)
215224joinDynThroughMap = (distributeMapOverDynPure =<<)
216225
226+-- | Combine a 'Dynamic' of an 'IntMap' of 'Dynamic's into a 'Dynamic'
227+-- with the current values of the 'Dynamic's in a map.
228+joinDynThroughIntMap :: forall t a. (Reflex t) => Dynamic t (IntMap (Dynamic t a)) -> Dynamic t (IntMap a)
229+joinDynThroughIntMap = (distributeIntMapOverDynPure =<<)
230+
217231-- | Print the value of the 'Dynamic' when it is first read and on each
218232-- subsequent change that is observed (as 'traceEvent'), prefixed with the
219233-- provided string. This should /only/ be used for debugging.
src/Reflex/Host/Headless.hs+3−5
@@ -43,7 +43,7 @@ type MonadHeadlessApp t m =
4343-- | Run a headless FRP network. Inside the action, you will most probably use
4444-- the capabilities provided by the 'TriggerEvent' and 'PerformEvent' type
4545-- classes to interface the FRP network with the outside world. Useful for
46−-- testing.
46+-- testing. Each headless network runs on its own spider timeline.
4747runHeadlessApp
4848 :: (forall t m. MonadHeadlessApp t m => m (Event t ()))
4949 -- ^ The action to be run in the headless FRP network. The FRP network is
@@ -51,10 +51,8 @@ runHeadlessApp
5151 -> IO ()
5252runHeadlessApp guest =
5353 -- We are using the 'Spider' implementation of reflex. Running the host
54− -- allows us to take actions on the FRP timeline. The scoped type signature
55− -- specifies that our host runs on the Global timeline.
56− -- For more information, see 'Reflex.Spider.Internal.runSpiderHost'.
57− (runSpiderHost :: SpiderHost Global a -> IO a) $ do
54+ -- allows us to take actions on the FRP timeline.
55+ withSpiderTimeline $ runSpiderHostForTimeline $ do
5856 -- Create the "post-build" event and associated trigger. This event fires
5957 -- once, when the application starts.
6058 (postBuild, postBuildTriggerRef) <- newEventWithTriggerRef