1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.proxyClassCreator = exports.isReactComponentInstance = exports.doesSupportClasses = exports.identity = exports.reactLifeCycleMountMethods = undefined;
|
5 |
|
6 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
7 |
|
8 |
|
9 | exports.getDisplayName = getDisplayName;
|
10 | exports.isReactClass = isReactClass;
|
11 | exports.safeReactConstructor = safeReactConstructor;
|
12 | exports.isNativeFunction = isNativeFunction;
|
13 | exports.getOwnKeys = getOwnKeys;
|
14 | exports.shallowStringsEqual = shallowStringsEqual;
|
15 | exports.deepPrototypeUpdate = deepPrototypeUpdate;
|
16 | exports.safeDefineProperty = safeDefineProperty;
|
17 |
|
18 | var _config = require('./config');
|
19 |
|
20 | var _config2 = _interopRequireDefault(_config);
|
21 |
|
22 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23 |
|
24 | function getDisplayName(Component) {
|
25 | var displayName = Component.displayName || Component.name;
|
26 | return displayName && displayName !== 'ReactComponent' ? displayName : 'Unknown';
|
27 | }
|
28 |
|
29 | var reactLifeCycleMountMethods = exports.reactLifeCycleMountMethods = ['componentWillMount', 'componentDidMount'];
|
30 |
|
31 | function isReactClass(Component) {
|
32 | return Component.prototype && (Component.prototype.isReactComponent || Component.prototype.componentWillMount || Component.prototype.componentWillUnmount || Component.prototype.componentDidMount || Component.prototype.componentDidUnmount || Component.prototype.render);
|
33 | }
|
34 |
|
35 | function safeReactConstructor(Component, lastInstance) {
|
36 | try {
|
37 | if (lastInstance) {
|
38 | return new Component(lastInstance.props, lastInstance.context);
|
39 | }
|
40 | return new Component({}, {});
|
41 | } catch (e) {
|
42 |
|
43 | }
|
44 | return null;
|
45 | }
|
46 |
|
47 | function isNativeFunction(fn) {
|
48 | return typeof fn === 'function' ? fn.toString().indexOf('[native code]') > 0 : false;
|
49 | }
|
50 |
|
51 | var identity = exports.identity = function identity(a) {
|
52 | return a;
|
53 | };
|
54 |
|
55 | var doesSupportClasses = exports.doesSupportClasses = function () {
|
56 | try {
|
57 | eval('class Test {}');
|
58 | return true;
|
59 | } catch (e) {
|
60 | return false;
|
61 | }
|
62 | }();
|
63 |
|
64 | var ES6ProxyComponentFactory = doesSupportClasses && eval('\n(function(InitialParent, postConstructionAction) {\n return class ProxyComponent extends InitialParent {\n constructor(props, context) {\n super(props, context)\n postConstructionAction.call(this)\n }\n }\n})\n');
|
65 |
|
66 | var ES5ProxyComponentFactory = function ES5ProxyComponentFactory(InitialParent, postConstructionAction) {
|
67 | function ProxyComponent(props, context) {
|
68 | InitialParent.call(this, props, context);
|
69 | postConstructionAction.call(this);
|
70 | }
|
71 | ProxyComponent.prototype = Object.create(InitialParent.prototype);
|
72 | Object.setPrototypeOf(ProxyComponent, InitialParent);
|
73 | return ProxyComponent;
|
74 | };
|
75 |
|
76 | var isReactComponentInstance = exports.isReactComponentInstance = function isReactComponentInstance(el) {
|
77 | return el && (typeof el === 'undefined' ? 'undefined' : _typeof(el)) === 'object' && !el.type && el.render;
|
78 | };
|
79 |
|
80 | var proxyClassCreator = exports.proxyClassCreator = doesSupportClasses ? ES6ProxyComponentFactory : ES5ProxyComponentFactory;
|
81 |
|
82 | function getOwnKeys(target) {
|
83 | return [].concat(Object.getOwnPropertyNames(target), Object.getOwnPropertySymbols(target));
|
84 | }
|
85 |
|
86 | function shallowStringsEqual(a, b) {
|
87 | for (var key in a) {
|
88 | if (String(a[key]) !== String(b[key])) {
|
89 | return false;
|
90 | }
|
91 | }
|
92 | return true;
|
93 | }
|
94 |
|
95 | function deepPrototypeUpdate(dest, source) {
|
96 | var deepDest = Object.getPrototypeOf(dest);
|
97 | var deepSrc = Object.getPrototypeOf(source);
|
98 | if (deepDest && deepSrc && deepSrc !== deepDest) {
|
99 | deepPrototypeUpdate(deepDest, deepSrc);
|
100 | }
|
101 | if (source.prototype && source.prototype !== dest.prototype) {
|
102 | dest.prototype = source.prototype;
|
103 | }
|
104 | }
|
105 |
|
106 | function safeDefineProperty(target, key, props) {
|
107 | try {
|
108 | Object.defineProperty(target, key, props);
|
109 | } catch (e) {
|
110 | _config2.default.logger.warn('Error while wrapping', key, ' -> ', e);
|
111 | }
|
112 | } |
\ | No newline at end of file |