Skip to content

Commit

Permalink
三: 3.创建 workLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-lx committed Nov 10, 2021
1 parent e6967c0 commit 5b5c5fa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mini-react/fiber.js
Expand Up @@ -102,3 +102,16 @@ function performUnitOfWork(workInProgress) {
}
}
}

// 处理循环和中断逻辑
function workLoop(deadline) {
let shouldYield = false;
while (nextUnitOfWork && !shouldYield) {
// 循环执行工作单元任务
performUnitOfWork(nextUnitOfWork);
shouldYield = deadline.timeRemaining() < 1;
}
requestIdleCallback(workLoop);
}

requestIdleCallback(workLoop);

0 comments on commit 5b5c5fa

Please sign in to comment.