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

Function getMaskedContext

code/one-direction-data-flow/public/app.js:12187–12219  ·  view source on GitHub ↗
(workInProgress, unmaskedContext)

Source from the content-addressed store, hash-verified

12185 }
12186
12187 function getMaskedContext(workInProgress, unmaskedContext) {
12188 var type = workInProgress.type;
12189 var contextTypes = type.contextTypes;
12190 if (!contextTypes) {
12191 return emptyObject;
12192 }
12193
12194 // Avoid recreating masked context unless unmasked context has changed.
12195 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
12196 // This may trigger infinite loops if componentWillReceiveProps calls setState.
12197 var instance = workInProgress.stateNode;
12198 if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
12199 return instance.__reactInternalMemoizedMaskedChildContext;
12200 }
12201
12202 var context = {};
12203 for (var key in contextTypes) {
12204 context[key] = unmaskedContext[key];
12205 }
12206
12207 {
12208 var name = getComponentName(workInProgress) || 'Unknown';
12209 checkPropTypes(contextTypes, context, 'context', name, ReactDebugCurrentFiber.getCurrentFiberStackAddendum);
12210 }
12211
12212 // Cache unmasked context so we can avoid recreating masked context unless necessary.
12213 // Context is created before the class component is instantiated so check for instance.
12214 if (instance) {
12215 cacheContext(workInProgress, unmaskedContext, context);
12216 }
12217
12218 return context;
12219 }
12220
12221 function hasContextChanged() {
12222 return didPerformWorkStackCursor.current;

Callers 6

constructClassInstanceFunction · 0.70
mountClassInstanceFunction · 0.70
resumeMountClassInstanceFunction · 0.70
updateClassInstanceFunction · 0.70

Calls 3

getComponentNameFunction · 0.70
checkPropTypesFunction · 0.70
cacheContextFunction · 0.70

Tested by

no test coverage detected