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

Function ReactFiberLegacyContext

code/third-party/public/app.js:11514–11735  ·  view source on GitHub ↗
(stack)

Source from the content-addressed store, hash-verified

11512}
11513
11514var ReactFiberLegacyContext = function (stack) {
11515 var createCursor = stack.createCursor,
11516 push = stack.push,
11517 pop = stack.pop;
11518
11519 // A cursor to the current merged context object on the stack.
11520
11521 var contextStackCursor = createCursor(emptyObject);
11522 // A cursor to a boolean indicating whether the context has changed.
11523 var didPerformWorkStackCursor = createCursor(false);
11524 // Keep track of the previous context object that was on the stack.
11525 // We use this to get access to the parent context after we have already
11526 // pushed the next context provider, and now need to merge their contexts.
11527 var previousContext = emptyObject;
11528
11529 function getUnmaskedContext(workInProgress) {
11530 var hasOwnContext = isContextProvider(workInProgress);
11531 if (hasOwnContext) {
11532 // If the fiber is a context provider itself, when we read its context
11533 // we have already pushed its own child context on the stack. A context
11534 // provider should not "see" its own child context. Therefore we read the
11535 // previous (parent) context instead for a context provider.
11536 return previousContext;
11537 }
11538 return contextStackCursor.current;
11539 }
11540
11541 function cacheContext(workInProgress, unmaskedContext, maskedContext) {
11542 var instance = workInProgress.stateNode;
11543 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
11544 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
11545 }
11546
11547 function getMaskedContext(workInProgress, unmaskedContext) {
11548 var type = workInProgress.type;
11549 var contextTypes = type.contextTypes;
11550 if (!contextTypes) {
11551 return emptyObject;
11552 }
11553
11554 // Avoid recreating masked context unless unmasked context has changed.
11555 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
11556 // This may trigger infinite loops if componentWillReceiveProps calls setState.
11557 var instance = workInProgress.stateNode;
11558 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
11559 return instance.__reactInternalMemoizedMaskedChildContext;
11560 }
11561
11562 var context = {};
11563 for (var key in contextTypes) {
11564 context[key] = unmaskedContext[key];
11565 }
11566
11567 {
11568 var name = getComponentName(workInProgress) || 'Unknown';
11569 checkPropTypes(contextTypes, context, 'context', name, ReactDebugCurrentFiber.getCurrentFiberStackAddendum);
11570 }
11571

Callers 1

ReactFiberSchedulerFunction · 0.70

Calls 1

createCursorFunction · 0.70

Tested by

no test coverage detected