MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / updateContextConsumer

Function updateContextConsumer

code/communication/public/app.js:10414–10456  ·  view source on GitHub ↗
(current, workInProgress, renderExpirationTime)

Source from the content-addressed store, hash-verified

10412 }
10413
10414 function updateContextConsumer(current, workInProgress, renderExpirationTime) {
10415 var context = workInProgress.type;
10416 var newProps = workInProgress.pendingProps;
10417 var oldProps = workInProgress.memoizedProps;
10418
10419 var newValue = context._currentValue;
10420 var changedBits = context._changedBits;
10421
10422 if (hasLegacyContextChanged()) {
10423 // Normally we can bail out on props equality but if context has changed
10424 // we don't do the bailout and we have to reuse existing props instead.
10425 } else if (changedBits === 0 && oldProps === newProps) {
10426 return bailoutOnAlreadyFinishedWork(current, workInProgress);
10427 }
10428 workInProgress.memoizedProps = newProps;
10429
10430 var observedBits = newProps.unstable_observedBits;
10431 if (observedBits === undefined || observedBits === null) {
10432 // Subscribe to all changes by default
10433 observedBits = MAX_SIGNED_31_BIT_INT;
10434 }
10435 // Store the observedBits on the fiber's stateNode for quick access.
10436 workInProgress.stateNode = observedBits;
10437
10438 if ((changedBits & observedBits) !== 0) {
10439 // Context change propagation stops at matching consumers, for time-
10440 // slicing. Continue the propagation here.
10441 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
10442 } else if (oldProps !== null && oldProps.children === newProps.children) {
10443 // No change. Bailout early if children are the same.
10444 return bailoutOnAlreadyFinishedWork(current, workInProgress);
10445 }
10446
10447 var render = newProps.children;
10448
10449 {
10450 warning(typeof render === 'function', 'A context consumer was rendered with multiple children, or a child ' + "that isn't a function. A context consumer expects a single child " + 'that is a function. If you did pass a function, make sure there ' + 'is no trailing or leading whitespace around it.');
10451 }
10452
10453 var newChildren = render(newValue);
10454 reconcileChildren(current, workInProgress, newChildren);
10455 return workInProgress.child;
10456 }
10457
10458 /*
10459 function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) {

Callers 1

beginWorkFunction · 0.70

Calls 4

warningFunction · 0.85
propagateContextChangeFunction · 0.70
reconcileChildrenFunction · 0.70

Tested by

no test coverage detected