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

Function updateContextProvider

code/dependency-injection/public/app.js:10397–10470  ·  view source on GitHub ↗
(current, workInProgress, renderExpirationTime)

Source from the content-addressed store, hash-verified

10395 }
10396
10397 function updateContextProvider(current, workInProgress, renderExpirationTime) {
10398 var providerType = workInProgress.type;
10399 var context = providerType.context;
10400
10401 var newProps = workInProgress.pendingProps;
10402 var oldProps = workInProgress.memoizedProps;
10403
10404 if (hasLegacyContextChanged()) {
10405 // Normally we can bail out on props equality but if context has changed
10406 // we don't do the bailout and we have to reuse existing props instead.
10407 } else if (oldProps === newProps) {
10408 workInProgress.stateNode = 0;
10409 pushProvider(workInProgress);
10410 return bailoutOnAlreadyFinishedWork(current, workInProgress);
10411 }
10412
10413 var newValue = newProps.value;
10414 workInProgress.memoizedProps = newProps;
10415
10416 var changedBits = void 0;
10417 if (oldProps === null) {
10418 // Initial render
10419 changedBits = MAX_SIGNED_31_BIT_INT;
10420 } else {
10421 if (oldProps.value === newProps.value) {
10422 // No change. Bailout early if children are the same.
10423 if (oldProps.children === newProps.children) {
10424 workInProgress.stateNode = 0;
10425 pushProvider(workInProgress);
10426 return bailoutOnAlreadyFinishedWork(current, workInProgress);
10427 }
10428 changedBits = 0;
10429 } else {
10430 var oldValue = oldProps.value;
10431 // Use Object.is to compare the new context value to the old value.
10432 // Inlined Object.is polyfill.
10433 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
10434 if (oldValue === newValue && (oldValue !== 0 || 1 / oldValue === 1 / newValue) || oldValue !== oldValue && newValue !== newValue // eslint-disable-line no-self-compare
10435 ) {
10436 // No change. Bailout early if children are the same.
10437 if (oldProps.children === newProps.children) {
10438 workInProgress.stateNode = 0;
10439 pushProvider(workInProgress);
10440 return bailoutOnAlreadyFinishedWork(current, workInProgress);
10441 }
10442 changedBits = 0;
10443 } else {
10444 changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
10445 {
10446 warning((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
10447 }
10448 changedBits |= 0;
10449
10450 if (changedBits === 0) {
10451 // No change. Bailout early if children are the same.
10452 if (oldProps.children === newProps.children) {
10453 workInProgress.stateNode = 0;
10454 pushProvider(workInProgress);

Callers 1

beginWorkFunction · 0.70

Calls 5

warningFunction · 0.85
pushProviderFunction · 0.70
propagateContextChangeFunction · 0.70
reconcileChildrenFunction · 0.70

Tested by

no test coverage detected