1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var _prodInvariant = require('./reactProdInvariant'),
|
14 | _assign = require('object-assign');
|
15 |
|
16 | var ReactCompositeComponent = require('./ReactCompositeComponent');
|
17 | var ReactEmptyComponent = require('./ReactEmptyComponent');
|
18 | var ReactHostComponent = require('./ReactHostComponent');
|
19 |
|
20 | var getNextDebugID = require('react/lib/getNextDebugID');
|
21 | var invariant = require('fbjs/lib/invariant');
|
22 | var warning = require('fbjs/lib/warning');
|
23 |
|
24 |
|
25 | var ReactCompositeComponentWrapper = function (element) {
|
26 | this.construct(element);
|
27 | };
|
28 |
|
29 | function getDeclarationErrorAddendum(owner) {
|
30 | if (owner) {
|
31 | var name = owner.getName();
|
32 | if (name) {
|
33 | return ' Check the render method of `' + name + '`.';
|
34 | }
|
35 | }
|
36 | return '';
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function isInternalComponentType(type) {
|
47 | return typeof type === 'function' && typeof type.prototype !== 'undefined' && typeof type.prototype.mountComponent === 'function' && typeof type.prototype.receiveComponent === 'function';
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | function instantiateReactComponent(node, shouldHaveDebugID) {
|
59 | var instance;
|
60 |
|
61 | if (node === null || node === false) {
|
62 | instance = ReactEmptyComponent.create(instantiateReactComponent);
|
63 | } else if (typeof node === 'object') {
|
64 | var element = node;
|
65 | var type = element.type;
|
66 | if (typeof type !== 'function' && typeof type !== 'string') {
|
67 | var info = '';
|
68 | if (process.env.NODE_ENV !== 'production') {
|
69 | if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
|
70 | info += ' You likely forgot to export your component from the file ' + "it's defined in.";
|
71 | }
|
72 | }
|
73 | info += getDeclarationErrorAddendum(element._owner);
|
74 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s', type == null ? type : typeof type, info) : _prodInvariant('130', type == null ? type : typeof type, info) : void 0;
|
75 | }
|
76 |
|
77 |
|
78 | if (typeof element.type === 'string') {
|
79 | instance = ReactHostComponent.createInternalComponent(element);
|
80 | } else if (isInternalComponentType(element.type)) {
|
81 |
|
82 |
|
83 |
|
84 | instance = new element.type(element);
|
85 |
|
86 |
|
87 | if (!instance.getHostNode) {
|
88 | instance.getHostNode = instance.getNativeNode;
|
89 | }
|
90 | } else {
|
91 | instance = new ReactCompositeComponentWrapper(element);
|
92 | }
|
93 | } else if (typeof node === 'string' || typeof node === 'number') {
|
94 | instance = ReactHostComponent.createInstanceForText(node);
|
95 | } else {
|
96 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Encountered invalid React node of type %s', typeof node) : _prodInvariant('131', typeof node) : void 0;
|
97 | }
|
98 |
|
99 | if (process.env.NODE_ENV !== 'production') {
|
100 | process.env.NODE_ENV !== 'production' ? warning(typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && typeof instance.getHostNode === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.') : void 0;
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | instance._mountIndex = 0;
|
107 | instance._mountImage = null;
|
108 |
|
109 | if (process.env.NODE_ENV !== 'production') {
|
110 | instance._debugID = shouldHaveDebugID ? getNextDebugID() : 0;
|
111 | }
|
112 |
|
113 |
|
114 |
|
115 | if (process.env.NODE_ENV !== 'production') {
|
116 | if (Object.preventExtensions) {
|
117 | Object.preventExtensions(instance);
|
118 | }
|
119 | }
|
120 |
|
121 | return instance;
|
122 | }
|
123 |
|
124 | _assign(ReactCompositeComponentWrapper.prototype, ReactCompositeComponent, {
|
125 | _instantiateReactComponent: instantiateReactComponent
|
126 | });
|
127 |
|
128 | module.exports = instantiateReactComponent; |
\ | No newline at end of file |