( instance: any, type: any, parentContext: Object, childContextTypes: Object, )
| 40 | } |
| 41 | |
| 42 | export function processChildContext( |
| 43 | instance: any, |
| 44 | type: any, |
| 45 | parentContext: Object, |
| 46 | childContextTypes: Object, |
| 47 | ): Object { |
| 48 | if (disableLegacyContext) { |
| 49 | return parentContext; |
| 50 | } else { |
| 51 | // TODO (bvaughn) Replace this behavior with an invariant() in the future. |
| 52 | // It has only been added in Fiber to match the (unintentional) behavior in Stack. |
| 53 | if (typeof instance.getChildContext !== 'function') { |
| 54 | if (__DEV__) { |
| 55 | const componentName = getComponentNameFromType(type) || 'Unknown'; |
| 56 | |
| 57 | if (!warnedAboutMissingGetChildContext[componentName]) { |
| 58 | warnedAboutMissingGetChildContext[componentName] = true; |
| 59 | console.error( |
| 60 | '%s.childContextTypes is specified but there is no getChildContext() method ' + |
| 61 | 'on the instance. You can either define getChildContext() on %s or remove ' + |
| 62 | 'childContextTypes from it.', |
| 63 | componentName, |
| 64 | componentName, |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | return parentContext; |
| 69 | } |
| 70 | |
| 71 | const childContext = instance.getChildContext(); |
| 72 | for (const contextKey in childContext) { |
| 73 | if (!(contextKey in childContextTypes)) { |
| 74 | throw new Error( |
| 75 | `${ |
| 76 | getComponentNameFromType(type) || 'Unknown' |
| 77 | }.getChildContext(): key "${contextKey}" is not defined in childContextTypes.`, |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 | return {...parentContext, ...childContext}; |
| 82 | } |
| 83 | } |
no test coverage detected