MCPcopy Index your code
hub / github.com/krasimir/react-in-patterns / ReactFiberLegacyContext

Function ReactFiberLegacyContext

code/new-context-api/public/app.js:11642–11863  ·  view source on GitHub ↗
(stack)

Source from the content-addressed store, hash-verified

11640}
11641
11642var ReactFiberLegacyContext = function (stack) {
11643 var createCursor = stack.createCursor,
11644 push = stack.push,
11645 pop = stack.pop;
11646
11647 // A cursor to the current merged context object on the stack.
11648
11649 var contextStackCursor = createCursor(emptyObject);
11650 // A cursor to a boolean indicating whether the context has changed.
11651 var didPerformWorkStackCursor = createCursor(false);
11652 // Keep track of the previous context object that was on the stack.
11653 // We use this to get access to the parent context after we have already
11654 // pushed the next context provider, and now need to merge their contexts.
11655 var previousContext = emptyObject;
11656
11657 function getUnmaskedContext(workInProgress) {
11658 var hasOwnContext = isContextProvider(workInProgress);
11659 if (hasOwnContext) {
11660 // If the fiber is a context provider itself, when we read its context
11661 // we have already pushed its own child context on the stack. A context
11662 // provider should not "see" its own child context. Therefore we read the
11663 // previous (parent) context instead for a context provider.
11664 return previousContext;
11665 }
11666 return contextStackCursor.current;
11667 }
11668
11669 function cacheContext(workInProgress, unmaskedContext, maskedContext) {
11670 var instance = workInProgress.stateNode;
11671 instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
11672 instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
11673 }
11674
11675 function getMaskedContext(workInProgress, unmaskedContext) {
11676 var type = workInProgress.type;
11677 var contextTypes = type.contextTypes;
11678 if (!contextTypes) {
11679 return emptyObject;
11680 }
11681
11682 // Avoid recreating masked context unless unmasked context has changed.
11683 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
11684 // This may trigger infinite loops if componentWillReceiveProps calls setState.
11685 var instance = workInProgress.stateNode;
11686 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
11687 return instance.__reactInternalMemoizedMaskedChildContext;
11688 }
11689
11690 var context = {};
11691 for (var key in contextTypes) {
11692 context[key] = unmaskedContext[key];
11693 }
11694
11695 {
11696 var name = getComponentName(workInProgress) || 'Unknown';
11697 checkPropTypes(contextTypes, context, 'context', name, ReactDebugCurrentFiber.getCurrentFiberStackAddendum);
11698 }
11699

Callers 1

ReactFiberSchedulerFunction · 0.70

Calls 1

createCursorFunction · 0.70

Tested by

no test coverage detected