react 0.11.2 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/dist/JSXTransformer.js +2714 -7859
  2. package/dist/react-with-addons.js +3139 -3593
  3. package/dist/react-with-addons.min.js +11 -17
  4. package/dist/react.js +2940 -3308
  5. package/dist/react.min.js +11 -16
  6. package/lib/AutoFocusMixin.js +5 -12
  7. package/lib/BeforeInputEventPlugin.js +12 -14
  8. package/lib/CSSCore.js +6 -13
  9. package/lib/CSSProperty.js +10 -14
  10. package/lib/CSSPropertyOperations.js +46 -12
  11. package/lib/CallbackQueue.js +7 -14
  12. package/lib/ChangeEventPlugin.js +5 -12
  13. package/lib/ClientReactRootIndex.js +5 -12
  14. package/lib/CompositionEventPlugin.js +5 -12
  15. package/lib/DOMChildrenOperations.js +8 -15
  16. package/lib/DOMProperty.js +16 -19
  17. package/lib/DOMPropertyOperations.js +14 -14
  18. package/lib/Danger.js +12 -17
  19. package/lib/DefaultEventPluginOrder.js +5 -12
  20. package/lib/EnterLeaveEventPlugin.js +5 -12
  21. package/lib/EventConstants.js +5 -12
  22. package/lib/EventListener.js +14 -0
  23. package/lib/EventPluginHub.js +8 -26
  24. package/lib/EventPluginRegistry.js +5 -12
  25. package/lib/EventPluginUtils.js +5 -12
  26. package/lib/EventPropagators.js +12 -17
  27. package/lib/ExecutionEnvironment.js +5 -12
  28. package/lib/HTMLDOMPropertyConfig.js +16 -15
  29. package/lib/LinkedStateMixin.js +5 -12
  30. package/lib/LinkedValueUtils.js +5 -12
  31. package/lib/LocalEventTrapMixin.js +8 -14
  32. package/lib/MobileSafariClickEventPlugin.js +5 -12
  33. package/lib/Object.assign.js +45 -0
  34. package/lib/PooledClass.js +5 -12
  35. package/lib/React.js +87 -54
  36. package/lib/ReactBrowserComponentMixin.js +5 -12
  37. package/lib/ReactBrowserEventEmitter.js +7 -14
  38. package/lib/ReactCSSTransitionGroup.js +15 -17
  39. package/lib/ReactCSSTransitionGroupChild.js +9 -13
  40. package/lib/ReactChildren.js +5 -12
  41. package/lib/ReactComponent.js +61 -68
  42. package/lib/ReactComponentBrowserEnvironment.js +5 -12
  43. package/lib/ReactComponentWithPureRenderMixin.js +5 -12
  44. package/lib/ReactCompositeComponent.js +191 -180
  45. package/lib/ReactContext.js +8 -15
  46. package/lib/ReactCurrentOwner.js +5 -12
  47. package/lib/ReactDOM.js +145 -177
  48. package/lib/ReactDOMButton.js +8 -14
  49. package/lib/ReactDOMComponent.js +103 -38
  50. package/lib/ReactDOMForm.js +9 -15
  51. package/lib/ReactDOMIDOperations.js +5 -12
  52. package/lib/ReactDOMImg.js +8 -14
  53. package/lib/ReactDOMInput.js +30 -38
  54. package/lib/ReactDOMOption.js +8 -14
  55. package/lib/ReactDOMSelect.js +25 -24
  56. package/lib/ReactDOMSelection.js +11 -18
  57. package/lib/ReactDOMTextarea.js +19 -24
  58. package/lib/ReactDefaultBatchingStrategy.js +14 -18
  59. package/lib/ReactDefaultInjection.js +23 -26
  60. package/lib/ReactDefaultPerf.js +14 -17
  61. package/lib/ReactDefaultPerfAnalysis.js +18 -17
  62. package/lib/ReactElement.js +242 -0
  63. package/lib/{ReactDescriptorValidator.js → ReactElementValidator.js} +51 -56
  64. package/lib/ReactEmptyComponent.js +8 -13
  65. package/lib/ReactErrorUtils.js +5 -12
  66. package/lib/ReactEventEmitterMixin.js +5 -12
  67. package/lib/ReactEventListener.js +7 -14
  68. package/lib/ReactInjection.js +7 -14
  69. package/lib/ReactInputSelection.js +5 -12
  70. package/lib/ReactInstanceHandles.js +5 -12
  71. package/lib/ReactLegacyElement.js +243 -0
  72. package/lib/ReactLink.js +5 -12
  73. package/lib/ReactMarkupChecksum.js +5 -12
  74. package/lib/ReactMount.js +45 -32
  75. package/lib/ReactMultiChild.js +14 -18
  76. package/lib/ReactMultiChildUpdateTypes.js +5 -12
  77. package/lib/ReactNativeComponent.js +69 -0
  78. package/lib/ReactOwner.js +5 -12
  79. package/lib/ReactPerf.js +8 -13
  80. package/lib/ReactPropTransferer.js +34 -33
  81. package/lib/ReactPropTypeLocationNames.js +5 -12
  82. package/lib/ReactPropTypeLocations.js +5 -12
  83. package/lib/ReactPropTypes.js +38 -29
  84. package/lib/ReactPutListenerQueue.js +7 -14
  85. package/lib/ReactReconcileTransaction.js +7 -15
  86. package/lib/ReactRootIndex.js +5 -12
  87. package/lib/ReactServerRendering.js +21 -34
  88. package/lib/ReactServerRenderingTransaction.js +11 -15
  89. package/lib/ReactStateSetters.js +5 -12
  90. package/lib/ReactTestUtils.js +31 -33
  91. package/lib/ReactTextComponent.js +18 -21
  92. package/lib/ReactTransitionChildMapping.js +6 -13
  93. package/lib/ReactTransitionEvents.js +5 -12
  94. package/lib/ReactTransitionGroup.js +14 -17
  95. package/lib/ReactUpdates.js +43 -22
  96. package/lib/ReactWithAddons.js +7 -13
  97. package/lib/SVGDOMPropertyConfig.js +5 -12
  98. package/lib/SelectEventPlugin.js +13 -20
  99. package/lib/ServerReactRootIndex.js +5 -12
  100. package/lib/SimpleEventPlugin.js +20 -15
  101. package/lib/SyntheticClipboardEvent.js +5 -12
  102. package/lib/SyntheticCompositionEvent.js +5 -12
  103. package/lib/SyntheticDragEvent.js +5 -12
  104. package/lib/SyntheticEvent.js +9 -17
  105. package/lib/SyntheticFocusEvent.js +5 -12
  106. package/lib/SyntheticInputEvent.js +4 -11
  107. package/lib/SyntheticKeyboardEvent.js +17 -19
  108. package/lib/SyntheticMouseEvent.js +5 -12
  109. package/lib/SyntheticTouchEvent.js +5 -12
  110. package/lib/SyntheticUIEvent.js +5 -12
  111. package/lib/SyntheticWheelEvent.js +5 -12
  112. package/lib/Transaction.js +5 -12
  113. package/lib/ViewportMetrics.js +5 -12
  114. package/lib/accumulateInto.js +62 -0
  115. package/lib/adler32.js +6 -13
  116. package/lib/camelize.js +30 -0
  117. package/lib/camelizeStyleName.js +40 -0
  118. package/lib/cloneWithProps.js +9 -15
  119. package/lib/containsNode.js +5 -12
  120. package/lib/copyProperties.js +12 -12
  121. package/lib/createArrayFrom.js +5 -12
  122. package/lib/createFullPageComponent.js +12 -18
  123. package/lib/createNodesFromMarkup.js +5 -12
  124. package/lib/cx.js +5 -12
  125. package/lib/dangerousStyleValue.js +5 -12
  126. package/lib/deprecated.js +47 -0
  127. package/lib/emptyFunction.js +11 -22
  128. package/lib/emptyObject.js +5 -12
  129. package/lib/escapeTextForBrowser.js +5 -12
  130. package/lib/flattenChildren.js +19 -13
  131. package/lib/focusNode.js +10 -16
  132. package/lib/forEachAccumulated.js +5 -12
  133. package/lib/getActiveElement.js +5 -12
  134. package/lib/getEventCharCode.js +50 -0
  135. package/lib/getEventKey.js +9 -21
  136. package/lib/getEventModifierState.js +4 -11
  137. package/lib/getEventTarget.js +5 -12
  138. package/lib/getMarkupWrap.js +5 -12
  139. package/lib/getNodeForCharacterOffset.js +5 -12
  140. package/lib/getReactRootElementInContainer.js +5 -12
  141. package/lib/getTextContentAccessor.js +5 -12
  142. package/lib/getUnboundedScrollPosition.js +5 -12
  143. package/lib/hyphenate.js +5 -12
  144. package/lib/hyphenateStyleName.js +8 -15
  145. package/lib/instantiateReactComponent.js +90 -42
  146. package/lib/invariant.js +5 -12
  147. package/lib/isEventSupported.js +5 -12
  148. package/lib/isNode.js +5 -12
  149. package/lib/isTextInputElement.js +5 -12
  150. package/lib/isTextNode.js +5 -12
  151. package/lib/joinClasses.js +8 -13
  152. package/lib/keyMirror.js +5 -12
  153. package/lib/keyOf.js +5 -12
  154. package/lib/mapObject.js +35 -36
  155. package/lib/memoizeStringOnly.js +5 -12
  156. package/lib/merge.js +14 -17
  157. package/lib/mergeInto.js +13 -35
  158. package/lib/monitorCodeUse.js +5 -12
  159. package/lib/onlyChild.js +8 -15
  160. package/lib/performance.js +5 -12
  161. package/lib/performanceNow.js +5 -12
  162. package/lib/setInnerHTML.js +10 -19
  163. package/lib/shallowEqual.js +6 -13
  164. package/lib/shouldUpdateReactComponent.js +14 -22
  165. package/lib/toArray.js +5 -12
  166. package/lib/traverseAllChildren.js +34 -48
  167. package/lib/update.js +8 -15
  168. package/lib/warning.js +6 -13
  169. package/package.json +3 -8
  170. package/lib/ReactDescriptor.js +0 -251
  171. package/lib/accumulate.js +0 -54
  172. package/lib/mergeHelpers.js +0 -147
  173. package/lib/mixInto.js +0 -34
