on develop help sign in
Merge pull request #106 from rheosystems/fix-list-with-key

Use listHoldWithKey in listWithKey

commit6ac9ace6f8d5c61e2b20dc8297a408e07c90c7c1 authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 18 Oct 2016, 01:49 (10 years ago) parented3b790ff01487
1 file changed+5−4
src/Reflex/Dom/Widget/Basic.hs+5−4
src/Reflex/Dom/Widget/Basic.hs+5−4
@@ -79,7 +79,7 @@ module Reflex.Dom.Widget.Basic
7979 , HasAttributes (..)
8080 ) where
8181
82−import Reflex.Class as Reflex
82+import Reflex.Class
8383import Reflex.Dom.Builder.Class
8484import Reflex.Dom.Class
8585import Reflex.Dom.Internal.Foreign ()
@@ -228,14 +228,15 @@ applyMapKeysSet patch old = Map.keysSet insertions `Set.union` (old `Set.differe
228228listWithKey :: 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))
229229listWithKey vals mkChild = do
230230 postBuild <- getPostBuild
231+ let childValChangedSelector = fanMap $ updated vals
231232 rec sentVals :: Dynamic t (Map k v) <- foldDyn applyMap Map.empty changeVals
232233 let changeVals :: Event t (Map k (Maybe v))
233234 changeVals = attachWith diffMapNoEq (current sentVals) $ leftmost
234235 [ updated vals
235236 , 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
236237 ]
237− listWithKeyShallowDiff Map.empty changeVals $ \k v0 dv -> do
238− mkChild k =<< holdDyn v0 dv
238+ listHoldWithKey Map.empty changeVals $ \k v ->
239+ mkChild k =<< holdDyn v (select childValChangedSelector $ Const2 k)
239240
240241{-# DEPRECATED listWithKey' "listWithKey' has been renamed to listWithKeyShallowDiff; also, its behavior has changed to fix a bug where children were always rebuilt (never updated)" #-}
241242listWithKey' :: (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))
@@ -250,7 +251,7 @@ listWithKeyShallowDiff initialVals valsChanged mkChild = do
250251 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
251252 Just _ -> Nothing -- We don't want to let spurious re-creations of items through
252253 listHoldWithKey initialVals (attachWith (flip (Map.differenceWith relevantPatch)) (current sentVals) valsChanged) $ \k v ->
253− mkChild k v $ Reflex.select childValChangedSelector $ Const2 k
254+ mkChild k v $ select childValChangedSelector $ Const2 k
254255
255256--TODO: Something better than Dynamic t (Map k v) - we want something where the Events carry diffs, not the whole value
256257-- | Create a dynamically-changing set of Event-valued widgets.