UNPKG

1.24 kBJavaScriptView Raw
1'use strict';
2
3var makeAssimilatePrototype = require('./makeAssimilatePrototype'),
4 requestForceUpdateAll = require('./requestForceUpdateAll');
5
6function 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
19function 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 * Returns a function that will patch React class with new versions of itself
31 * on subsequent invocations. Both legacy and ES6 style classes are supported.
32 */
33module.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