react 0.13.3 → 0.14.0-alpha1
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.
- package/addons.js +7 -0
- package/addons/CSSTransitionGroup.js +1 -0
- package/addons/LinkedStateMixin.js +1 -0
- package/addons/Perf.js +1 -0
- package/addons/PureRenderMixin.js +1 -0
- package/addons/TestUtils.js +1 -0
- package/addons/TransitionGroup.js +1 -0
- package/addons/batchedUpdates.js +1 -0
- package/addons/cloneWithProps.js +1 -0
- package/addons/createFragment.js +1 -0
- package/addons/renderSubtreeIntoContainer.js +1 -0
- package/addons/shallowCompare.js +1 -0
- package/addons/update.js +1 -0
- package/dist/JSXTransformer.js +3355 -1685
- package/dist/react-with-addons.js +3092 -5145
- package/dist/react-with-addons.min.js +6 -8
- package/dist/react.js +2772 -4594
- package/dist/react.min.js +5 -6
- package/lib/AutoFocusMixin.js +4 -3
- package/lib/BeforeInputEventPlugin.js +30 -118
- package/lib/CSSCore.js +12 -23
- package/lib/CSSProperty.js +4 -3
- package/lib/CSSPropertyOperations.js +14 -30
- package/lib/CallbackQueue.js +7 -10
- package/lib/ChangeEventPlugin.js +24 -88
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +13 -33
- package/lib/DOMProperty.js +41 -65
- package/lib/DOMPropertyOperations.js +30 -51
- package/lib/Danger.js +19 -60
- package/lib/DefaultEventPluginOrder.js +2 -12
- package/lib/EnterLeaveEventPlugin.js +11 -33
- package/lib/EventConstants.js +2 -2
- package/lib/EventListener.js +11 -13
- package/lib/EventPluginHub.js +44 -47
- package/lib/EventPluginRegistry.js +18 -74
- package/lib/EventPluginUtils.js +27 -38
- package/lib/EventPropagators.js +23 -26
- package/lib/ExecutionEnvironment.js +4 -8
- package/lib/FallbackCompositionState.js +3 -3
- package/lib/HTMLDOMPropertyConfig.js +5 -17
- package/lib/LinkedStateMixin.js +3 -6
- package/lib/LinkedValueUtils.js +34 -64
- package/lib/LocalEventTrapMixin.js +9 -16
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +8 -11
- package/lib/React.js +20 -38
- package/lib/ReactBrowserComponentMixin.js +9 -2
- package/lib/ReactBrowserEventEmitter.js +26 -82
- package/lib/ReactCSSTransitionGroup.js +13 -24
- package/lib/ReactCSSTransitionGroupChild.js +18 -28
- package/lib/ReactChildReconciler.js +11 -19
- package/lib/ReactChildren.js +7 -16
- package/lib/ReactClass.js +78 -231
- package/lib/ReactComponent.js +17 -51
- package/lib/ReactComponentBrowserEnvironment.js +4 -6
- package/lib/ReactComponentEnvironment.js +6 -12
- package/lib/ReactComponentWithPureRenderMixin.js +4 -5
- package/lib/ReactCompositeComponent.js +83 -318
- package/lib/ReactContext.js +2 -44
- package/lib/ReactCurrentOwner.js +1 -3
- package/lib/ReactDOM.js +3 -2
- package/lib/ReactDOMButton.js +3 -4
- package/lib/ReactDOMComponent.js +182 -148
- package/lib/ReactDOMForm.js +3 -3
- package/lib/ReactDOMIDOperations.js +11 -20
- package/lib/ReactDOMIframe.js +3 -3
- package/lib/ReactDOMImg.js +3 -3
- package/lib/ReactDOMInput.js +22 -35
- package/lib/ReactDOMOption.js +52 -10
- package/lib/ReactDOMSelect.js +50 -28
- package/lib/ReactDOMSelection.js +5 -20
- package/lib/ReactDOMTextComponent.js +17 -18
- package/lib/ReactDOMTextarea.js +15 -27
- package/lib/ReactDefaultBatchingStrategy.js +9 -13
- package/lib/ReactDefaultInjection.js +21 -40
- package/lib/ReactDefaultPerf.js +36 -69
- package/lib/ReactDefaultPerfAnalysis.js +8 -14
- package/lib/ReactElement.js +35 -72
- package/lib/ReactElementValidator.js +51 -110
- package/lib/ReactEmptyComponent.js +7 -11
- package/lib/ReactErrorUtils.js +2 -2
- package/lib/ReactEventEmitterMixin.js +3 -12
- package/lib/ReactEventListener.js +16 -38
- package/lib/ReactFragment.js +23 -54
- package/lib/ReactInjection.js +1 -1
- package/lib/ReactInputSelection.js +11 -21
- package/lib/ReactInstanceHandles.js +27 -57
- package/lib/ReactInstanceMap.js +5 -5
- package/lib/ReactLifeCycle.js +1 -1
- package/lib/ReactLink.js +2 -4
- package/lib/ReactMarkupChecksum.js +5 -10
- package/lib/ReactMount.js +136 -260
- package/lib/ReactMultiChild.js +19 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +7 -11
- package/lib/ReactOwner.js +7 -24
- package/lib/ReactPerf.js +8 -12
- package/lib/ReactPropTransferer.js +4 -4
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +13 -46
- package/lib/ReactReconcileTransaction.js +9 -34
- package/lib/ReactReconciler.js +9 -19
- package/lib/ReactRef.js +5 -8
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +7 -15
- package/lib/ReactServerRenderingTransaction.js +7 -32
- package/lib/ReactStateSetters.js +6 -6
- package/lib/ReactTestUtils.js +89 -165
- package/lib/ReactTransitionChildMapping.js +5 -7
- package/lib/ReactTransitionEvents.js +5 -5
- package/lib/ReactTransitionGroup.js +30 -52
- package/lib/ReactUpdateQueue.js +27 -90
- package/lib/ReactUpdates.js +27 -79
- package/lib/ReactWithAddons.js +7 -6
- package/lib/SVGDOMPropertyConfig.js +39 -2
- package/lib/SelectEventPlugin.js +28 -29
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +136 -128
- package/lib/SyntheticClipboardEvent.js +3 -7
- package/lib/SyntheticCompositionEvent.js +3 -9
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +8 -10
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +3 -9
- package/lib/SyntheticKeyboardEvent.js +4 -4
- package/lib/SyntheticMouseEvent.js +8 -14
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +3 -3
- package/lib/SyntheticWheelEvent.js +11 -15
- package/lib/Transaction.js +12 -24
- package/lib/ViewportMetrics.js +2 -2
- package/lib/accumulateInto.js +2 -5
- package/lib/adler32.js +2 -2
- package/lib/camelize.js +4 -2
- package/lib/camelizeStyleName.js +2 -2
- package/lib/cloneWithProps.js +5 -11
- package/lib/containsNode.js +29 -16
- package/lib/createArrayFromMixed.js +17 -16
- package/lib/createFullPageComponent.js +4 -11
- package/lib/createNodesFromMarkup.js +6 -8
- package/lib/dangerousStyleValue.js +2 -3
- package/lib/emptyFunction.js +10 -4
- package/lib/emptyObject.js +1 -1
- package/lib/escapeTextContentForBrowser.js +1 -1
- package/lib/findDOMNode.js +5 -24
- package/lib/flattenChildren.js +4 -10
- package/lib/focusNode.js +2 -3
- package/lib/forEachAccumulated.js +2 -2
- package/lib/getActiveElement.js +4 -2
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +2 -4
- package/lib/getMarkupWrap.js +5 -5
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getTextContentAccessor.js +2 -4
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +3 -1
- package/lib/hyphenateStyleName.js +2 -2
- package/lib/instantiateReactComponent.js +14 -38
- package/lib/invariant.js +8 -12
- package/lib/isEventSupported.js +7 -10
- package/lib/isNode.js +4 -6
- package/lib/isTextInputElement.js +2 -4
- package/lib/isTextNode.js +3 -1
- package/lib/joinClasses.js +2 -2
- package/lib/keyMirror.js +3 -6
- package/lib/keyOf.js +4 -3
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +2 -2
- package/lib/onlyChild.js +2 -5
- package/lib/performance.js +2 -5
- package/lib/performanceNow.js +3 -1
- package/lib/quoteAttributeValueForBrowser.js +1 -1
- package/lib/renderSubtreeIntoContainer.js +16 -0
- package/lib/setInnerHTML.js +11 -8
- package/lib/setTextContent.js +3 -3
- package/lib/shallowCompare.js +24 -0
- package/lib/shallowEqual.js +17 -11
- package/lib/shouldUpdateReactComponent.js +3 -64
- package/lib/toArray.js +8 -19
- package/lib/traverseAllChildren.js +19 -82
- package/lib/update.js +25 -85
- package/lib/validateDOMNesting.js +264 -0
- package/lib/warning.js +17 -15
- package/package.json +3 -3
- package/lib/MobileSafariClickEventPlugin.js +0 -56
- package/lib/ReactPutListenerQueue.js +0 -54
- package/lib/cx.js +0 -52
- package/lib/getReactRootElementInContainer.js +0 -33
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* @providesModule ReactDefaultPerfAnalysis
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
12
14
|
var assign = require("./Object.assign");
|
|
13
15
|
|
|
14
16
|
// Don't try to save users less than 1.2ms (a number I made up)
|
|
@@ -46,7 +48,7 @@ function getDOMSummary(measurements) {
|
|
|
46
48
|
var id;
|
|
47
49
|
|
|
48
50
|
for (id in measurement.writes) {
|
|
49
|
-
measurement.writes[id].forEach(function(write) {
|
|
51
|
+
measurement.writes[id].forEach(function (write) {
|
|
50
52
|
items.push({
|
|
51
53
|
id: id,
|
|
52
54
|
type: DOM_OPERATION_TYPES[write.type] || write.type,
|
|
@@ -64,11 +66,7 @@ function getExclusiveSummary(measurements) {
|
|
|
64
66
|
|
|
65
67
|
for (var i = 0; i < measurements.length; i++) {
|
|
66
68
|
var measurement = measurements[i];
|
|
67
|
-
var allIDs = assign(
|
|
68
|
-
{},
|
|
69
|
-
measurement.exclusive,
|
|
70
|
-
measurement.inclusive
|
|
71
|
-
);
|
|
69
|
+
var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
|
|
72
70
|
|
|
73
71
|
for (var id in allIDs) {
|
|
74
72
|
displayName = measurement.displayNames[id].current;
|
|
@@ -103,7 +101,7 @@ function getExclusiveSummary(measurements) {
|
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
arr.sort(function(a, b) {
|
|
104
|
+
arr.sort(function (a, b) {
|
|
107
105
|
return b.exclusive - a.exclusive;
|
|
108
106
|
});
|
|
109
107
|
|
|
@@ -116,11 +114,7 @@ function getInclusiveSummary(measurements, onlyClean) {
|
|
|
116
114
|
|
|
117
115
|
for (var i = 0; i < measurements.length; i++) {
|
|
118
116
|
var measurement = measurements[i];
|
|
119
|
-
var allIDs = assign(
|
|
120
|
-
{},
|
|
121
|
-
measurement.exclusive,
|
|
122
|
-
measurement.inclusive
|
|
123
|
-
);
|
|
117
|
+
var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
|
|
124
118
|
var cleanComponents;
|
|
125
119
|
|
|
126
120
|
if (onlyClean) {
|
|
@@ -162,7 +156,7 @@ function getInclusiveSummary(measurements, onlyClean) {
|
|
|
162
156
|
}
|
|
163
157
|
}
|
|
164
158
|
|
|
165
|
-
arr.sort(function(a, b) {
|
|
159
|
+
arr.sort(function (a, b) {
|
|
166
160
|
return b.time - a.time;
|
|
167
161
|
});
|
|
168
162
|
|
|
@@ -201,4 +195,4 @@ var ReactDefaultPerfAnalysis = {
|
|
|
201
195
|
getTotalTime: getTotalTime
|
|
202
196
|
};
|
|
203
197
|
|
|
204
|
-
module.exports = ReactDefaultPerfAnalysis;
|
|
198
|
+
module.exports = ReactDefaultPerfAnalysis;
|
package/lib/ReactElement.js
CHANGED
|
@@ -35,20 +35,15 @@ function defineWarningProperty(object, key) {
|
|
|
35
35
|
configurable: false,
|
|
36
36
|
enumerable: true,
|
|
37
37
|
|
|
38
|
-
get: function() {
|
|
38
|
+
get: function () {
|
|
39
39
|
if (!this._store) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
42
|
return this._store[key];
|
|
43
43
|
},
|
|
44
44
|
|
|
45
|
-
set: function(value) {
|
|
46
|
-
|
|
47
|
-
false,
|
|
48
|
-
'Don\'t set the %s property of the React element. Instead, ' +
|
|
49
|
-
'specify the correct value when initially creating the element.',
|
|
50
|
-
key
|
|
51
|
-
) : null);
|
|
45
|
+
set: function (value) {
|
|
46
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'Don\'t set the %s property of the React element. Instead, ' + 'specify the correct value when initially creating the element.', key) : null;
|
|
52
47
|
this._store[key] = value;
|
|
53
48
|
}
|
|
54
49
|
|
|
@@ -75,9 +70,7 @@ function defineMutationMembrane(prototype) {
|
|
|
75
70
|
defineWarningProperty(prototype, key);
|
|
76
71
|
}
|
|
77
72
|
useMutationMembrane = true;
|
|
78
|
-
} catch (x) {
|
|
79
|
-
// IE will fail on defineProperty
|
|
80
|
-
}
|
|
73
|
+
} catch (x) {}
|
|
81
74
|
}
|
|
82
75
|
|
|
83
76
|
/**
|
|
@@ -90,7 +83,7 @@ function defineMutationMembrane(prototype) {
|
|
|
90
83
|
* @param {*} props
|
|
91
84
|
* @internal
|
|
92
85
|
*/
|
|
93
|
-
var ReactElement = function(type, key, ref, owner, context, props) {
|
|
86
|
+
var ReactElement = function (type, key, ref, owner, context, props) {
|
|
94
87
|
// Built-in properties that belong on the element
|
|
95
88
|
this.type = type;
|
|
96
89
|
this.key = key;
|
|
@@ -99,30 +92,12 @@ var ReactElement = function(type, key, ref, owner, context, props) {
|
|
|
99
92
|
// Record the component responsible for creating this element.
|
|
100
93
|
this._owner = owner;
|
|
101
94
|
|
|
102
|
-
|
|
103
|
-
// through the owner.
|
|
104
|
-
this._context = context;
|
|
105
|
-
|
|
106
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
95
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
107
96
|
// The validation flag and props are currently mutative. We put them on
|
|
108
97
|
// an external backing store so that we can freeze the whole object.
|
|
109
98
|
// This can be replaced with a WeakMap once they are implemented in
|
|
110
99
|
// commonly used development environments.
|
|
111
|
-
this._store = {props: props, originalProps: assign({}, props)};
|
|
112
|
-
|
|
113
|
-
// To make comparing ReactElements easier for testing purposes, we make
|
|
114
|
-
// the validation flag non-enumerable (where possible, which should
|
|
115
|
-
// include every environment we run tests in), so the test framework
|
|
116
|
-
// ignores it.
|
|
117
|
-
try {
|
|
118
|
-
Object.defineProperty(this._store, 'validated', {
|
|
119
|
-
configurable: false,
|
|
120
|
-
enumerable: false,
|
|
121
|
-
writable: true
|
|
122
|
-
});
|
|
123
|
-
} catch (x) {
|
|
124
|
-
}
|
|
125
|
-
this._store.validated = false;
|
|
100
|
+
this._store = { props: props, originalProps: assign({}, props) };
|
|
126
101
|
|
|
127
102
|
// We're not allowed to set props directly on the object so we early
|
|
128
103
|
// return and rely on the prototype membrane to forward to the backing
|
|
@@ -142,11 +117,11 @@ ReactElement.prototype = {
|
|
|
142
117
|
_isReactElement: true
|
|
143
118
|
};
|
|
144
119
|
|
|
145
|
-
if (
|
|
120
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
146
121
|
defineMutationMembrane(ReactElement.prototype);
|
|
147
122
|
}
|
|
148
123
|
|
|
149
|
-
ReactElement.createElement = function(type, config, children) {
|
|
124
|
+
ReactElement.createElement = function (type, config, children) {
|
|
150
125
|
var propName;
|
|
151
126
|
|
|
152
127
|
// Reserved names are extracted
|
|
@@ -160,8 +135,7 @@ ReactElement.createElement = function(type, config, children) {
|
|
|
160
135
|
key = config.key === undefined ? null : '' + config.key;
|
|
161
136
|
// Remaining properties are added to a new props object
|
|
162
137
|
for (propName in config) {
|
|
163
|
-
if (config.hasOwnProperty(propName) &&
|
|
164
|
-
!RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
138
|
+
if (config.hasOwnProperty(propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
165
139
|
props[propName] = config[propName];
|
|
166
140
|
}
|
|
167
141
|
}
|
|
@@ -174,6 +148,20 @@ ReactElement.createElement = function(type, config, children) {
|
|
|
174
148
|
props.children = children;
|
|
175
149
|
} else if (childrenLength > 1) {
|
|
176
150
|
var childArray = Array(childrenLength);
|
|
151
|
+
|
|
152
|
+
// To make comparing ReactElements easier for testing purposes, we make
|
|
153
|
+
// the validation flag non-enumerable (where possible, which should
|
|
154
|
+
// include every environment we run tests in), so the test framework
|
|
155
|
+
// ignores it.
|
|
156
|
+
try {
|
|
157
|
+
Object.defineProperty(childArray, '_reactChildKeysValidated', {
|
|
158
|
+
configurable: false,
|
|
159
|
+
enumerable: false,
|
|
160
|
+
writable: true
|
|
161
|
+
});
|
|
162
|
+
} catch (x) {}
|
|
163
|
+
childArray._reactChildKeysValidated = true;
|
|
164
|
+
|
|
177
165
|
for (var i = 0; i < childrenLength; i++) {
|
|
178
166
|
childArray[i] = arguments[i + 2];
|
|
179
167
|
}
|
|
@@ -190,20 +178,13 @@ ReactElement.createElement = function(type, config, children) {
|
|
|
190
178
|
}
|
|
191
179
|
}
|
|
192
180
|
|
|
193
|
-
return new ReactElement(
|
|
194
|
-
type,
|
|
195
|
-
key,
|
|
196
|
-
ref,
|
|
197
|
-
ReactCurrentOwner.current,
|
|
198
|
-
ReactContext.current,
|
|
199
|
-
props
|
|
200
|
-
);
|
|
181
|
+
return new ReactElement(type, key, ref, ReactCurrentOwner.current, ReactContext.current, props);
|
|
201
182
|
};
|
|
202
183
|
|
|
203
|
-
ReactElement.createFactory = function(type) {
|
|
184
|
+
ReactElement.createFactory = function (type) {
|
|
204
185
|
var factory = ReactElement.createElement.bind(null, type);
|
|
205
186
|
// Expose the type on the factory and the prototype so that it can be
|
|
206
|
-
// easily accessed on elements. E.g.
|
|
187
|
+
// easily accessed on elements. E.g. `<Foo />.type === Foo`.
|
|
207
188
|
// This should not be named `constructor` since this may not be the function
|
|
208
189
|
// that created the element, and it may not even be a constructor.
|
|
209
190
|
// Legacy hook TODO: Warn if this is accessed
|
|
@@ -211,24 +192,12 @@ ReactElement.createFactory = function(type) {
|
|
|
211
192
|
return factory;
|
|
212
193
|
};
|
|
213
194
|
|
|
214
|
-
ReactElement.cloneAndReplaceProps = function(oldElement, newProps) {
|
|
215
|
-
var newElement = new ReactElement(
|
|
216
|
-
oldElement.type,
|
|
217
|
-
oldElement.key,
|
|
218
|
-
oldElement.ref,
|
|
219
|
-
oldElement._owner,
|
|
220
|
-
oldElement._context,
|
|
221
|
-
newProps
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
225
|
-
// If the key on the original is valid, then the clone is valid
|
|
226
|
-
newElement._store.validated = oldElement._store.validated;
|
|
227
|
-
}
|
|
195
|
+
ReactElement.cloneAndReplaceProps = function (oldElement, newProps) {
|
|
196
|
+
var newElement = new ReactElement(oldElement.type, oldElement.key, oldElement.ref, oldElement._owner, oldElement._context, newProps);
|
|
228
197
|
return newElement;
|
|
229
198
|
};
|
|
230
199
|
|
|
231
|
-
ReactElement.cloneElement = function(element, config, children) {
|
|
200
|
+
ReactElement.cloneElement = function (element, config, children) {
|
|
232
201
|
var propName;
|
|
233
202
|
|
|
234
203
|
// Original props are copied
|
|
@@ -252,8 +221,7 @@ ReactElement.cloneElement = function(element, config, children) {
|
|
|
252
221
|
}
|
|
253
222
|
// Remaining properties override existing props
|
|
254
223
|
for (propName in config) {
|
|
255
|
-
if (config.hasOwnProperty(propName) &&
|
|
256
|
-
!RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
224
|
+
if (config.hasOwnProperty(propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
257
225
|
props[propName] = config[propName];
|
|
258
226
|
}
|
|
259
227
|
}
|
|
@@ -272,14 +240,7 @@ ReactElement.cloneElement = function(element, config, children) {
|
|
|
272
240
|
props.children = childArray;
|
|
273
241
|
}
|
|
274
242
|
|
|
275
|
-
return new ReactElement(
|
|
276
|
-
element.type,
|
|
277
|
-
key,
|
|
278
|
-
ref,
|
|
279
|
-
owner,
|
|
280
|
-
element._context,
|
|
281
|
-
props
|
|
282
|
-
);
|
|
243
|
+
return new ReactElement(element.type, key, ref, owner, element._context, props);
|
|
283
244
|
};
|
|
284
245
|
|
|
285
246
|
/**
|
|
@@ -287,7 +248,7 @@ ReactElement.cloneElement = function(element, config, children) {
|
|
|
287
248
|
* @return {boolean} True if `object` is a valid component.
|
|
288
249
|
* @final
|
|
289
250
|
*/
|
|
290
|
-
ReactElement.isValidElement = function(object) {
|
|
251
|
+
ReactElement.isValidElement = function (object) {
|
|
291
252
|
// ReactTestUtils is often used outside of beforeEach where as React is
|
|
292
253
|
// within it. This leads to two different instances of React on the same
|
|
293
254
|
// page. To identify a element from a different React instance we use
|
|
@@ -302,3 +263,5 @@ ReactElement.isValidElement = function(object) {
|
|
|
302
263
|
};
|
|
303
264
|
|
|
304
265
|
module.exports = ReactElement;
|
|
266
|
+
|
|
267
|
+
// IE will fail on defineProperty
|
|
@@ -76,9 +76,7 @@ function getName(instance) {
|
|
|
76
76
|
*/
|
|
77
77
|
function getCurrentOwnerDisplayName() {
|
|
78
78
|
var current = ReactCurrentOwner.current;
|
|
79
|
-
return (
|
|
80
|
-
current && getName(current) || undefined
|
|
81
|
-
);
|
|
79
|
+
return current && getName(current) || undefined;
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
/**
|
|
@@ -92,16 +90,10 @@ function getCurrentOwnerDisplayName() {
|
|
|
92
90
|
* @param {*} parentType element's parent's type.
|
|
93
91
|
*/
|
|
94
92
|
function validateExplicitKey(element, parentType) {
|
|
95
|
-
if (element.
|
|
93
|
+
if (element.key != null) {
|
|
96
94
|
return;
|
|
97
95
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
warnAndMonitorForKeyUse(
|
|
101
|
-
'Each child in an array or iterator should have a unique "key" prop.',
|
|
102
|
-
element,
|
|
103
|
-
parentType
|
|
104
|
-
);
|
|
96
|
+
warnAndMonitorForKeyUse('Each child in an array or iterator should have a unique "key" prop.', element, parentType);
|
|
105
97
|
}
|
|
106
98
|
|
|
107
99
|
/**
|
|
@@ -117,11 +109,7 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
117
109
|
if (!NUMERIC_PROPERTY_REGEX.test(name)) {
|
|
118
110
|
return;
|
|
119
111
|
}
|
|
120
|
-
warnAndMonitorForKeyUse(
|
|
121
|
-
'Child objects should have non-numeric keys so ordering is preserved.',
|
|
122
|
-
element,
|
|
123
|
-
parentType
|
|
124
|
-
);
|
|
112
|
+
warnAndMonitorForKeyUse('Child objects should have non-numeric keys so ordering is preserved.', element, parentType);
|
|
125
113
|
}
|
|
126
114
|
|
|
127
115
|
/**
|
|
@@ -134,42 +122,29 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
134
122
|
*/
|
|
135
123
|
function warnAndMonitorForKeyUse(message, element, parentType) {
|
|
136
124
|
var ownerName = getCurrentOwnerDisplayName();
|
|
137
|
-
var parentName = typeof parentType === 'string' ?
|
|
138
|
-
parentType : parentType.displayName || parentType.name;
|
|
125
|
+
var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
|
139
126
|
|
|
140
127
|
var useName = ownerName || parentName;
|
|
141
|
-
var memoizer = ownerHasKeyUseWarning[message] || (
|
|
142
|
-
(ownerHasKeyUseWarning[message] = {})
|
|
143
|
-
);
|
|
128
|
+
var memoizer = ownerHasKeyUseWarning[message] || (ownerHasKeyUseWarning[message] = {});
|
|
144
129
|
if (memoizer.hasOwnProperty(useName)) {
|
|
145
130
|
return;
|
|
146
131
|
}
|
|
147
132
|
memoizer[useName] = true;
|
|
148
133
|
|
|
149
|
-
var parentOrOwnerAddendum =
|
|
150
|
-
ownerName ? (" Check the render method of " + ownerName + ".") :
|
|
151
|
-
parentName ? (" Check the React.render call using <" + parentName + ">.") :
|
|
152
|
-
'';
|
|
134
|
+
var parentOrOwnerAddendum = ownerName ? ' Check the render method of ' + ownerName + '.' : parentName ? ' Check the React.render call using <' + parentName + '>.' : '';
|
|
153
135
|
|
|
154
136
|
// Usually the current owner is the offender, but if it accepts children as a
|
|
155
137
|
// property, it may be the creator of the child that's responsible for
|
|
156
138
|
// assigning it a key.
|
|
157
139
|
var childOwnerAddendum = '';
|
|
158
|
-
if (element &&
|
|
159
|
-
element._owner &&
|
|
160
|
-
element._owner !== ReactCurrentOwner.current) {
|
|
140
|
+
if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
|
|
161
141
|
// Name of the component that originally created this child.
|
|
162
142
|
var childOwnerName = getName(element._owner);
|
|
163
143
|
|
|
164
|
-
childOwnerAddendum =
|
|
144
|
+
childOwnerAddendum = ' It was passed a child from ' + childOwnerName + '.';
|
|
165
145
|
}
|
|
166
146
|
|
|
167
|
-
|
|
168
|
-
false,
|
|
169
|
-
message + '%s%s See https://fb.me/react-warning-keys for more information.',
|
|
170
|
-
parentOrOwnerAddendum,
|
|
171
|
-
childOwnerAddendum
|
|
172
|
-
) : null);
|
|
147
|
+
'production' !== process.env.NODE_ENV ? warning(false, message + '%s%s See https://fb.me/react-warning-keys for more information.', parentOrOwnerAddendum, childOwnerAddendum) : null;
|
|
173
148
|
}
|
|
174
149
|
|
|
175
150
|
/**
|
|
@@ -183,15 +158,22 @@ function warnAndMonitorForKeyUse(message, element, parentType) {
|
|
|
183
158
|
*/
|
|
184
159
|
function validateChildKeys(node, parentType) {
|
|
185
160
|
if (Array.isArray(node)) {
|
|
161
|
+
if (node._reactChildKeysValidated) {
|
|
162
|
+
// All child elements were passed in a valid location.
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
186
165
|
for (var i = 0; i < node.length; i++) {
|
|
187
166
|
var child = node[i];
|
|
188
167
|
if (ReactElement.isValidElement(child)) {
|
|
189
168
|
validateExplicitKey(child, parentType);
|
|
169
|
+
} else {
|
|
170
|
+
// TODO: Warn on unkeyed arrays and suggest using createFragment
|
|
171
|
+
validateChildKeys(child, parentType);
|
|
190
172
|
}
|
|
191
173
|
}
|
|
192
|
-
} else if (ReactElement.isValidElement(node)) {
|
|
174
|
+
} else if (typeof node === 'string' || typeof node === 'number' || ReactElement.isValidElement(node)) {
|
|
193
175
|
// This element was passed in a valid location.
|
|
194
|
-
|
|
176
|
+
return;
|
|
195
177
|
} else if (node) {
|
|
196
178
|
var iteratorFn = getIteratorFn(node);
|
|
197
179
|
// Entry iterators provide implicit keys.
|
|
@@ -202,6 +184,8 @@ function validateChildKeys(node, parentType) {
|
|
|
202
184
|
while (!(step = iterator.next()).done) {
|
|
203
185
|
if (ReactElement.isValidElement(step.value)) {
|
|
204
186
|
validateExplicitKey(step.value, parentType);
|
|
187
|
+
} else {
|
|
188
|
+
validateChildKeys(step.value, parentType);
|
|
205
189
|
}
|
|
206
190
|
}
|
|
207
191
|
}
|
|
@@ -210,6 +194,7 @@ function validateChildKeys(node, parentType) {
|
|
|
210
194
|
for (var key in fragment) {
|
|
211
195
|
if (fragment.hasOwnProperty(key)) {
|
|
212
196
|
validatePropertyKey(key, fragment[key], parentType);
|
|
197
|
+
validateChildKeys(fragment[key], parentType);
|
|
213
198
|
}
|
|
214
199
|
}
|
|
215
200
|
}
|
|
@@ -235,25 +220,19 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
235
220
|
try {
|
|
236
221
|
// This is intentionally an invariant that gets caught. It's the same
|
|
237
222
|
// behavior as without this statement except with a better message.
|
|
238
|
-
|
|
239
|
-
typeof propTypes[propName] === 'function',
|
|
240
|
-
'%s: %s type `%s` is invalid; it must be a function, usually from ' +
|
|
241
|
-
'React.PropTypes.',
|
|
242
|
-
componentName || 'React class',
|
|
243
|
-
ReactPropTypeLocationNames[location],
|
|
244
|
-
propName
|
|
245
|
-
) : invariant(typeof propTypes[propName] === 'function'));
|
|
223
|
+
'production' !== process.env.NODE_ENV ? invariant(typeof propTypes[propName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(typeof propTypes[propName] === 'function');
|
|
246
224
|
error = propTypes[propName](props, propName, componentName, location);
|
|
247
225
|
} catch (ex) {
|
|
248
226
|
error = ex;
|
|
249
227
|
}
|
|
228
|
+
'production' !== process.env.NODE_ENV ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], propName, typeof error) : null;
|
|
250
229
|
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
251
230
|
// Only monitor this failure once because there tends to be a lot of the
|
|
252
231
|
// same error.
|
|
253
232
|
loggedTypeFailures[error.message] = true;
|
|
254
233
|
|
|
255
|
-
var addendum = getDeclarationErrorAddendum(
|
|
256
|
-
|
|
234
|
+
var addendum = getDeclarationErrorAddendum();
|
|
235
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'Failed propType: %s%s', error.message, addendum) : null;
|
|
257
236
|
}
|
|
258
237
|
}
|
|
259
238
|
}
|
|
@@ -270,8 +249,7 @@ var warnedPropsMutations = {};
|
|
|
270
249
|
function warnForPropsMutation(propName, element) {
|
|
271
250
|
var type = element.type;
|
|
272
251
|
var elementName = typeof type === 'string' ? type : type.displayName;
|
|
273
|
-
var ownerName = element._owner ?
|
|
274
|
-
element._owner.getPublicInstance().constructor.displayName : null;
|
|
252
|
+
var ownerName = element._owner ? element._owner.getPublicInstance().constructor.displayName : null;
|
|
275
253
|
|
|
276
254
|
var warningKey = propName + '|' + elementName + '|' + ownerName;
|
|
277
255
|
if (warnedPropsMutations.hasOwnProperty(warningKey)) {
|
|
@@ -288,15 +266,7 @@ function warnForPropsMutation(propName, element) {
|
|
|
288
266
|
ownerInfo = ' The element was created by ' + ownerName + '.';
|
|
289
267
|
}
|
|
290
268
|
|
|
291
|
-
|
|
292
|
-
false,
|
|
293
|
-
'Don\'t set .props.%s of the React component%s. Instead, specify the ' +
|
|
294
|
-
'correct value when initially creating the element or use ' +
|
|
295
|
-
'React.cloneElement to make a new element with updated props.%s',
|
|
296
|
-
propName,
|
|
297
|
-
elementInfo,
|
|
298
|
-
ownerInfo
|
|
299
|
-
) : null);
|
|
269
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'Don\'t set .props.%s of the React component%s. Instead, specify the ' + 'correct value when initially creating the element or use ' + 'React.cloneElement to make a new element with updated props.%s', propName, elementInfo, ownerInfo) : null;
|
|
300
270
|
}
|
|
301
271
|
|
|
302
272
|
// Inline Object.is polyfill
|
|
@@ -332,8 +302,7 @@ function checkAndWarnForMutatedProps(element) {
|
|
|
332
302
|
|
|
333
303
|
for (var propName in props) {
|
|
334
304
|
if (props.hasOwnProperty(propName)) {
|
|
335
|
-
if (!originalProps.hasOwnProperty(propName) ||
|
|
336
|
-
!is(originalProps[propName], props[propName])) {
|
|
305
|
+
if (!originalProps.hasOwnProperty(propName) || !is(originalProps[propName], props[propName])) {
|
|
337
306
|
warnForPropsMutation(propName, element);
|
|
338
307
|
|
|
339
308
|
// Copy over the new value so that the two props objects match again
|
|
@@ -350,7 +319,7 @@ function checkAndWarnForMutatedProps(element) {
|
|
|
350
319
|
* @param {ReactElement} element
|
|
351
320
|
*/
|
|
352
321
|
function validatePropTypes(element) {
|
|
353
|
-
if (element.type
|
|
322
|
+
if (!(typeof element.type === 'string' || typeof element.type === 'function')) {
|
|
354
323
|
// This has already warned. Don't throw.
|
|
355
324
|
return;
|
|
356
325
|
}
|
|
@@ -358,24 +327,13 @@ function validatePropTypes(element) {
|
|
|
358
327
|
// to a composite class which may have propTypes.
|
|
359
328
|
// TODO: Validating a string's propTypes is not decoupled from the
|
|
360
329
|
// rendering target which is problematic.
|
|
361
|
-
var componentClass = ReactNativeComponent.getComponentClassForElement(
|
|
362
|
-
element
|
|
363
|
-
);
|
|
330
|
+
var componentClass = ReactNativeComponent.getComponentClassForElement(element);
|
|
364
331
|
var name = componentClass.displayName || componentClass.name;
|
|
365
332
|
if (componentClass.propTypes) {
|
|
366
|
-
checkPropTypes(
|
|
367
|
-
name,
|
|
368
|
-
componentClass.propTypes,
|
|
369
|
-
element.props,
|
|
370
|
-
ReactPropTypeLocations.prop
|
|
371
|
-
);
|
|
333
|
+
checkPropTypes(name, componentClass.propTypes, element.props, ReactPropTypeLocations.prop);
|
|
372
334
|
}
|
|
373
335
|
if (typeof componentClass.getDefaultProps === 'function') {
|
|
374
|
-
|
|
375
|
-
componentClass.getDefaultProps.isReactClassApproved,
|
|
376
|
-
'getDefaultProps is only used on classic React.createClass ' +
|
|
377
|
-
'definitions. Use a static property named `defaultProps` instead.'
|
|
378
|
-
) : null);
|
|
336
|
+
'production' !== process.env.NODE_ENV ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : null;
|
|
379
337
|
}
|
|
380
338
|
}
|
|
381
339
|
|
|
@@ -383,15 +341,10 @@ var ReactElementValidator = {
|
|
|
383
341
|
|
|
384
342
|
checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
|
|
385
343
|
|
|
386
|
-
createElement: function(type, props, children) {
|
|
344
|
+
createElement: function (type, props, children) {
|
|
387
345
|
// We warn in this case but don't throw. We expect the element creation to
|
|
388
346
|
// succeed and there will likely be errors in render.
|
|
389
|
-
|
|
390
|
-
type != null,
|
|
391
|
-
'React.createElement: type should not be null or undefined. It should ' +
|
|
392
|
-
'be a string (for DOM elements) or a ReactClass (for composite ' +
|
|
393
|
-
'components).'
|
|
394
|
-
) : null);
|
|
347
|
+
'production' !== process.env.NODE_ENV ? warning(typeof type === 'string' || typeof type === 'function', 'React.createElement: type should not be null, undefined, boolean, or ' + 'number. It should be a string (for DOM elements) or a ReactClass ' + '(for composite components).%s', getDeclarationErrorAddendum()) : null;
|
|
395
348
|
|
|
396
349
|
var element = ReactElement.createElement.apply(this, arguments);
|
|
397
350
|
|
|
@@ -410,44 +363,30 @@ var ReactElementValidator = {
|
|
|
410
363
|
return element;
|
|
411
364
|
},
|
|
412
365
|
|
|
413
|
-
createFactory: function(type) {
|
|
414
|
-
var validatedFactory = ReactElementValidator.createElement.bind(
|
|
415
|
-
null,
|
|
416
|
-
type
|
|
417
|
-
);
|
|
366
|
+
createFactory: function (type) {
|
|
367
|
+
var validatedFactory = ReactElementValidator.createElement.bind(null, type);
|
|
418
368
|
// Legacy hook TODO: Warn if this is accessed
|
|
419
369
|
validatedFactory.type = type;
|
|
420
370
|
|
|
421
|
-
if (
|
|
371
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
422
372
|
try {
|
|
423
|
-
Object.defineProperty(
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
'Factory.type is deprecated. Access the class directly ' +
|
|
432
|
-
'before passing it to createFactory.'
|
|
433
|
-
) : null);
|
|
434
|
-
Object.defineProperty(this, 'type', {
|
|
435
|
-
value: type
|
|
436
|
-
});
|
|
437
|
-
return type;
|
|
438
|
-
}
|
|
373
|
+
Object.defineProperty(validatedFactory, 'type', {
|
|
374
|
+
enumerable: false,
|
|
375
|
+
get: function () {
|
|
376
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : null;
|
|
377
|
+
Object.defineProperty(this, 'type', {
|
|
378
|
+
value: type
|
|
379
|
+
});
|
|
380
|
+
return type;
|
|
439
381
|
}
|
|
440
|
-
);
|
|
441
|
-
} catch (x) {
|
|
442
|
-
// IE will fail on defineProperty (es5-shim/sham too)
|
|
443
|
-
}
|
|
382
|
+
});
|
|
383
|
+
} catch (x) {}
|
|
444
384
|
}
|
|
445
385
|
|
|
446
|
-
|
|
447
386
|
return validatedFactory;
|
|
448
387
|
},
|
|
449
388
|
|
|
450
|
-
cloneElement: function(element, props, children) {
|
|
389
|
+
cloneElement: function (element, props, children) {
|
|
451
390
|
var newElement = ReactElement.cloneElement.apply(this, arguments);
|
|
452
391
|
for (var i = 2; i < arguments.length; i++) {
|
|
453
392
|
validateChildKeys(arguments[i], newElement.type);
|
|
@@ -459,3 +398,5 @@ var ReactElementValidator = {
|
|
|
459
398
|
};
|
|
460
399
|
|
|
461
400
|
module.exports = ReactElementValidator;
|
|
401
|
+
|
|
402
|
+
// IE will fail on defineProperty (es5-shim/sham too)
|