( parent: React.ComponentType<P>, name: string )
| 92 | } |
| 93 | |
| 94 | function getDecorated<P extends Record<string, any>>( |
| 95 | parent: React.ComponentType<P>, |
| 96 | name: string |
| 97 | ): React.ComponentClass<P> { |
| 98 | if (!decorated[name]) { |
| 99 | let class_ = exposeDecorated(parent); |
| 100 | (class_ as any).displayName = `_exposeDecorated(${name})`; |
| 101 | |
| 102 | modules.forEach((mod: any) => { |
| 103 | const method = 'decorate' + name; |
| 104 | const fn: Function & {_pluginName: string} = mod[method]; |
| 105 | |
| 106 | if (fn) { |
| 107 | let class__; |
| 108 | |
| 109 | try { |
| 110 | class__ = fn(class_, {React, PureComponent, Notification, notify}); |
| 111 | class__.displayName = `${fn._pluginName}(${name})`; |
| 112 | } catch (err) { |
| 113 | notify( |
| 114 | 'Plugin error', |
| 115 | `${fn._pluginName}: Error occurred in \`${method}\`. Check Developer Tools for details`, |
| 116 | {error: err} |
| 117 | ); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if (!class__ || typeof class__.prototype.render !== 'function') { |
| 122 | notify( |
| 123 | 'Plugin error', |
| 124 | `${fn._pluginName}: Invalid return value of \`${method}\`. No \`render\` method found. Please return a \`React.Component\`.` |
| 125 | ); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | class_ = class__; |
| 130 | } |
| 131 | }); |
| 132 | |
| 133 | decorated[name] = class_; |
| 134 | } |
| 135 | |
| 136 | return decorated[name]; |
| 137 | } |
| 138 | |
| 139 | // for each component, we return a higher-order component |
| 140 | // that wraps with the higher-order components |
no test coverage detected