1 | 'use strict';
|
2 |
|
3 | var makeAssimilatePrototype = require('./makeAssimilatePrototype'),
|
4 | requestForceUpdateAll = require('./requestForceUpdateAll');
|
5 |
|
6 | function hasLegacyTypeProperty(ReactClass) {
|
7 | if (!ReactClass.hasOwnProperty('type')) {
|
8 | return false;
|
9 | }
|
10 |
|
11 | var descriptor = Object.getOwnPropertyDescriptor(ReactClass, 'type');
|
12 | if (typeof descriptor.get === 'function') {
|
13 | return false;
|
14 | }
|
15 |
|
16 | return true;
|
17 | }
|
18 |
|
19 | function getPrototype(ReactClass) {
|
20 | var prototype = ReactClass.prototype;
|
21 |
|
22 | if (typeof prototype.render !== 'function' && hasLegacyTypeProperty(ReactClass)) {
|
23 | prototype = ReactClass.type.prototype;
|
24 | }
|
25 |
|
26 | return prototype;
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | module.exports = function makePatchReactClass(getRootInstances) {
|
34 | var assimilatePrototype = makeAssimilatePrototype(),
|
35 | FirstClass = null;
|
36 |
|
37 | return function patchReactClass(NextClass) {
|
38 | var nextPrototype = getPrototype(NextClass);
|
39 | assimilatePrototype(nextPrototype);
|
40 |
|
41 | if (FirstClass) {
|
42 | requestForceUpdateAll(getRootInstances);
|
43 | }
|
44 |
|
45 | return FirstClass || (FirstClass = NextClass);
|
46 | };
|
47 | }; |
\ | No newline at end of file |