如題,比如 ReactFilberScheduler.js? 中有一個(gè)全局變量 isRendering 變量在 requestWork? 和 performWorkOnRoot 方法中有用到,requestWork 函數(shù)開(kāi)頭判斷當(dāng) isRendering = true 的直接返回return;而在?performWorkOnRoot 的開(kāi)頭將?isRendering 置為 true? 而在末尾置為 false,那么問(wèn)題來(lái)了? requestWork? 的開(kāi)頭對(duì) isRendering 的判斷有什么意義?function requestWork(root: FiberRoot, expirationTime: ExpirationTime) {? addRootToSchedule(root, expirationTime);? if (isRendering) {? ? // Prevent reentrancy. Remaining work will be scheduled at the end of? ? // the currently rendering batch.? ? return;? }? //....Omitted code}function performWorkOnRoot(root: FiberRoot, expirationTime: ExpirationTime, isExpired: boolean) {? invariant(? ? !isRendering,? ? 'performWorkOnRoot was called recursively. This error is likely caused ' +? ? ? 'by a bug in React. Please file an issue.',? );? isRendering = true; ? //...Omitted code? isRendering = false;}
關(guān)于React源碼中一些全局變量用意有些疑問(wèn),貼了關(guān)于 isRendering 全局變量的代碼,有沒(méi)有幫忙解答一下的?
一身三影
2019-07-03 15:37:04