@@ -1,22 +1,15 @@
1
1
  /**
2
- * Copyright 2013-2014 Facebook, Inc.
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
15
8
  *
16
9
  * @providesModule ReactDefaultPerfAnalysis
17
10
  */
18
11
 
19
- var merge = require("./merge");
12
+ var assign = require("./Object.assign");
20
13
 
21
14
  // Don't try to save users less than 1.2ms (a number I made up)
22
15
  var DONT_CARE_THRESHOLD = 1.2;
@@ -71,7 +64,11 @@ function getExclusiveSummary(measurements) {
71
64
 
72
65
  for (var i = 0; i < measurements.length; i++) {
73
66
  var measurement = measurements[i];
74
- var allIDs = merge(measurement.exclusive, measurement.inclusive);
67
+ var allIDs = assign(
68
+ {},
69
+ measurement.exclusive,
70
+ measurement.inclusive
71
+ );
75
72
 
76
73
  for (var id in allIDs) {
77
74
  displayName = measurement.displayNames[id].current;
@@ -119,7 +116,11 @@ function getInclusiveSummary(measurements, onlyClean) {
119
116
 
120
117
  for (var i = 0; i < measurements.length; i++) {
121
118
  var measurement = measurements[i];
122
- var allIDs = merge(measurement.exclusive, measurement.inclusive);
119
+ var allIDs = assign(
120
+ {},
121
+ measurement.exclusive,
122
+ measurement.inclusive
123
+ );
123
124
  var cleanComponents;
124
125
 
125
126
  if (onlyClean) {
@@ -174,11 +175,11 @@ function getUnchangedComponents(measurement) {
174
175
  // the amount of time it took to render the entire subtree.
175
176
  var cleanComponents = {};
176
177
  var dirtyLeafIDs = Object.keys(measurement.writes);
177
- var allIDs = merge(measurement.exclusive, measurement.inclusive);
178
+ var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
178
179
 
179
180
  for (var id in allIDs) {
180
181
  var isDirty = false;
181
- // For each component that rendered, see if a component that triggerd
182
+ // For each component that rendered, see if a component that triggered
182
183
  // a DOM op is in its subtree.
183
184
  for (var i = 0; i < dirtyLeafIDs.length; i++) {
184
185
  if (dirtyLeafIDs[i].indexOf(id) === 0) {
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Copyright 2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule ReactElement
10
+ */
11
+
12
+ "use strict";
13
+
14
+ var ReactContext = require("./ReactContext");
15
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
16
+
17
+ var warning = require("./warning");
18
+
19
+ var RESERVED_PROPS = {
20
+ key: true,
21
+ ref: true
22
+ };
23
+
24
+ /**
25
+ * Warn for mutations.
26
+ *
27
+ * @internal
28
+ * @param {object} object
29
+ * @param {string} key
30
+ */
31
+ function defineWarningProperty(object, key) {
32
+ Object.defineProperty(object, key, {
33
+
34
+ configurable: false,
35
+ enumerable: true,
36
+
37
+ get: function() {
38
+ if (!this._store) {
39
+ return null;
40
+ }
41
+ return this._store[key];
42
+ },
43
+
44
+ set: function(value) {
45
+ ("production" !== process.env.NODE_ENV ? warning(
46
+ false,
47
+ 'Don\'t set the ' + key + ' property of the component. ' +
48
+ 'Mutate the existing props object instead.'
49
+ ) : null);
50
+ this._store[key] = value;
51
+ }
52
+
53
+ });
54
+ }
55
+
56
+ /**
57
+ * This is updated to true if the membrane is successfully created.
58
+ */
59
+ var useMutationMembrane = false;
60
+
61
+ /**
62
+ * Warn for mutations.
63
+ *
64
+ * @internal
65
+ * @param {object} element
66
+ */
67
+ function defineMutationMembrane(prototype) {
68
+ try {
69
+ var pseudoFrozenProperties = {
70
+ props: true
71
+ };
72
+ for (var key in pseudoFrozenProperties) {
73
+ defineWarningProperty(prototype, key);
74
+ }
75
+ useMutationMembrane = true;
76
+ } catch (x) {
77
+ // IE will fail on defineProperty
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Base constructor for all React elements. This is only used to make this
83
+ * work with a dynamic instanceof check. Nothing should live on this prototype.
84
+ *
85
+ * @param {*} type
86
+ * @param {string|object} ref
87
+ * @param {*} key
88
+ * @param {*} props
89
+ * @internal
90
+ */
91
+ var ReactElement = function(type, key, ref, owner, context, props) {
92
+ // Built-in properties that belong on the element
93
+ this.type = type;
94
+ this.key = key;
95
+ this.ref = ref;
96
+
97
+ // Record the component responsible for creating this element.
98
+ this._owner = owner;
99
+
100
+ // TODO: Deprecate withContext, and then the context becomes accessible
101
+ // through the owner.
102
+ this._context = context;
103
+
104
+ if ("production" !== process.env.NODE_ENV) {
105
+ // The validation flag and props are currently mutative. We put them on
106
+ // an external backing store so that we can freeze the whole object.
107
+ // This can be replaced with a WeakMap once they are implemented in
108
+ // commonly used development environments.
109
+ this._store = { validated: false, props: props };
110
+
111
+ // We're not allowed to set props directly on the object so we early
112
+ // return and rely on the prototype membrane to forward to the backing
113
+ // store.
114
+ if (useMutationMembrane) {
115
+ Object.freeze(this);
116
+ return;
117
+ }
118
+ }
119
+
120
+ this.props = props;
121
+ };
122
+
123
+ // We intentionally don't expose the function on the constructor property.
124
+ // ReactElement should be indistinguishable from a plain object.
125
+ ReactElement.prototype = {
126
+ _isReactElement: true
127
+ };
128
+
129
+ if ("production" !== process.env.NODE_ENV) {
130
+ defineMutationMembrane(ReactElement.prototype);
131
+ }
132
+
133
+ ReactElement.createElement = function(type, config, children) {
134
+ var propName;
135
+
136
+ // Reserved names are extracted
137
+ var props = {};
138
+
139
+ var key = null;
140
+ var ref = null;
141
+
142
+ if (config != null) {
143
+ ref = config.ref === undefined ? null : config.ref;
144
+ if ("production" !== process.env.NODE_ENV) {
145
+ ("production" !== process.env.NODE_ENV ? warning(
146
+ config.key !== null,
147
+ 'createElement(...): Encountered component with a `key` of null. In ' +
148
+ 'a future version, this will be treated as equivalent to the string ' +
149
+ '\'null\'; instead, provide an explicit key or use undefined.'
150
+ ) : null);
151
+ }
152
+ // TODO: Change this back to `config.key === undefined`
153
+ key = config.key == null ? null : '' + config.key;
154
+ // Remaining properties are added to a new props object
155
+ for (propName in config) {
156
+ if (config.hasOwnProperty(propName) &&
157
+ !RESERVED_PROPS.hasOwnProperty(propName)) {
158
+ props[propName] = config[propName];
159
+ }
160
+ }
161
+ }
162
+
163
+ // Children can be more than one argument, and those are transferred onto
164
+ // the newly allocated props object.
165
+ var childrenLength = arguments.length - 2;
166
+ if (childrenLength === 1) {
167
+ props.children = children;
168
+ } else if (childrenLength > 1) {
169
+ var childArray = Array(childrenLength);
170
+ for (var i = 0; i < childrenLength; i++) {
171
+ childArray[i] = arguments[i + 2];
172
+ }
173
+ props.children = childArray;
174
+ }
175
+
176
+ // Resolve default props
177
+ if (type && type.defaultProps) {
178
+ var defaultProps = type.defaultProps;
179
+ for (propName in defaultProps) {
180
+ if (typeof props[propName] === 'undefined') {
181
+ props[propName] = defaultProps[propName];
182
+ }
183
+ }
184
+ }
185
+
186
+ return new ReactElement(
187
+ type,
188
+ key,
189
+ ref,
190
+ ReactCurrentOwner.current,
191
+ ReactContext.current,
192
+ props
193
+ );
194
+ };
195
+
196
+ ReactElement.createFactory = function(type) {
197
+ var factory = ReactElement.createElement.bind(null, type);
198
+ // Expose the type on the factory and the prototype so that it can be
199
+ // easily accessed on elements. E.g. <Foo />.type === Foo.type.
200
+ // This should not be named `constructor` since this may not be the function
201
+ // that created the element, and it may not even be a constructor.
202
+ factory.type = type;
203
+ return factory;
204
+ };
205
+
206
+ ReactElement.cloneAndReplaceProps = function(oldElement, newProps) {
207
+ var newElement = new ReactElement(
208
+ oldElement.type,
209
+ oldElement.key,
210
+ oldElement.ref,
211
+ oldElement._owner,
212
+ oldElement._context,
213
+ newProps
214
+ );
215
+
216
+ if ("production" !== process.env.NODE_ENV) {
217
+ // If the key on the original is valid, then the clone is valid
218
+ newElement._store.validated = oldElement._store.validated;
219
+ }
220
+ return newElement;
221
+ };
222
+
223
+ /**
224
+ * @param {?object} object
225
+ * @return {boolean} True if `object` is a valid component.
226
+ * @final
227
+ */
228
+ ReactElement.isValidElement = function(object) {
229
+ // ReactTestUtils is often used outside of beforeEach where as React is
230
+ // within it. This leads to two different instances of React on the same
231
+ // page. To identify a element from a different React instance we use
232
+ // a flag instead of an instanceof check.
233
+ var isElement = !!(object && object._isReactElement);
234
+ // if (isElement && !(object instanceof ReactElement)) {
235
+ // This is an indicator that you're using multiple versions of React at the
236
+ // same time. This will screw with ownership and stuff. Fix it, please.
237
+ // TODO: We could possibly warn here.
238
+ // }
239
+ return isElement;
240
+ };
241
+
242
+ module.exports = ReactElement;
@@ -1,35 +1,29 @@
1
1
  /**
2
- * Copyright 2014 Facebook, Inc.
2
+ * Copyright 2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
7
8
  *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule ReactDescriptorValidator
9
+ * @providesModule ReactElementValidator
17
10
  */
18
11
 
19
12
  /**
20
- * ReactDescriptorValidator provides a wrapper around a descriptor factory
21
- * which validates the props passed to the descriptor. This is intended to be
13
+ * ReactElementValidator provides a wrapper around a element factory
14
+ * which validates the props passed to the element. This is intended to be
22
15
  * used only in DEV and could be replaced by a static type checker for languages
23
16
  * that support it.
24
17
  */
25
18
 
26
19
  "use strict";
27
20
 
28
- var ReactDescriptor = require("./ReactDescriptor");
21
+ var ReactElement = require("./ReactElement");
29
22
  var ReactPropTypeLocations = require("./ReactPropTypeLocations");
30
23
  var ReactCurrentOwner = require("./ReactCurrentOwner");
31
24
 
32
25
  var monitorCodeUse = require("./monitorCodeUse");
26
+ var warning = require("./warning");
33
27
 
34
28
  /**
35
29
  * Warn if there's no key explicitly set on dynamic arrays of children or
@@ -68,7 +62,7 @@ function getCurrentOwnerDisplayName() {
68
62
  * @param {*} parentType component's parent's type.
69
63
  */
70
64
  function validateExplicitKey(component, parentType) {
71
- if (component._store.validated || component.props.key != null) {
65
+ if (component._store.validated || component.key != null) {
72
66
  return;
73
67
  }
74
68
  component._store.validated = true;
@@ -174,11 +168,11 @@ function validateChildKeys(component, parentType) {
174
168
  if (Array.isArray(component)) {
175
169
  for (var i = 0; i < component.length; i++) {
176
170
  var child = component[i];
177
- if (ReactDescriptor.isValidDescriptor(child)) {
171
+ if (ReactElement.isValidElement(child)) {
178
172
  validateExplicitKey(child, parentType);
179
173
  }
180
174
  }
181
- } else if (ReactDescriptor.isValidDescriptor(component)) {
175
+ } else if (ReactElement.isValidElement(component)) {
182
176
  // This component was passed in a valid location.
183
177
  component._store.validated = true;
184
178
  } else if (component && typeof component === 'object') {
@@ -224,60 +218,61 @@ function checkPropTypes(componentName, propTypes, props, location) {
224
218
  }
225
219
  }
226
220
 
227
- var ReactDescriptorValidator = {
221
+ var ReactElementValidator = {
228
222
 
229
- /**
230
- * Wraps a descriptor factory function in another function which validates
231
- * the props and context of the descriptor and warns about any failed type
232
- * checks.
233
- *
234
- * @param {function} factory The original descriptor factory
235
- * @param {object?} propTypes A prop type definition set
236
- * @param {object?} contextTypes A context type definition set
237
- * @return {object} The component descriptor, which may be invalid.
238
- * @private
239
- */
240
- createFactory: function(factory, propTypes, contextTypes) {
241
- var validatedFactory = function(props, children) {
242
- var descriptor = factory.apply(this, arguments);
223
+ createElement: function(type, props, children) {
224
+ // We warn in this case but don't throw. We expect the element creation to
225
+ // succeed and there will likely be errors in render.
226
+ ("production" !== process.env.NODE_ENV ? warning(
227
+ type != null,
228
+ 'React.createElement: type should not be null or undefined. It should ' +
229
+ 'be a string (for DOM elements) or a ReactClass (for composite ' +
230
+ 'components).'
231
+ ) : null);
243
232
 
244
- for (var i = 1; i < arguments.length; i++) {
245
- validateChildKeys(arguments[i], descriptor.type);
246
- }
233
+ var element = ReactElement.createElement.apply(this, arguments);
234
+
235
+ // The result can be nullish if a mock or a custom function is used.
236
+ // TODO: Drop this when these are no longer allowed as the type argument.
237
+ if (element == null) {
238
+ return element;
239
+ }
247
240
 
248
- var name = descriptor.type.displayName;
249
- if (propTypes) {
241
+ for (var i = 2; i < arguments.length; i++) {
242
+ validateChildKeys(arguments[i], type);
243
+ }
244
+
245
+ if (type) {
246
+ var name = type.displayName;
247
+ if (type.propTypes) {
250
248
  checkPropTypes(
251
249
  name,
252
- propTypes,
253
- descriptor.props,
250
+ type.propTypes,
251
+ element.props,
254
252
  ReactPropTypeLocations.prop
255
253
  );
256
254
  }
257
- if (contextTypes) {
255
+ if (type.contextTypes) {
258
256
  checkPropTypes(
259
257
  name,
260
- contextTypes,
261
- descriptor._context,
258
+ type.contextTypes,
259
+ element._context,
262
260
  ReactPropTypeLocations.context
263
261
  );
264
262
  }
265
- return descriptor;
266
- };
267
-
268
- validatedFactory.prototype = factory.prototype;
269
- validatedFactory.type = factory.type;
270
-
271
- // Copy static properties
272
- for (var key in factory) {
273
- if (factory.hasOwnProperty(key)) {
274
- validatedFactory[key] = factory[key];
275
- }
276
263
  }
264
+ return element;
265
+ },
277
266
 
267
+ createFactory: function(type) {
268
+ var validatedFactory = ReactElementValidator.createElement.bind(
269
+ null,
270
+ type
271
+ );
272
+ validatedFactory.type = type;
278
273
  return validatedFactory;
279
274
  }
280
275
 
281
276
  };
282
277
 
283
- module.exports = ReactDescriptorValidator;
278
+ module.exports = ReactElementValidator;