( workInProgress: Fiber, unmaskedContext: Object, )
| 71 | } |
| 72 | |
| 73 | function getMaskedContext( |
| 74 | workInProgress: Fiber, |
| 75 | unmaskedContext: Object, |
| 76 | ): Object { |
| 77 | if (disableLegacyContext) { |
| 78 | return emptyContextObject; |
| 79 | } else { |
| 80 | const type = workInProgress.type; |
| 81 | const contextTypes = type.contextTypes; |
| 82 | if (!contextTypes) { |
| 83 | return emptyContextObject; |
| 84 | } |
| 85 | |
| 86 | // Avoid recreating masked context unless unmasked context has changed. |
| 87 | // Failing to do this will result in unnecessary calls to componentWillReceiveProps. |
| 88 | // This may trigger infinite loops if componentWillReceiveProps calls setState. |
| 89 | const instance = workInProgress.stateNode; |
| 90 | if ( |
| 91 | instance && |
| 92 | instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext |
| 93 | ) { |
| 94 | return instance.__reactInternalMemoizedMaskedChildContext; |
| 95 | } |
| 96 | |
| 97 | const context: {[string]: $FlowFixMe} = {}; |
| 98 | for (const key in contextTypes) { |
| 99 | context[key] = unmaskedContext[key]; |
| 100 | } |
| 101 | |
| 102 | // Cache unmasked context so we can avoid recreating masked context unless necessary. |
| 103 | // Context is created before the class component is instantiated so check for instance. |
| 104 | if (instance) { |
| 105 | cacheContext(workInProgress, unmaskedContext, context); |
| 106 | } |
| 107 | |
| 108 | return context; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | function hasContextChanged(): boolean { |
| 113 | if (disableLegacyContext) { |
no test coverage detected