on develop help sign in
don't add child nodes when parent node cannot be found
09b98b1Ali Abrar
src/Reflex/Dom/Widget/Basic.hs+14−14
@@ -184,8 +184,8 @@ listWithKey vals mkChild = do
184 return ((result, voidAction), postBuild)
184 return ((result, voidAction), postBuild)
185 scheduleFollowup newChildrenTriggerRef $ fmap fst initialState --TODO: Do all these in a single runFrame
185 scheduleFollowup newChildrenTriggerRef $ fmap fst initialState --TODO: Do all these in a single runFrame
186 sequence_ $ fmap snd initialState
186 sequence_ $ fmap snd initialState
187− Just p <- liftIO $ nodeGetParentNode endPlaceholder
187+ mp <- liftIO $ nodeGetParentNode endPlaceholder
188− _ <- liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
188+ forM_ mp $ \p -> liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
189 return ()
189 return ()
190 addVoidAction $ flip fmap (updated vals) $ \newVals -> do
190 addVoidAction $ flip fmap (updated vals) $ \newVals -> do
191 curState <- sample children
191 curState <- sample children
@@ -202,8 +202,8 @@ listWithKey vals mkChild = do
202 let placeholder = case Map.lookupGT k curState of
202 let placeholder = case Map.lookupGT k curState of
203 Nothing -> endPlaceholder
203 Nothing -> endPlaceholder
204 Just (_, ((_, (start, _)), _)) -> start
204 Just (_, ((_, (start, _)), _)) -> start
205− Just p <- liftIO $ nodeGetParentNode placeholder
205+ mp <- liftIO $ nodeGetParentNode placeholder
206− _ <- liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
206+ forM_ mp $ \p -> liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
207 return $ Just s
207 return $ Just s
208 These state _ -> do
208 These state _ -> do
209 return $ Just state
209 return $ Just state
@@ -230,8 +230,8 @@ listWithKey' initialVals valsChanged mkChild = do
230 initialState <- iforM initialVals $ \k v -> subWidgetWithVoidActions (toNode dfOrig) $ wrapChild k v --Note: we have to use subWidgetWithVoidActions rather than runWidget here, because running post-build actions during build can cause not-yet-constructed values to be read
230 initialState <- iforM initialVals $ \k v -> subWidgetWithVoidActions (toNode dfOrig) $ wrapChild k v --Note: we have to use subWidgetWithVoidActions rather than runWidget here, because running post-build actions during build can cause not-yet-constructed values to be read
231 children <- holdDyn initialState newChildren
231 children <- holdDyn initialState newChildren
232 addVoidAction $ switch $ fmap (mergeWith (>>) . map snd . Map.elems) $ current children
232 addVoidAction $ switch $ fmap (mergeWith (>>) . map snd . Map.elems) $ current children
233− Just pOrig <- liftIO $ nodeGetParentNode endPlaceholder
233+ mpOrig <- liftIO $ nodeGetParentNode endPlaceholder
234− _ <- liftIO $ nodeInsertBefore pOrig (Just dfOrig) (Just endPlaceholder)
234+ forM_ mpOrig $ \pOrig -> liftIO $ nodeInsertBefore pOrig (Just dfOrig) (Just endPlaceholder)
235 addVoidAction $ flip fmap valsChanged $ \newVals -> do
235 addVoidAction $ flip fmap valsChanged $ \newVals -> do
236 curState <- sample $ current children
236 curState <- sample $ current children
237 --TODO: Should we remove the parent from the DOM first to avoid reflows?
237 --TODO: Should we remove the parent from the DOM first to avoid reflows?
@@ -245,8 +245,8 @@ listWithKey' initialVals valsChanged mkChild = do
245 (childResult, childPostBuild, childVoidAction) <- lift $ buildChild df k v
245 (childResult, childPostBuild, childVoidAction) <- lift $ buildChild df k v
246 let s = (childResult, childVoidAction)
246 let s = (childResult, childVoidAction)
247 modify (>>childPostBuild)
247 modify (>>childPostBuild)
248− Just p <- liftIO $ nodeGetParentNode end
248+ mp <- liftIO $ nodeGetParentNode end
249− _ <- liftIO $ nodeInsertBefore p (Just df) (Just end)
249+ forM_ mp $ \p -> liftIO $ nodeInsertBefore p (Just df) (Just end)
250 return $ Just s
250 return $ Just s
251 That Nothing -> return Nothing -- Deleting non-existent child
251 That Nothing -> return Nothing -- Deleting non-existent child
252 That (Just v) -> do -- Creating new child
252 That (Just v) -> do -- Creating new child
@@ -257,8 +257,8 @@ listWithKey' initialVals valsChanged mkChild = do
257 let placeholder = case Map.lookupGT k curState of
257 let placeholder = case Map.lookupGT k curState of
258 Nothing -> endPlaceholder
258 Nothing -> endPlaceholder
259 Just (_, ((_, (start, _)), _)) -> start
259 Just (_, ((_, (start, _)), _)) -> start
260− Just p <- liftIO $ nodeGetParentNode placeholder
260+ mp <- liftIO $ nodeGetParentNode placeholder
261− _ <- liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
261+ forM_ mp $ \p -> liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
262 return $ Just s
262 return $ Just s
263 This state -> do -- No change
263 This state -> do -- No change
264 return $ Just state
264 return $ Just state
@@ -292,8 +292,8 @@ listViewWithKey' vals mkChild = do
292 return ((result, voidAction), postBuild)
292 return ((result, voidAction), postBuild)
293 scheduleFollowup newChildrenTriggerRef $ fmap fst initialState --TODO: Do all these in a single runFrame
293 scheduleFollowup newChildrenTriggerRef $ fmap fst initialState --TODO: Do all these in a single runFrame
294 sequence_ $ fmap snd initialState
294 sequence_ $ fmap snd initialState
295− Just p <- liftIO $ nodeGetParentNode endPlaceholder
295+ mp <- liftIO $ nodeGetParentNode endPlaceholder
296− _ <- liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
296+ forM_ mp $ \p -> liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
297 return ()
297 return ()
298 addVoidAction $ flip fmap (updated vals) $ \newVals -> do
298 addVoidAction $ flip fmap (updated vals) $ \newVals -> do
299 curState <- sample children
299 curState <- sample children
@@ -310,8 +310,8 @@ listViewWithKey' vals mkChild = do
310 let placeholder = case Map.lookupGT k curState of
310 let placeholder = case Map.lookupGT k curState of
311 Nothing -> endPlaceholder
311 Nothing -> endPlaceholder
312 Just (_, ((_, (start, _)), _)) -> start
312 Just (_, ((_, (start, _)), _)) -> start
313− Just p <- liftIO $ nodeGetParentNode placeholder
313+ mp <- liftIO $ nodeGetParentNode placeholder
314− _ <- liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
314+ forM_ mp $ \p -> liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
315 return $ Just s
315 return $ Just s
316 These state _ -> do
316 These state _ -> do
317 return $ Just state
317 return $ Just state