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