on develop help sign in
Moves the collection management functions to `reflex`.
986e1cfDave Laing
reflex-dom-core/src/Foreign/JavaScript/TH.hs+1−1
@@ -136,7 +136,7 @@ instance PrimMonad m => PrimMonad (WithJSContextSingleton x m) where
136 type PrimState (WithJSContextSingleton x m) = PrimState m
136 type PrimState (WithJSContextSingleton x m) = PrimState m
137 primitive = lift . primitive
137 primitive = lift . primitive
138
138
139−instance MonadAdjust t m => MonadAdjust t (WithJSContextSingleton x m) where
139+instance Adjustable t m => Adjustable t (WithJSContextSingleton x m) where
140 runWithReplace a0 a' = WithJSContextSingleton $ runWithReplace (coerce a0) (coerceEvent a')
140 runWithReplace a0 a' = WithJSContextSingleton $ runWithReplace (coerce a0) (coerceEvent a')
141 traverseIntMapWithKeyWithAdjust f dm0 dm' = WithJSContextSingleton $ traverseIntMapWithKeyWithAdjust (\k v -> unWithJSContextSingleton $ f k v) (coerce dm0) (coerceEvent dm')
141 traverseIntMapWithKeyWithAdjust f dm0 dm' = WithJSContextSingleton $ traverseIntMapWithKeyWithAdjust (\k v -> unWithJSContextSingleton $ f k v) (coerce dm0) (coerceEvent dm')
142 traverseDMapWithKeyWithAdjust f dm0 dm' = WithJSContextSingleton $ traverseDMapWithKeyWithAdjust (\k v -> unWithJSContextSingleton $ f k v) (coerce dm0) (coerceEvent dm')
142 traverseDMapWithKeyWithAdjust f dm0 dm' = WithJSContextSingleton $ traverseDMapWithKeyWithAdjust (\k v -> unWithJSContextSingleton $ f k v) (coerce dm0) (coerceEvent dm')
reflex-dom-core/src/Reflex/Dom/Builder/Class.hs+1−1
@@ -70,7 +70,7 @@ class Default (EventSpec d EventResult) => DomSpace d where
70
70
71-- | @'DomBuilder' t m@ indicates that @m@ is a 'Monad' capable of building
71-- | @'DomBuilder' t m@ indicates that @m@ is a 'Monad' capable of building
72-- dynamic DOM in the 'Reflex' timeline @t@
72-- dynamic DOM in the 'Reflex' timeline @t@
73−class (Monad m, Reflex t, DomSpace (DomBuilderSpace m), MonadAdjust t m) => DomBuilder t m | m -> t where
73+class (Monad m, Reflex t, DomSpace (DomBuilderSpace m), Adjustable t m) => DomBuilder t m | m -> t where
74 type DomBuilderSpace m :: *
74 type DomBuilderSpace m :: *
75 textNode :: TextNodeConfig t -> m (TextNode (DomBuilderSpace m) t)
75 textNode :: TextNodeConfig t -> m (TextNode (DomBuilderSpace m) t)
76 default textNode :: ( MonadTrans f
76 default textNode :: ( MonadTrans f
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+7−7
@@ -325,7 +325,7 @@ extractUpTo df s e = liftJSM $ do
325 void $ call f f (df, s, e)
325 void $ call f f (df, s, e)
326#endif
326#endif
327
327
328−type SupportsImmediateDomBuilder t m = (Reflex t, MonadJSM m, MonadHold t m, MonadFix m, MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref JSM, MonadAdjust t m, PrimMonad m)
328+type SupportsImmediateDomBuilder t m = (Reflex t, MonadJSM m, MonadHold t m, MonadFix m, MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref JSM, Adjustable t m, PrimMonad m)
329
329
330{-# INLINABLE collectUpTo #-}
330{-# INLINABLE collectUpTo #-}
331collectUpTo :: (MonadJSM m, IsNode start, IsNode end) => start -> end -> m DOM.DocumentFragment
331collectUpTo :: (MonadJSM m, IsNode start, IsNode end) => start -> end -> m DOM.DocumentFragment
@@ -388,7 +388,7 @@ wrap e cfg = do
388 }
388 }
389
389
390{-# INLINABLE makeElement #-}
390{-# INLINABLE makeElement #-}
391−makeElement :: forall er t m a. (MonadJSM m, MonadFix m, MonadReflexCreateTrigger t m, MonadAdjust t m) => Text -> ElementConfig er t GhcjsDomSpace -> ImmediateDomBuilderT t m a -> ImmediateDomBuilderT t m ((Element er GhcjsDomSpace t, a), DOM.Element)
391+makeElement :: forall er t m a. (MonadJSM m, MonadFix m, MonadReflexCreateTrigger t m, Adjustable t m) => Text -> ElementConfig er t GhcjsDomSpace -> ImmediateDomBuilderT t m a -> ImmediateDomBuilderT t m ((Element er GhcjsDomSpace t, a), DOM.Element)
392makeElement elementTag cfg child = do
392makeElement elementTag cfg child = do
393 doc <- askDocument
393 doc <- askDocument
394 e <- liftJSM $ uncheckedCastTo DOM.Element <$> case cfg ^. namespace of
394 e <- liftJSM $ uncheckedCastTo DOM.Element <$> case cfg ^. namespace of
@@ -640,7 +640,7 @@ instance SupportsImmediateDomBuilder t m => MountableDomBuilder t (ImmediateDomB
640 liftIO $ writeIORef (_immediateDomFragment_state childFragment) $ FragmentState_Mounted (before, after)
640 liftIO $ writeIORef (_immediateDomFragment_state childFragment) $ FragmentState_Mounted (before, after)
641 liftIO $ writeIORef (_immediateDomFragment_state fragment) $ FragmentState_Mounted (before, after)
641 liftIO $ writeIORef (_immediateDomFragment_state fragment) $ FragmentState_Mounted (before, after)
642
642
643−instance (Reflex t, MonadAdjust t m, MonadJSM m, MonadHold t m, MonadFix m, PrimMonad m) => MonadAdjust t (ImmediateDomBuilderT t m) where
643+instance (Reflex t, Adjustable t m, MonadJSM m, MonadHold t m, MonadFix m, PrimMonad m) => Adjustable t (ImmediateDomBuilderT t m) where
644 {-# INLINABLE runWithReplace #-}
644 {-# INLINABLE runWithReplace #-}
645 runWithReplace a0 a' = do
645 runWithReplace a0 a' = do
646 initialEnv <- ImmediateDomBuilderT ask
646 initialEnv <- ImmediateDomBuilderT ask
@@ -753,7 +753,7 @@ instance (Reflex t, MonadAdjust t m, MonadJSM m, MonadHold t m, MonadFix m, Prim
753 liftIO $ writeIORef placeholders $! phsAfter
753 liftIO $ writeIORef placeholders $! phsAfter
754
754
755{-# INLINABLE traverseDMapWithKeyWithAdjust' #-}
755{-# INLINABLE traverseDMapWithKeyWithAdjust' #-}
756−traverseDMapWithKeyWithAdjust' :: forall t m (k :: * -> *) v v'. (MonadAdjust t m, MonadHold t m, MonadFix m, MonadIO m, MonadJSM m, PrimMonad m, DMap.GCompare k) => (forall a. k a -> v a -> ImmediateDomBuilderT t m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> ImmediateDomBuilderT t m (DMap k v', Event t (PatchDMap k v'))
756+traverseDMapWithKeyWithAdjust' :: forall t m (k :: * -> *) v v'. (Adjustable t m, MonadHold t m, MonadFix m, MonadIO m, MonadJSM m, PrimMonad m, DMap.GCompare k) => (forall a. k a -> v a -> ImmediateDomBuilderT t m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> ImmediateDomBuilderT t m (DMap k v', Event t (PatchDMap k v'))
757traverseDMapWithKeyWithAdjust' = do
757traverseDMapWithKeyWithAdjust' = do
758 let updateChildUnreadiness (p :: PatchDMap k (Compose ((,,,) DOM.DocumentFragment DOM.Text (IORef (ChildReadyState k))) v')) old = do
758 let updateChildUnreadiness (p :: PatchDMap k (Compose ((,,,) DOM.DocumentFragment DOM.Text (IORef (ChildReadyState k))) v')) old = do
759 let new :: forall a. k a -> ComposeMaybe (Compose ((,,,) DOM.DocumentFragment DOM.Text (IORef (ChildReadyState k))) v') a -> IO (ComposeMaybe (Constant (IORef (ChildReadyState k))) a)
759 let new :: forall a. k a -> ComposeMaybe (Compose ((,,,) DOM.DocumentFragment DOM.Text (IORef (ChildReadyState k))) v') a -> IO (ComposeMaybe (Constant (IORef (ChildReadyState k))) a)
@@ -781,7 +781,7 @@ traverseDMapWithKeyWithAdjust' = do
781 liftIO $ writeIORef placeholders $! fromMaybe phs $ apply (weakenPatchDMapWith (\(Compose (_, ph, _, _)) -> ph) $ PatchDMap p) phs
781 liftIO $ writeIORef placeholders $! fromMaybe phs $ apply (weakenPatchDMapWith (\(Compose (_, ph, _, _)) -> ph) $ PatchDMap p) phs
782
782
783{-# INLINABLE traverseIntMapWithKeyWithAdjust' #-}
783{-# INLINABLE traverseIntMapWithKeyWithAdjust' #-}
784−traverseIntMapWithKeyWithAdjust' :: forall t m v v'. (MonadAdjust t m, MonadHold t m, MonadFix m, MonadIO m, MonadJSM m, PrimMonad m) => (IntMap.Key -> v -> ImmediateDomBuilderT t m v') -> IntMap v -> Event t (PatchIntMap v) -> ImmediateDomBuilderT t m (IntMap v', Event t (PatchIntMap v'))
784+traverseIntMapWithKeyWithAdjust' :: forall t m v v'. (Adjustable t m, MonadHold t m, MonadFix m, MonadIO m, MonadJSM m, PrimMonad m) => (IntMap.Key -> v -> ImmediateDomBuilderT t m v') -> IntMap v -> Event t (PatchIntMap v) -> ImmediateDomBuilderT t m (IntMap v', Event t (PatchIntMap v'))
785traverseIntMapWithKeyWithAdjust' = do
785traverseIntMapWithKeyWithAdjust' = do
786 let updateChildUnreadiness (p@(PatchIntMap pInner) :: PatchIntMap (DOM.DocumentFragment, DOM.Text, IORef ChildReadyStateInt, v')) old = do
786 let updateChildUnreadiness (p@(PatchIntMap pInner) :: PatchIntMap (DOM.DocumentFragment, DOM.Text, IORef ChildReadyStateInt, v')) old = do
787 let new :: IntMap.Key -> Maybe (DOM.DocumentFragment, DOM.Text, IORef ChildReadyStateInt, v') -> IO (Maybe (IORef ChildReadyStateInt))
787 let new :: IntMap.Key -> Maybe (DOM.DocumentFragment, DOM.Text, IORef ChildReadyStateInt, v') -> IO (Maybe (IORef ChildReadyStateInt))
@@ -824,7 +824,7 @@ data ChildReadyStateInt
824
824
825{-# INLINE hoistTraverseIntMapWithKeyWithAdjust #-}
825{-# INLINE hoistTraverseIntMapWithKeyWithAdjust #-}
826hoistTraverseIntMapWithKeyWithAdjust :: forall v v' t m p.
826hoistTraverseIntMapWithKeyWithAdjust :: forall v v' t m p.
827− ( MonadAdjust t m
827+ ( Adjustable t m
828 , MonadIO m
828 , MonadIO m
829 , MonadJSM m
829 , MonadJSM m
830 , MonadFix m
830 , MonadFix m
@@ -908,7 +908,7 @@ hoistTraverseIntMapWithKeyWithAdjust base updateChildUnreadiness applyDomUpdate_
908
908
909{-# INLINABLE hoistTraverseWithKeyWithAdjust #-}
909{-# INLINABLE hoistTraverseWithKeyWithAdjust #-}
910hoistTraverseWithKeyWithAdjust :: forall (k :: * -> *) v v' t m p.
910hoistTraverseWithKeyWithAdjust :: forall (k :: * -> *) v v' t m p.
911− ( MonadAdjust t m
911+ ( Adjustable t m
912 , MonadHold t m
912 , MonadHold t m
913 , DMap.GCompare k
913 , DMap.GCompare k
914 , MonadIO m
914 , MonadIO m
reflex-dom-core/src/Reflex/Dom/Builder/InputDisabled.hs+1−1
@@ -76,7 +76,7 @@ instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (InputDisabl
76 newEventWithTrigger = lift . newEventWithTrigger
76 newEventWithTrigger = lift . newEventWithTrigger
77 newFanEventWithTrigger f = lift $ newFanEventWithTrigger f
77 newFanEventWithTrigger f = lift $ newFanEventWithTrigger f
78
78
79−instance MonadAdjust t m => MonadAdjust t (InputDisabledT m) where
79+instance Adjustable t m => Adjustable t (InputDisabledT m) where
80 runWithReplace a0 a' = InputDisabledT $ runWithReplace (coerce a0) (coerceEvent a')
80 runWithReplace a0 a' = InputDisabledT $ runWithReplace (coerce a0) (coerceEvent a')
81 traverseDMapWithKeyWithAdjust f dm0 dm' = InputDisabledT $ traverseDMapWithKeyWithAdjust (\k v -> runInputDisabledT $ f k v) (coerce dm0) (coerceEvent dm')
81 traverseDMapWithKeyWithAdjust f dm0 dm' = InputDisabledT $ traverseDMapWithKeyWithAdjust (\k v -> runInputDisabledT $ f k v) (coerce dm0) (coerceEvent dm')
82 traverseDMapWithKeyWithAdjustWithMove f dm0 dm' = InputDisabledT $ traverseDMapWithKeyWithAdjustWithMove (\k v -> runInputDisabledT $ f k v) (coerce dm0) (coerceEvent dm')
82 traverseDMapWithKeyWithAdjustWithMove f dm0 dm' = InputDisabledT $ traverseDMapWithKeyWithAdjustWithMove (\k v -> runInputDisabledT $ f k v) (coerce dm0) (coerceEvent dm')
reflex-dom-core/src/Reflex/Dom/Builder/Static.hs+4−4
@@ -33,6 +33,7 @@ import Data.Dependent.Sum (DSum (..))
33import Data.Functor.Compose
33import Data.Functor.Compose
34import Data.Functor.Constant
34import Data.Functor.Constant
35import qualified Data.Map as Map
35import qualified Data.Map as Map
36+import Data.Map.Misc (applyMap)
36import Data.Monoid
37import Data.Monoid
37import qualified Data.Set as Set
38import qualified Data.Set as Set
38import Data.Text (Text)
39import Data.Text (Text)
@@ -41,7 +42,6 @@ import Data.Tuple
41import GHC.Generics
42import GHC.Generics
42import Reflex.Class
43import Reflex.Class
43import Reflex.Dom.Builder.Class
44import Reflex.Dom.Builder.Class
44−import Reflex.Dom.Widget.Basic (applyMap)
45import Reflex.Dynamic
45import Reflex.Dynamic
46import Reflex.Host.Class
46import Reflex.Host.Class
47import Reflex.PerformEvent.Base
47import Reflex.PerformEvent.Base
@@ -122,7 +122,7 @@ instance MonadRef m => MonadRef (StaticDomBuilderT t m) where
122instance MonadAtomicRef m => MonadAtomicRef (StaticDomBuilderT t m) where
122instance MonadAtomicRef m => MonadAtomicRef (StaticDomBuilderT t m) where
123 atomicModifyRef r = lift . atomicModifyRef r
123 atomicModifyRef r = lift . atomicModifyRef r
124
124
125−type SupportsStaticDomBuilder t m = (Reflex t, MonadIO m, MonadHold t m, MonadFix m, PerformEvent t m, MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref IO, MonadAdjust t m)
125+type SupportsStaticDomBuilder t m = (Reflex t, MonadIO m, MonadHold t m, MonadFix m, PerformEvent t m, MonadReflexCreateTrigger t m, MonadRef m, Ref m ~ Ref IO, Adjustable t m)
126
126
127data StaticDomSpace
127data StaticDomSpace
128
128
@@ -146,7 +146,7 @@ instance DomSpace StaticDomSpace where
146 type RawSelectElement StaticDomSpace = ()
146 type RawSelectElement StaticDomSpace = ()
147 addEventSpecFlags _ _ _ _ = StaticEventSpec
147 addEventSpecFlags _ _ _ _ = StaticEventSpec
148
148
149−instance (Reflex t, MonadAdjust t m, MonadHold t m) => MonadAdjust t (StaticDomBuilderT t m) where
149+instance (Reflex t, Adjustable t m, MonadHold t m) => Adjustable t (StaticDomBuilderT t m) where
150 runWithReplace a0 a' = do
150 runWithReplace a0 a' = do
151 e <- StaticDomBuilderT ask
151 e <- StaticDomBuilderT ask
152 (result0, result') <- lift $ runWithReplace (runStaticDomBuilderT a0 e) (flip runStaticDomBuilderT e <$> a')
152 (result0, result') <- lift $ runWithReplace (runStaticDomBuilderT a0 e) (flip runStaticDomBuilderT e <$> a')
@@ -157,7 +157,7 @@ instance (Reflex t, MonadAdjust t m, MonadHold t m) => MonadAdjust t (StaticDomB
157 traverseDMapWithKeyWithAdjustWithMove = hoistDMapWithKeyWithAdjust traverseDMapWithKeyWithAdjustWithMove mapPatchDMapWithMove
157 traverseDMapWithKeyWithAdjustWithMove = hoistDMapWithKeyWithAdjust traverseDMapWithKeyWithAdjustWithMove mapPatchDMapWithMove
158
158
159hoistDMapWithKeyWithAdjust :: forall (k :: * -> *) v v' t m p.
159hoistDMapWithKeyWithAdjust :: forall (k :: * -> *) v v' t m p.
160− ( MonadAdjust t m
160+ ( Adjustable t m
161 , MonadHold t m
161 , MonadHold t m
162 , PatchTarget (p k (Constant (Behavior t Builder))) ~ DMap k (Constant (Behavior t Builder))
162 , PatchTarget (p k (Constant (Behavior t Builder))) ~ DMap k (Constant (Behavior t Builder))
163 , Patch (p k (Constant (Behavior t Builder)))
163 , Patch (p k (Constant (Behavior t Builder)))
reflex-dom-core/src/Reflex/Dom/Modals/Base.hs+1−1
@@ -106,7 +106,7 @@ instance MonadAtomicRef m => MonadAtomicRef (ModalsT t m) where
106 {-# INLINABLE atomicModifyRef #-}
106 {-# INLINABLE atomicModifyRef #-}
107 atomicModifyRef r = lift . atomicModifyRef r
107 atomicModifyRef r = lift . atomicModifyRef r
108
108
109−instance (MonadAdjust t m, MonadHold t m, MonadFix m) => MonadAdjust t (ModalsT t m) where
109+instance (Adjustable t m, MonadHold t m, MonadFix m) => Adjustable t (ModalsT t m) where
110 runWithReplace a0 a' = ModalsT $ runWithReplace (unModalsT a0) (fmapCheap unModalsT a')
110 runWithReplace a0 a' = ModalsT $ runWithReplace (unModalsT a0) (fmapCheap unModalsT a')
111 traverseDMapWithKeyWithAdjust f dm0 dm' = ModalsT $ traverseDMapWithKeyWithAdjust (coerce f) dm0 dm'
111 traverseDMapWithKeyWithAdjust f dm0 dm' = ModalsT $ traverseDMapWithKeyWithAdjust (coerce f) dm0 dm'
112 traverseDMapWithKeyWithAdjustWithMove f dm0 dm' = ModalsT $ traverseDMapWithKeyWithAdjustWithMove (coerce f) dm0 dm'
112 traverseDMapWithKeyWithAdjustWithMove f dm0 dm' = ModalsT $ traverseDMapWithKeyWithAdjustWithMove (coerce f) dm0 dm'
reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+2−139
@@ -3,7 +3,6 @@
3{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE GADTs #-}
5{-# LANGUAGE GADTs #-}
6−{-# LANGUAGE LambdaCase #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}
9{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE RankNTypes #-}
@@ -12,7 +11,6 @@
12{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeFamilies #-}
13module Reflex.Dom.Widget.Basic
12module Reflex.Dom.Widget.Basic
14 ( partitionMapBySetLT
13 ( partitionMapBySetLT
15− , listHoldWithKey
16 , ChildResult (..)
14 , ChildResult (..)
17
15
18 -- * Displaying Values
16 -- * Displaying Values
@@ -24,21 +22,6 @@ module Reflex.Dom.Widget.Basic
24 , widgetHold
22 , widgetHold
25 , untilReady
23 , untilReady
26
24
27− -- * Working with Maps
28− , diffMapNoEq
29− , diffMap
30− , applyMap
31− , mapPartitionEithers
32− , applyMapKeysSet
33−
34− -- * Widgets on Collections
35− , listWithKey
36− , listWithKey'
37− , listWithKeyShallowDiff
38− , listViewWithKey
39− , selectViewListWithKey
40− , selectViewListWithKey_
41−
42 -- * Creating DOM Elements
25 -- * Creating DOM Elements
43 , el
26 , el
44 , elAttr
27 , elAttr
@@ -56,10 +39,6 @@ module Reflex.Dom.Widget.Basic
56 , dynamicAttributesToModifyAttributes
39 , dynamicAttributesToModifyAttributes
57 , dynamicAttributesToModifyAttributesWithInitial
40 , dynamicAttributesToModifyAttributesWithInitial
58
41
59− -- * List Utils
60− , list
61− , simpleList
62−
63 -- * Specific DOM Elements
42 -- * Specific DOM Elements
64 , Link (..)
43 , Link (..)
65 , linkClass
44 , linkClass
@@ -83,6 +62,7 @@ module Reflex.Dom.Widget.Basic
83 ) where
62 ) where
84
63
85import Reflex.Class
64import Reflex.Class
65+import Reflex.Collection
86import Reflex.Dom.Builder.Class
66import Reflex.Dom.Builder.Class
87import Reflex.Dom.Class
67import Reflex.Dom.Class
88import Reflex.Dynamic
68import Reflex.Dynamic
@@ -95,9 +75,9 @@ import Data.Align
95import Data.Default
75import Data.Default
96import Data.Either
76import Data.Either
97import Data.Foldable
77import Data.Foldable
98−import Data.Functor.Misc
99import Data.Map (Map)
78import Data.Map (Map)
100import qualified Data.Map as Map
79import qualified Data.Map as Map
80+import Data.Map.Misc
101import Data.Maybe
81import Data.Maybe
102import Data.Set (Set)
82import Data.Set (Set)
103import qualified Data.Set as Set
83import qualified Data.Set as Set
@@ -129,13 +109,6 @@ partitionMapBySetLT s m0 = Map.fromDistinctAscList $ go (Set.toAscList s) m0
129
109
130newtype ChildResult t k a = ChildResult { unChildResult :: (a, Event t (Map k (Maybe (ChildResult t k a)))) }
110newtype ChildResult t k a = ChildResult { unChildResult :: (a, Event t (Map k (Maybe (ChildResult t k a)))) }
131
111
132−listHoldWithKey :: forall t m k v a. (Ord k, DomBuilder t m, MonadHold t m) => Map k v -> Event t (Map k (Maybe v)) -> (k -> v -> m a) -> m (Dynamic t (Map k a))
133−listHoldWithKey m0 m' f = do
134− let dm0 = mapWithFunctorToDMap $ Map.mapWithKey f m0
135− dm' = fmap (PatchDMap . mapWithFunctorToDMap . Map.mapWithKey (\k v -> ComposeMaybe $ fmap (f k) v)) m'
136− (a0, a') <- sequenceDMapWithAdjust dm0 dm'
137− fmap dmapToMap . incrementalToDynamic <$> holdIncremental a0 a' --TODO: Move the dmapToMap to the righthand side so it doesn't get fully redone every time
138−
139text :: DomBuilder t m => Text -> m ()
112text :: DomBuilder t m => Text -> m ()
140text t = void $ textNode $ def & textNodeConfig_initialContents .~ t
113text t = void $ textNode $ def & textNodeConfig_initialContents .~ t
141
114
@@ -182,107 +155,6 @@ untilReady a b = do
182 postBuild <- getPostBuild
155 postBuild <- getPostBuild
183 runWithReplace a $ b <$ postBuild
156 runWithReplace a $ b <$ postBuild
184
157
185−diffMapNoEq :: (Ord k) => Map k v -> Map k v -> Map k (Maybe v)
186−diffMapNoEq olds news = flip Map.mapMaybe (align olds news) $ \case
187− This _ -> Just Nothing
188− These _ new -> Just $ Just new
189− That new -> Just $ Just new
190−
191−diffMap :: (Ord k, Eq v) => Map k v -> Map k v -> Map k (Maybe v)
192−diffMap olds news = flip Map.mapMaybe (align olds news) $ \case
193− This _ -> Just Nothing
194− These old new
195− | old == new -> Nothing
196− | otherwise -> Just $ Just new
197− That new -> Just $ Just new
198−
199−applyMap :: Ord k => Map k (Maybe v) -> Map k v -> Map k v
200−applyMap patch old = insertions `Map.union` (old `Map.difference` deletions)
201− where (deletions, insertions) = mapPartitionEithers $ maybeToEither <$> patch
202− maybeToEither = \case
203− Nothing -> Left ()
204− Just r -> Right r
205−
206−mapPartitionEithers :: Map k (Either a b) -> (Map k a, Map k b)
207−mapPartitionEithers m = (fromLeft <$> ls, fromRight <$> rs)
208− where (ls, rs) = Map.partition isLeft m
209− fromLeft (Left l) = l
210− fromLeft _ = error "mapPartitionEithers: fromLeft received a Right value; this should be impossible"
211− fromRight (Right r) = r
212− fromRight _ = error "mapPartitionEithers: fromRight received a Left value; this should be impossible"
213−
214−-- | Apply a map patch to a set
215−-- > applyMapKeysSet patch (Map.keysSet m) == Map.keysSet (applyMap patch m)
216−applyMapKeysSet :: Ord k => Map k (Maybe v) -> Set k -> Set k
217−applyMapKeysSet patch old = Map.keysSet insertions `Set.union` (old `Set.difference` Map.keysSet deletions)
218− where (insertions, deletions) = Map.partition isJust patch
219−
220−--TODO: Something better than Dynamic t (Map k v) - we want something where the Events carry diffs, not the whole value
221−listWithKey :: forall t k v m a. (Ord k, DomBuilder t m, PostBuild t m, MonadFix m, MonadHold t m) => Dynamic t (Map k v) -> (k -> Dynamic t v -> m a) -> m (Dynamic t (Map k a))
222−listWithKey vals mkChild = do
223− postBuild <- getPostBuild
224− let childValChangedSelector = fanMap $ updated vals
225− -- We keep track of changes to children values in the mkChild function we pass to listHoldWithKey
226− -- The other changes we need to keep track of are child insertions and deletions. diffOnlyKeyChanges
227− -- keeps track of insertions and deletions but ignores value changes, since they're already accounted for.
228− diffOnlyKeyChanges olds news = flip Map.mapMaybe (align olds news) $ \case
229− This _ -> Just Nothing
230− These _ _ -> Nothing
231− That new -> Just $ Just new
232− rec sentVals :: Dynamic t (Map k v) <- foldDyn applyMap Map.empty changeVals
233− let changeVals :: Event t (Map k (Maybe v))
234− changeVals = attachWith diffOnlyKeyChanges (current sentVals) $ leftmost
235− [ updated vals
236− , tag (current vals) postBuild --TODO: This should probably be added to the attachWith, not to the updated; if we were using diffMap instead of diffMapNoEq, I think it might not work
237− ]
238− listHoldWithKey Map.empty changeVals $ \k v ->
239− mkChild k =<< holdDyn v (select childValChangedSelector $ Const2 k)
240−
241−{-# DEPRECATED listWithKey' "listWithKey' has been renamed to listWithKeyShallowDiff; also, its behavior has changed to fix a bug where children were always rebuilt (never updated)" #-}
242−listWithKey' :: (Ord k, DomBuilder t m, MonadFix m, MonadHold t m) => Map k v -> Event t (Map k (Maybe v)) -> (k -> v -> Event t v -> m a) -> m (Dynamic t (Map k a))
243−listWithKey' = listWithKeyShallowDiff
244−
245−-- | Display the given map of items (in key order) using the builder function provided, and update it with the given event. 'Nothing' update entries will delete the corresponding children, and 'Just' entries will create them if they do not exist or send an update event to them if they do.
246−listWithKeyShallowDiff :: (Ord k, DomBuilder t m, MonadFix m, MonadHold t m) => Map k v -> Event t (Map k (Maybe v)) -> (k -> v -> Event t v -> m a) -> m (Dynamic t (Map k a))
247−listWithKeyShallowDiff initialVals valsChanged mkChild = do
248− let childValChangedSelector = fanMap $ fmap (Map.mapMaybe id) valsChanged
249− sentVals <- foldDyn applyMap Map.empty $ fmap (fmap void) valsChanged
250− let relevantPatch patch _ = case patch of
251− Nothing -> Just Nothing -- Even if we let a Nothing through when the element doesn't already exist, this doesn't cause a problem because it is ignored
252− Just _ -> Nothing -- We don't want to let spurious re-creations of items through
253− listHoldWithKey initialVals (attachWith (flip (Map.differenceWith relevantPatch)) (current sentVals) valsChanged) $ \k v ->
254− mkChild k v $ select childValChangedSelector $ Const2 k
255−
256−--TODO: Something better than Dynamic t (Map k v) - we want something where the Events carry diffs, not the whole value
257−-- | Create a dynamically-changing set of Event-valued widgets.
258−-- This is like listWithKey, specialized for widgets returning (Event t a). listWithKey would return 'Dynamic t (Map k (Event t a))' in this scenario, but listViewWithKey flattens this to 'Event t (Map k a)' via 'switch'.
259−listViewWithKey :: (Ord k, DomBuilder t m, PostBuild t m, MonadHold t m, MonadFix m) => Dynamic t (Map k v) -> (k -> Dynamic t v -> m (Event t a)) -> m (Event t (Map k a))
260−listViewWithKey vals mkChild = switch . fmap mergeMap <$> listViewWithKey' vals mkChild
261−
262−listViewWithKey' :: (Ord k, DomBuilder t m, PostBuild t m, MonadHold t m, MonadFix m) => Dynamic t (Map k v) -> (k -> Dynamic t v -> m a) -> m (Behavior t (Map k a))
263−listViewWithKey' vals mkChild = current <$> listWithKey vals mkChild
264−
265−-- | Create a dynamically-changing set of widgets, one of which is selected at any time.
266−selectViewListWithKey :: forall t m k v a. (DomBuilder t m, Ord k, PostBuild t m, MonadHold t m, MonadFix m)
267− => Dynamic t k -- ^ Current selection key
268− -> Dynamic t (Map k v) -- ^ Dynamic key/value map
269− -> (k -> Dynamic t v -> Dynamic t Bool -> m (Event t a)) -- ^ Function to create a widget for a given key from Dynamic value and Dynamic Bool indicating if this widget is currently selected
270− -> m (Event t (k, a)) -- ^ Event that fires when any child's return Event fires. Contains key of an arbitrary firing widget.
271−selectViewListWithKey selection vals mkChild = do
272− let selectionDemux = demux selection -- For good performance, this value must be shared across all children
273− selectChild <- listWithKey vals $ \k v -> do
274− let selected = demuxed selectionDemux k
275− selectSelf <- mkChild k v selected
276− return $ fmap ((,) k) selectSelf
277− return $ switchPromptlyDyn $ leftmost . Map.elems <$> selectChild
278−
279−selectViewListWithKey_ :: forall t m k v a. (DomBuilder t m, Ord k, PostBuild t m, MonadHold t m, MonadFix m)
280− => Dynamic t k -- ^ Current selection key
281− -> Dynamic t (Map k v) -- ^ Dynamic key/value map
282− -> (k -> Dynamic t v -> Dynamic t Bool -> m (Event t a)) -- ^ Function to create a widget for a given key from Dynamic value and Dynamic Bool indicating if this widget is currently selected
283− -> m (Event t k) -- ^ Event that fires when any child's return Event fires. Contains key of an arbitrary firing widget.
284−selectViewListWithKey_ selection vals mkChild = fmap fst <$> selectViewListWithKey selection vals mkChild
285−
286-- | Create a DOM element
158-- | Create a DOM element
287-- > el "div" (text "Hello World")
159-- > el "div" (text "Hello World")
288-- <div>Hello World</div>
160-- <div>Hello World</div>
@@ -380,15 +252,6 @@ dynamicAttributesToModifyAttributesWithInitial attrs0 d = do
380-- Copied and pasted from Reflex.Widget.Class
252-- Copied and pasted from Reflex.Widget.Class
381--------------------------------------------------------------------------------
253--------------------------------------------------------------------------------
382
254
383−-- | Create a dynamically-changing set of widgets from a Dynamic key/value map.
384−-- Unlike the 'withKey' variants, the child widgets are insensitive to which key they're associated with.
385−list :: (Ord k, DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m) => Dynamic t (Map k v) -> (Dynamic t v -> m a) -> m (Dynamic t (Map k a))
386−list dm mkChild = listWithKey dm (\_ dv -> mkChild dv)
387−
388−-- | Create a dynamically-changing set of widgets from a Dynamic list.
389−simpleList :: (DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m) => Dynamic t [v] -> (Dynamic t v -> m a) -> m (Dynamic t [a])
390−simpleList xs mkChild = fmap (fmap (map snd . Map.toList)) $ flip list mkChild $ fmap (Map.fromList . zip [(1::Int)..]) xs
391−
392{-
255{-
393schedulePostBuild x = performEvent_ . (x <$) =<< getPostBuild
256schedulePostBuild x = performEvent_ . (x <$) =<< getPostBuild
394
257
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+1
@@ -41,6 +41,7 @@ import GHCJS.DOM.HTMLTextAreaElement (HTMLTextAreaElement)
41import GHCJS.DOM.Types (MonadJSM, File, uncheckedCastTo)
41import GHCJS.DOM.Types (MonadJSM, File, uncheckedCastTo)
42import qualified GHCJS.DOM.Types as DOM (HTMLElement(..), EventTarget(..))
42import qualified GHCJS.DOM.Types as DOM (HTMLElement(..), EventTarget(..))
43import Reflex.Class
43import Reflex.Class
44+import Reflex.Collection
44import Reflex.Dom.Builder.Class
45import Reflex.Dom.Builder.Class
45import Reflex.Dom.Builder.Immediate
46import Reflex.Dom.Builder.Immediate
46import Reflex.Dom.Class
47import Reflex.Dom.Class
reflex-dom-core/src/Reflex/Dom/Widget/Lazy.hs+1
@@ -7,6 +7,7 @@
7module Reflex.Dom.Widget.Lazy where
7module Reflex.Dom.Widget.Lazy where
8
8
9import Reflex.Class
9import Reflex.Class
10+import Reflex.Collection
10import Reflex.Dom.Builder.Class
11import Reflex.Dom.Builder.Class
11import Reflex.Dom.Builder.Immediate
12import Reflex.Dom.Builder.Immediate
12import Reflex.Dom.Class
13import Reflex.Dom.Class
reflex-dom/examples/sortableList.hs+1−1
@@ -67,7 +67,7 @@ displayRedrawTime e = do
67 text "Time: "
67 text "Time: "
68 dynText =<< holdDyn "not yet run" (T.pack . show <$> diff)
68 dynText =<< holdDyn "not yet run" (T.pack . show <$> diff)
69
69
70−simpleSortableList :: forall t m k v. (MonadHold t m, MonadFix m, MonadAdjust t m, Ord k) => (k -> v -> m ()) -> Map k v -> Event t (v -> v -> Ordering) -> Event t (v -> v -> Ordering) -> m ()
70+simpleSortableList :: forall t m k v. (MonadHold t m, MonadFix m, Adjustable t m, Ord k) => (k -> v -> m ()) -> Map k v -> Event t (v -> v -> Ordering) -> Event t (v -> v -> Ordering) -> m ()
71simpleSortableList f m0 resortFunc resortSlowFunc = do
71simpleSortableList f m0 resortFunc resortSlowFunc = do
72 rec let resortPatchFast = attachWith (flip patchThatSortsMapWith) (currentIncremental m) resortFunc
72 rec let resortPatchFast = attachWith (flip patchThatSortsMapWith) (currentIncremental m) resortFunc
73 redrawPatch :: Map k v -> (v -> v -> Ordering) -> PatchMapWithMove k v
73 redrawPatch :: Map k v -> (v -> v -> Ordering) -> PatchMapWithMove k v