on develop help sign in
Moves the collection management functions to `reflex`.

Also deals with the renaming of `MonadAdjust`.

commit986e1cfb514e8a8832479924166920f783787742 authorDave Laing <dave.laing.80@gmail.com> dateSat 8 Jul 2017, 17:55 (9 years ago) parent585d49e
10 files changed+20−155
reflex-dom-core/src/Foreign/JavaScript/TH.hs+1−1 reflex-dom-core/src/Reflex/Dom/Builder/Class.hs+1−1 reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+7−7 reflex-dom-core/src/Reflex/Dom/Builder/InputDisabled.hs+1−1 reflex-dom-core/src/Reflex/Dom/Builder/Static.hs+4−4 reflex-dom-core/src/Reflex/Dom/Modals/Base.hs+1−1 reflex-dom-core/src/Reflex/Dom/Widget/Basic.hs+2−139 reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+1 reflex-dom-core/src/Reflex/Dom/Widget/Lazy.hs+1 reflex-dom/examples/sortableList.hs+1−1
reflex-dom-core/src/Foreign/JavaScript/TH.hs+1−1
@@ -136,7 +136,7 @@ instance PrimMonad m => PrimMonad (WithJSContextSingleton x m) where
136136 type PrimState (WithJSContextSingleton x m) = PrimState m
137137 primitive = lift . primitive
138138
139−instance MonadAdjust t m => MonadAdjust t (WithJSContextSingleton x m) where
139+instance Adjustable t m => Adjustable t (WithJSContextSingleton x m) where
140140 runWithReplace a0 a' = WithJSContextSingleton $ runWithReplace (coerce a0) (coerceEvent a')
141141 traverseIntMapWithKeyWithAdjust f dm0 dm' = WithJSContextSingleton $ traverseIntMapWithKeyWithAdjust (\k v -> unWithJSContextSingleton $ f k v) (coerce dm0) (coerceEvent dm')
142142 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
7070
7171-- | @'DomBuilder' t m@ indicates that @m@ is a 'Monad' capable of building
7272-- 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
7474 type DomBuilderSpace m :: *
7575 textNode :: TextNodeConfig t -> m (TextNode (DomBuilderSpace m) t)
7676 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
325325 void $ call f f (df, s, e)
326326#endif
327327
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)
329329
330330{-# INLINABLE collectUpTo #-}
331331collectUpTo :: (MonadJSM m, IsNode start, IsNode end) => start -> end -> m DOM.DocumentFragment
@@ -388,7 +388,7 @@ wrap e cfg = do
388388 }
389389
390390{-# 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)
392392makeElement elementTag cfg child = do
393393 doc <- askDocument
394394 e <- liftJSM $ uncheckedCastTo DOM.Element <$> case cfg ^. namespace of
@@ -640,7 +640,7 @@ instance SupportsImmediateDomBuilder t m => MountableDomBuilder t (ImmediateDomB
640640 liftIO $ writeIORef (_immediateDomFragment_state childFragment) $ FragmentState_Mounted (before, after)
641641 liftIO $ writeIORef (_immediateDomFragment_state fragment) $ FragmentState_Mounted (before, after)
642642
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
644644 {-# INLINABLE runWithReplace #-}
645645 runWithReplace a0 a' = do
646646 initialEnv <- ImmediateDomBuilderT ask
@@ -753,7 +753,7 @@ instance (Reflex t, MonadAdjust t m, MonadJSM m, MonadHold t m, MonadFix m, Prim
753753 liftIO $ writeIORef placeholders $! phsAfter
754754
755755{-# 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'))
757757traverseDMapWithKeyWithAdjust' = do
758758 let updateChildUnreadiness (p :: PatchDMap k (Compose ((,,,) DOM.DocumentFragment DOM.Text (IORef (ChildReadyState k))) v')) old = do
759759 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
781781 liftIO $ writeIORef placeholders $! fromMaybe phs $ apply (weakenPatchDMapWith (\(Compose (_, ph, _, _)) -> ph) $ PatchDMap p) phs
782782
783783{-# 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'))
785785traverseIntMapWithKeyWithAdjust' = do
786786 let updateChildUnreadiness (p@(PatchIntMap pInner) :: PatchIntMap (DOM.DocumentFragment, DOM.Text, IORef ChildReadyStateInt, v')) old = do
787787 let new :: IntMap.Key -> Maybe (DOM.DocumentFragment, DOM.Text, IORef ChildReadyStateInt, v') -> IO (Maybe (IORef ChildReadyStateInt))
@@ -824,7 +824,7 @@ data ChildReadyStateInt
824824
825825{-# INLINE hoistTraverseIntMapWithKeyWithAdjust #-}
826826hoistTraverseIntMapWithKeyWithAdjust :: forall v v' t m p.
827− ( MonadAdjust t m
827+ ( Adjustable t m
828828 , MonadIO m
829829 , MonadJSM m
830830 , MonadFix m
@@ -908,7 +908,7 @@ hoistTraverseIntMapWithKeyWithAdjust base updateChildUnreadiness applyDomUpdate_
908908
909909{-# INLINABLE hoistTraverseWithKeyWithAdjust #-}
910910hoistTraverseWithKeyWithAdjust :: forall (k :: * -> *) v v' t m p.
911− ( MonadAdjust t m
911+ ( Adjustable t m
912912 , MonadHold t m
913913 , DMap.GCompare k
914914 , MonadIO m
reflex-dom-core/src/Reflex/Dom/Builder/InputDisabled.hs+1−1
@@ -76,7 +76,7 @@ instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (InputDisabl
7676 newEventWithTrigger = lift . newEventWithTrigger
7777 newFanEventWithTrigger f = lift $ newFanEventWithTrigger f
7878
79−instance MonadAdjust t m => MonadAdjust t (InputDisabledT m) where
79+instance Adjustable t m => Adjustable t (InputDisabledT m) where
8080 runWithReplace a0 a' = InputDisabledT $ runWithReplace (coerce a0) (coerceEvent a')
8181 traverseDMapWithKeyWithAdjust f dm0 dm' = InputDisabledT $ traverseDMapWithKeyWithAdjust (\k v -> runInputDisabledT $ f k v) (coerce dm0) (coerceEvent dm')
8282 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 (..))
3333import Data.Functor.Compose
3434import Data.Functor.Constant
3535import qualified Data.Map as Map
36+import Data.Map.Misc (applyMap)
3637import Data.Monoid
3738import qualified Data.Set as Set
3839import Data.Text (Text)
@@ -41,7 +42,6 @@ import Data.Tuple
4142import GHC.Generics
4243import Reflex.Class
4344import Reflex.Dom.Builder.Class
44−import Reflex.Dom.Widget.Basic (applyMap)
4545import Reflex.Dynamic
4646import Reflex.Host.Class
4747import Reflex.PerformEvent.Base
@@ -122,7 +122,7 @@ instance MonadRef m => MonadRef (StaticDomBuilderT t m) where
122122instance MonadAtomicRef m => MonadAtomicRef (StaticDomBuilderT t m) where
123123 atomicModifyRef r = lift . atomicModifyRef r
124124
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)
126126
127127data StaticDomSpace
128128
@@ -146,7 +146,7 @@ instance DomSpace StaticDomSpace where
146146 type RawSelectElement StaticDomSpace = ()
147147 addEventSpecFlags _ _ _ _ = StaticEventSpec
148148
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
150150 runWithReplace a0 a' = do
151151 e <- StaticDomBuilderT ask
152152 (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
157157 traverseDMapWithKeyWithAdjustWithMove = hoistDMapWithKeyWithAdjust traverseDMapWithKeyWithAdjustWithMove mapPatchDMapWithMove
158158
159159hoistDMapWithKeyWithAdjust :: forall (k :: * -> *) v v' t m p.
160− ( MonadAdjust t m
160+ ( Adjustable t m
161161 , MonadHold t m
162162 , PatchTarget (p k (Constant (Behavior t Builder))) ~ DMap k (Constant (Behavior t Builder))
163163 , 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
106106 {-# INLINABLE atomicModifyRef #-}
107107 atomicModifyRef r = lift . atomicModifyRef r
108108
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
110110 runWithReplace a0 a' = ModalsT $ runWithReplace (unModalsT a0) (fmapCheap unModalsT a')
111111 traverseDMapWithKeyWithAdjust f dm0 dm' = ModalsT $ traverseDMapWithKeyWithAdjust (coerce f) dm0 dm'
112112 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 @@
33{-# LANGUAGE FlexibleContexts #-}
44{-# LANGUAGE FlexibleInstances #-}
55{-# LANGUAGE GADTs #-}
6−{-# LANGUAGE LambdaCase #-}
76{-# LANGUAGE MultiParamTypeClasses #-}
87{-# LANGUAGE OverloadedStrings #-}
98{-# LANGUAGE RankNTypes #-}
@@ -12,7 +11,6 @@
1211{-# LANGUAGE TypeFamilies #-}
1312module Reflex.Dom.Widget.Basic
1413 ( partitionMapBySetLT
15− , listHoldWithKey
1614 , ChildResult (..)
1715
1816 -- * Displaying Values
@@ -24,21 +22,6 @@ module Reflex.Dom.Widget.Basic
2422 , widgetHold
2523 , untilReady
2624
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−
4225 -- * Creating DOM Elements
4326 , el
4427 , elAttr
@@ -56,10 +39,6 @@ module Reflex.Dom.Widget.Basic
5639 , dynamicAttributesToModifyAttributes
5740 , dynamicAttributesToModifyAttributesWithInitial
5841
59− -- * List Utils
60− , list
61− , simpleList
62−
6342 -- * Specific DOM Elements
6443 , Link (..)
6544 , linkClass
@@ -83,6 +62,7 @@ module Reflex.Dom.Widget.Basic
8362 ) where
8463
8564import Reflex.Class
65+import Reflex.Collection
8666import Reflex.Dom.Builder.Class
8767import Reflex.Dom.Class
8868import Reflex.Dynamic
@@ -95,9 +75,9 @@ import Data.Align
9575import Data.Default
9676import Data.Either
9777import Data.Foldable
98−import Data.Functor.Misc
9978import Data.Map (Map)
10079import qualified Data.Map as Map
80+import Data.Map.Misc
10181import Data.Maybe
10282import Data.Set (Set)
10383import qualified Data.Set as Set
@@ -129,13 +109,6 @@ partitionMapBySetLT s m0 = Map.fromDistinctAscList $ go (Set.toAscList s) m0
129109
130110newtype ChildResult t k a = ChildResult { unChildResult :: (a, Event t (Map k (Maybe (ChildResult t k a)))) }
131111
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−
139112text :: DomBuilder t m => Text -> m ()
140113text t = void $ textNode $ def & textNodeConfig_initialContents .~ t
141114
@@ -182,107 +155,6 @@ untilReady a b = do
182155 postBuild <- getPostBuild
183156 runWithReplace a $ b <$ postBuild
184157
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−
286158-- | Create a DOM element
287159-- > el "div" (text "Hello World")
288160-- <div>Hello World</div>
@@ -380,15 +252,6 @@ dynamicAttributesToModifyAttributesWithInitial attrs0 d = do
380252-- Copied and pasted from Reflex.Widget.Class
381253--------------------------------------------------------------------------------
382254
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−
392255{-
393256schedulePostBuild x = performEvent_ . (x <$) =<< getPostBuild
394257
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+1
@@ -41,6 +41,7 @@ import GHCJS.DOM.HTMLTextAreaElement (HTMLTextAreaElement)
4141import GHCJS.DOM.Types (MonadJSM, File, uncheckedCastTo)
4242import qualified GHCJS.DOM.Types as DOM (HTMLElement(..), EventTarget(..))
4343import Reflex.Class
44+import Reflex.Collection
4445import Reflex.Dom.Builder.Class
4546import Reflex.Dom.Builder.Immediate
4647import Reflex.Dom.Class
reflex-dom-core/src/Reflex/Dom/Widget/Lazy.hs+1
@@ -7,6 +7,7 @@
77module Reflex.Dom.Widget.Lazy where
88
99import Reflex.Class
10+import Reflex.Collection
1011import Reflex.Dom.Builder.Class
1112import Reflex.Dom.Builder.Immediate
1213import Reflex.Dom.Class
reflex-dom/examples/sortableList.hs+1−1
@@ -67,7 +67,7 @@ displayRedrawTime e = do
6767 text "Time: "
6868 dynText =<< holdDyn "not yet run" (T.pack . show <$> diff)
6969
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 ()
7171simpleSortableList f m0 resortFunc resortSlowFunc = do
7272 rec let resortPatchFast = attachWith (flip patchThatSortsMapWith) (currentIncremental m) resortFunc
7373 redrawPatch :: Map k v -> (v -> v -> Ordering) -> PatchMapWithMove k v