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

Function updateContextConsumer

code/third-party/public/app.js:9612–9654  ·  view source on GitHub ↗
(current, workInProgress, renderExpirationTime)

Source from the content-addressed store, hash-verified

9610 }
9611
9612 function updateContextConsumer(current, workInProgress, renderExpirationTime) {
9613 var context = workInProgress.type;
9614 var newProps = workInProgress.pendingProps;
9615 var oldProps = workInProgress.memoizedProps;
9616
9617 var newValue = context._currentValue;
9618 var changedBits = context._changedBits;
9619
9620 if (hasLegacyContextChanged()) {
9621 // Normally we can bail out on props equality but if context has changed
9622 // we don't do the bailout and we have to reuse existing props instead.
9623 } else if (changedBits === 0 && oldProps === newProps) {
9624 return bailoutOnAlreadyFinishedWork(current, workInProgress);
9625 }
9626 workInProgress.memoizedProps = newProps;
9627
9628 var observedBits = newProps.unstable_observedBits;
9629 if (observedBits === undefined || observedBits === null) {
9630 // Subscribe to all changes by default
9631 observedBits = MAX_SIGNED_31_BIT_INT;
9632 }
9633 // Store the observedBits on the fiber's stateNode for quick access.
9634 workInProgress.stateNode = observedBits;
9635
9636 if ((changedBits & observedBits) !== 0) {
9637 // Context change propagation stops at matching consumers, for time-
9638 // slicing. Continue the propagation here.
9639 propagateContextChange(workInProgress, context, changedBits, renderExpirationTime);
9640 } else if (oldProps !== null && oldProps.children === newProps.children) {
9641 // No change. Bailout early if children are the same.
9642 return bailoutOnAlreadyFinishedWork(current, workInProgress);
9643 }
9644
9645 var render = newProps.children;
9646
9647 {
9648 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.');
9649 }
9650
9651 var newChildren = render(newValue);
9652 reconcileChildren(current, workInProgress, newChildren);
9653 return workInProgress.child;
9654 }
9655
9656 /*
9657 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