on develop help sign in
Fix runWithReplace when the initial child isn't ready immediately
commit107129a9ea02b79a7e9d14b76c7e282e8679ca01 authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 24 Apr 2017, 15:01 (10 years ago) parentb96b7ff
1 file changed+2−3
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+2−3
reflex-dom-core/src/Reflex/Dom/Builder/Immediate.hs+2−3
@@ -579,6 +579,7 @@ instance (Reflex t, MonadAdjust t m, MonadJSM m, MonadHold t m, PerformEvent t m
579579 before <- textNodeInternal ("" :: Text)
580580 let parentUnreadyChildren = _immediateDomBuilderEnv_unreadyChildren initialEnv
581581 haveEverBeenReady <- liftIO $ newIORef False
582+ currentCohort <- liftIO $ newIORef (-1 :: Int) -- Equal to the cohort currently in the DOM
582583 let myCommitAction = do
583584 liftIO (readIORef haveEverBeenReady) >>= \case
584585 True -> return ()
@@ -604,14 +605,13 @@ instance (Reflex t, MonadAdjust t m, MonadJSM m, MonadHold t m, PerformEvent t m
604605 0 -> writeIORef haveEverBeenReady True
605606 _ -> modifyIORef' parentUnreadyChildren succ
606607 return result
607− currentCohort <- liftIO $ newIORef (0 :: Int)
608608 a'' <- numberOccurrences a'
609609 (result0, result') <- lift $ runWithReplace drawInitialChild $ ffor a'' $ \(cohortId, child) -> do
610610 df <- createDocumentFragmentUnchecked $ _immediateDomBuilderEnv_document initialEnv
611611 unreadyChildren <- liftIO $ newIORef 0
612612 let commitAction = do
613613 c <- liftIO $ readIORef currentCohort
614− when (c < cohortId) $ do -- If a newer cohort has already been committed, just ignore this
614+ when (c <= cohortId) $ do -- If a newer cohort has already been committed, just ignore this
615615 deleteBetweenExclusive before after
616616 insertBefore df after
617617 liftIO $ writeIORef currentCohort cohortId
@@ -621,7 +621,6 @@ instance (Reflex t, MonadAdjust t m, MonadJSM m, MonadHold t m, PerformEvent t m
621621 , _immediateDomBuilderEnv_unreadyChildren = unreadyChildren
622622 , _immediateDomBuilderEnv_commitAction = commitAction
623623 }
624−
625624 liftIO (readIORef unreadyChildren) >>= \case
626625 0 -> liftJSM commitAction
627626 _ -> return () -- Whoever decrements it to 0 will handle it