MCPcopy Create free account
hub / github.com/QuarkGluonPlasma/react-course-code / commitEffectHooks

Function commitEffectHooks

mini-react/src/mini-react.js:303–347  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

301 }
302
303 function commitEffectHooks() {
304 function runCleanup(fiber){
305 if (!fiber) return;
306
307 fiber.alternate?.effectHooks?.forEach((hook, index)=>{
308 const deps = fiber.effectHooks[index].deps;
309
310 if (!hook.deps || !isDepsEqual(hook.deps, deps)) {
311 hook.cleanup?.();
312 }
313 })
314
315 runCleanup(fiber.child);
316 runCleanup(fiber.sibling);
317 }
318
319 function run(fiber) {
320 if (!fiber) return;
321
322 fiber.effectHooks?.forEach((newHook, index) => {
323 if(!fiber.alternate) {
324 newHook.cleanup = newHook.callback();
325 return;
326 }
327
328 if(!newHook.deps) {
329 newHook.cleanup = newHook.callback();
330 }
331
332 if (newHook.deps.length > 0) {
333 const oldHook = fiber.alternate?.effectHooks[index];
334
335 if(!isDepsEqual(oldHook.deps, newHook.deps)) {
336 newHook.cleanup = newHook.callback()
337 }
338 }
339 });
340
341 run(fiber.child);
342 run(fiber.sibling);
343 }
344
345 runCleanup(wipRoot);
346 run(wipRoot);
347 }
348
349 const MiniReact = {
350 createElement,

Callers 1

commitRootFunction · 0.85

Calls 2

runCleanupFunction · 0.85
runFunction · 0.85

Tested by

no test coverage detected