on develop help sign in
Fix problem where listWithKeyShallowDiff doesn't send deletions
commit5dac8ae2340ab27bd7c68211232a93cf0839430b authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 1 Sep 2015, 20:43 (11 years ago) parent249168e
1 file changed+4−1
src/Reflex/Dom/Widget/Basic.hs+4−1
src/Reflex/Dom/Widget/Basic.hs+4−1
@@ -187,7 +187,10 @@ listWithKeyShallowDiff :: (Ord k, MonadWidget t m) => Map k v -> Event t (Map k
187187listWithKeyShallowDiff initialVals valsChanged mkChild = do
188188 let childValChangedSelector = fanMap $ fmap (Map.mapMaybe id) valsChanged
189189 sentVals <- foldDyn (flip applyMap) Map.empty $ fmap (fmap (fmap (\_ -> ()))) valsChanged
190− listHoldWithKey initialVals (attachWith (flip Map.difference) (current sentVals) valsChanged) $ \k v ->
190+ let relevantDiff diff cur = case diff of
191+ 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
192+ Just _ -> Nothing -- We don't want to let spurious re-creations of items through
193+ listHoldWithKey initialVals (attachWith (flip (Map.differenceWith relevantDiff)) (current sentVals) valsChanged) $ \k v ->
191194 mkChild k v $ select childValChangedSelector $ Const2 k
192195
193196-- | Display the given map of items using the builder function provided, and update it with the given event. 'Nothing' entries will delete the corresponding children, and 'Just' entries will create or replace them. Since child events do not take any signal arguments, they are always rebuilt. To update a child without rebuilding, either embed signals in the map's values, or refer to them directly in the builder function.