on develop help sign in
Fix problem where listWithKeyShallowDiff doesn't send deletions
5dac8aeRyan Trinkle
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
187listWithKeyShallowDiff initialVals valsChanged mkChild = do
187listWithKeyShallowDiff initialVals valsChanged mkChild = do
188 let childValChangedSelector = fanMap $ fmap (Map.mapMaybe id) valsChanged
188 let childValChangedSelector = fanMap $ fmap (Map.mapMaybe id) valsChanged
189 sentVals <- foldDyn (flip applyMap) Map.empty $ fmap (fmap (fmap (\_ -> ()))) valsChanged
189 sentVals <- foldDyn (flip applyMap) Map.empty $ fmap (fmap (fmap (\_ -> ()))) valsChanged
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
190− listHoldWithKey initialVals (attachWith (flip Map.difference) (current sentVals) valsChanged) $ \k v ->
193+ listHoldWithKey initialVals (attachWith (flip (Map.differenceWith relevantDiff)) (current sentVals) valsChanged) $ \k v ->
191 mkChild k v $ select childValChangedSelector $ Const2 k
194 mkChild k v $ select childValChangedSelector $ Const2 k
192
195
193-- | 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.
196-- | 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.