react 0.13.0-alpha.2 → 0.13.0-rc2
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/dist/JSXTransformer.js +1798 -1194
- package/dist/react-with-addons.js +2640 -2046
- package/dist/react-with-addons.min.js +7 -6
- package/dist/react.js +2459 -1930
- package/dist/react.min.js +6 -6
- package/lib/AutoFocusMixin.js +1 -1
- package/lib/BeforeInputEventPlugin.js +1 -5
- package/lib/CSSCore.js +1 -1
- package/lib/CSSProperty.js +3 -1
- package/lib/CSSPropertyOperations.js +43 -16
- package/lib/CallbackQueue.js +1 -1
- package/lib/ChangeEventPlugin.js +1 -1
- package/lib/ClientReactRootIndex.js +1 -1
- package/lib/DOMChildrenOperations.js +4 -43
- package/lib/DOMProperty.js +1 -1
- package/lib/DOMPropertyOperations.js +10 -15
- package/lib/Danger.js +1 -1
- package/lib/DefaultEventPluginOrder.js +2 -2
- package/lib/EnterLeaveEventPlugin.js +1 -1
- package/lib/EventConstants.js +1 -1
- package/lib/EventListener.js +1 -1
- package/lib/EventPluginHub.js +1 -1
- package/lib/EventPluginRegistry.js +1 -1
- package/lib/EventPluginUtils.js +3 -3
- package/lib/EventPropagators.js +1 -1
- package/lib/ExecutionEnvironment.js +1 -1
- package/lib/FallbackCompositionState.js +1 -1
- package/lib/HTMLDOMPropertyConfig.js +12 -5
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +1 -1
- package/lib/LocalEventTrapMixin.js +9 -2
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +11 -14
- package/lib/ReactBrowserComponentMixin.js +1 -1
- package/lib/ReactBrowserEventEmitter.js +2 -2
- package/lib/ReactCSSTransitionGroup.js +1 -1
- package/lib/ReactCSSTransitionGroupChild.js +8 -5
- package/lib/ReactChildReconciler.js +9 -5
- package/lib/ReactChildren.js +3 -2
- package/lib/ReactClass.js +144 -76
- package/lib/ReactComponent.js +99 -166
- package/lib/ReactComponentBrowserEnvironment.js +1 -1
- package/lib/ReactComponentEnvironment.js +1 -1
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +261 -480
- package/lib/ReactContext.js +13 -3
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +1 -1
- package/lib/ReactDOMButton.js +1 -1
- package/lib/ReactDOMComponent.js +23 -48
- package/lib/ReactDOMForm.js +1 -1
- package/lib/ReactDOMIDOperations.js +3 -3
- package/lib/ReactDOMIframe.js +43 -0
- package/lib/ReactDOMImg.js +1 -1
- package/lib/ReactDOMInput.js +1 -1
- package/lib/ReactDOMOption.js +1 -1
- package/lib/ReactDOMSelect.js +1 -1
- package/lib/ReactDOMSelection.js +1 -1
- package/lib/ReactDOMTextComponent.js +3 -12
- package/lib/ReactDOMTextarea.js +1 -1
- package/lib/ReactDefaultBatchingStrategy.js +4 -4
- package/lib/ReactDefaultInjection.js +25 -1
- package/lib/ReactDefaultPerf.js +11 -3
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +59 -4
- package/lib/ReactElementValidator.js +141 -85
- package/lib/ReactEmptyComponent.js +5 -5
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +1 -2
- package/lib/ReactFragment.js +181 -0
- package/lib/ReactInjection.js +1 -1
- package/lib/ReactInputSelection.js +1 -1
- package/lib/ReactInstanceHandles.js +1 -1
- package/lib/ReactInstanceMap.js +1 -1
- package/lib/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +77 -20
- package/lib/ReactMultiChild.js +7 -4
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +33 -36
- package/lib/ReactOwner.js +1 -1
- package/lib/ReactPerf.js +1 -1
- package/lib/ReactPropTransferer.js +1 -1
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +5 -3
- package/lib/ReactPutListenerQueue.js +1 -1
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactReconciler.js +120 -0
- package/lib/ReactRef.js +40 -67
- package/lib/ReactRootIndex.js +1 -1
- package/lib/ReactServerRendering.js +1 -1
- package/lib/ReactServerRenderingTransaction.js +1 -1
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +48 -7
- package/lib/ReactTransitionChildMapping.js +7 -3
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +5 -5
- package/lib/ReactUpdateQueue.js +295 -0
- package/lib/ReactUpdates.js +11 -20
- package/lib/ReactWithAddons.js +3 -1
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +1 -1
- package/lib/ServerReactRootIndex.js +1 -1
- package/lib/SimpleEventPlugin.js +3 -3
- package/lib/SyntheticClipboardEvent.js +1 -1
- package/lib/SyntheticCompositionEvent.js +1 -1
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +1 -1
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +1 -1
- package/lib/SyntheticKeyboardEvent.js +1 -1
- package/lib/SyntheticMouseEvent.js +1 -1
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/Transaction.js +2 -2
- package/lib/ViewportMetrics.js +1 -1
- package/lib/accumulateInto.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/camelize.js +1 -1
- package/lib/camelizeStyleName.js +1 -1
- package/lib/cloneWithProps.js +4 -4
- package/lib/containsNode.js +1 -1
- package/lib/{createArrayFrom.js → createArrayFromMixed.js} +6 -6
- package/lib/createFullPageComponent.js +1 -1
- package/lib/createNodesFromMarkup.js +4 -4
- package/lib/cx.js +16 -1
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/emptyFunction.js +1 -1
- package/lib/emptyObject.js +1 -1
- package/lib/{escapeTextForBrowser.js → escapeTextContentForBrowser.js} +4 -5
- package/lib/findDOMNode.js +19 -1
- package/lib/flattenChildren.js +1 -1
- package/lib/focusNode.js +1 -1
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getActiveElement.js +1 -1
- 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 +1 -1
- package/lib/getMarkupWrap.js +1 -1
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +1 -1
- package/lib/hyphenateStyleName.js +1 -1
- package/lib/instantiateReactComponent.js +20 -20
- package/lib/invariant.js +1 -1
- package/lib/isEventSupported.js +1 -1
- package/lib/isNode.js +1 -1
- package/lib/isTextInputElement.js +1 -1
- package/lib/isTextNode.js +1 -1
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/keyOf.js +1 -1
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +1 -1
- package/lib/onlyChild.js +1 -1
- package/lib/performance.js +1 -1
- package/lib/performanceNow.js +1 -1
- package/lib/quoteAttributeValueForBrowser.js +26 -0
- package/lib/setInnerHTML.js +1 -1
- package/lib/setTextContent.js +40 -0
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +32 -10
- package/lib/toArray.js +2 -2
- package/lib/traverseAllChildren.js +18 -4
- package/lib/update.js +1 -1
- package/lib/warning.js +12 -1
- package/package.json +1 -1
- package/lib/ReactComponentBase.js +0 -126
- package/lib/accumulate.js +0 -47
- package/lib/copyProperties.js +0 -56
- package/lib/merge.js +0 -34
- package/lib/mergeInto.js +0 -24
- package/lib/monitorCodeUse.js +0 -30
package/lib/ReactDefaultPerf.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -242,10 +242,18 @@ var ReactDefaultPerf = {
|
|
|
242
242
|
addValue(entry.inclusive, rootNodeID, totalTime);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
var displayName = null;
|
|
246
|
+
if (this._instance.constructor.displayName) {
|
|
247
|
+
displayName = this._instance.constructor.displayName;
|
|
248
|
+
} else if (this._currentElement.type) {
|
|
249
|
+
displayName = this._currentElement.type;
|
|
250
|
+
}
|
|
251
|
+
|
|
245
252
|
entry.displayNames[rootNodeID] = {
|
|
246
|
-
current:
|
|
253
|
+
current: displayName,
|
|
247
254
|
owner: this._currentElement._owner ?
|
|
248
|
-
|
|
255
|
+
this._currentElement._owner._instance.constructor.displayName :
|
|
256
|
+
'<root>'
|
|
249
257
|
};
|
|
250
258
|
|
|
251
259
|
return rv;
|
package/lib/ReactElement.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2014, Facebook, Inc.
|
|
2
|
+
* Copyright 2014-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -45,8 +45,9 @@ function defineWarningProperty(object, key) {
|
|
|
45
45
|
set: function(value) {
|
|
46
46
|
("production" !== process.env.NODE_ENV ? warning(
|
|
47
47
|
false,
|
|
48
|
-
'Don\'t set the
|
|
49
|
-
'specify the correct value when initially creating the element.'
|
|
48
|
+
'Don\'t set the %s property of the React element. Instead, ' +
|
|
49
|
+
'specify the correct value when initially creating the element.',
|
|
50
|
+
key
|
|
50
51
|
) : null);
|
|
51
52
|
this._store[key] = value;
|
|
52
53
|
}
|
|
@@ -107,7 +108,7 @@ var ReactElement = function(type, key, ref, owner, context, props) {
|
|
|
107
108
|
// an external backing store so that we can freeze the whole object.
|
|
108
109
|
// This can be replaced with a WeakMap once they are implemented in
|
|
109
110
|
// commonly used development environments.
|
|
110
|
-
this._store = {
|
|
111
|
+
this._store = {props: props, originalProps: assign({}, props)};
|
|
111
112
|
|
|
112
113
|
// To make comparing ReactElements easier for testing purposes, we make
|
|
113
114
|
// the validation flag non-enumerable (where possible, which should
|
|
@@ -227,6 +228,60 @@ ReactElement.cloneAndReplaceProps = function(oldElement, newProps) {
|
|
|
227
228
|
return newElement;
|
|
228
229
|
};
|
|
229
230
|
|
|
231
|
+
ReactElement.cloneElement = function(element, config, children) {
|
|
232
|
+
var propName;
|
|
233
|
+
|
|
234
|
+
// Original props are copied
|
|
235
|
+
var props = assign({}, element.props);
|
|
236
|
+
|
|
237
|
+
// Reserved names are extracted
|
|
238
|
+
var key = element.key;
|
|
239
|
+
var ref = element.ref;
|
|
240
|
+
|
|
241
|
+
// Owner will be preserved, unless ref is overridden
|
|
242
|
+
var owner = element._owner;
|
|
243
|
+
|
|
244
|
+
if (config != null) {
|
|
245
|
+
if (config.ref !== undefined) {
|
|
246
|
+
// Silently steal the ref from the parent.
|
|
247
|
+
ref = config.ref;
|
|
248
|
+
owner = ReactCurrentOwner.current;
|
|
249
|
+
}
|
|
250
|
+
if (config.key !== undefined) {
|
|
251
|
+
key = '' + config.key;
|
|
252
|
+
}
|
|
253
|
+
// Remaining properties override existing props
|
|
254
|
+
for (propName in config) {
|
|
255
|
+
if (config.hasOwnProperty(propName) &&
|
|
256
|
+
!RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
257
|
+
props[propName] = config[propName];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Children can be more than one argument, and those are transferred onto
|
|
263
|
+
// the newly allocated props object.
|
|
264
|
+
var childrenLength = arguments.length - 2;
|
|
265
|
+
if (childrenLength === 1) {
|
|
266
|
+
props.children = children;
|
|
267
|
+
} else if (childrenLength > 1) {
|
|
268
|
+
var childArray = Array(childrenLength);
|
|
269
|
+
for (var i = 0; i < childrenLength; i++) {
|
|
270
|
+
childArray[i] = arguments[i + 2];
|
|
271
|
+
}
|
|
272
|
+
props.children = childArray;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return new ReactElement(
|
|
276
|
+
element.type,
|
|
277
|
+
key,
|
|
278
|
+
ref,
|
|
279
|
+
owner,
|
|
280
|
+
element._context,
|
|
281
|
+
props
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
|
|
230
285
|
/**
|
|
231
286
|
* @param {?object} object
|
|
232
287
|
* @return {boolean} True if `object` is a valid component.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2014, Facebook, Inc.
|
|
2
|
+
* Copyright 2014-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -19,25 +19,32 @@
|
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
21
|
var ReactElement = require("./ReactElement");
|
|
22
|
+
var ReactFragment = require("./ReactFragment");
|
|
22
23
|
var ReactPropTypeLocations = require("./ReactPropTypeLocations");
|
|
23
24
|
var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
|
|
24
25
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
26
|
+
var ReactNativeComponent = require("./ReactNativeComponent");
|
|
25
27
|
|
|
26
28
|
var getIteratorFn = require("./getIteratorFn");
|
|
27
|
-
var monitorCodeUse = require("./monitorCodeUse");
|
|
28
29
|
var invariant = require("./invariant");
|
|
29
30
|
var warning = require("./warning");
|
|
30
31
|
|
|
32
|
+
function getDeclarationErrorAddendum() {
|
|
33
|
+
if (ReactCurrentOwner.current) {
|
|
34
|
+
var name = ReactCurrentOwner.current.getName();
|
|
35
|
+
if (name) {
|
|
36
|
+
return ' Check the render method of `' + name + '`.';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
/**
|
|
32
43
|
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
33
44
|
* object keys are not valid. This allows us to keep track of children between
|
|
34
45
|
* updates.
|
|
35
46
|
*/
|
|
36
|
-
var ownerHasKeyUseWarning = {
|
|
37
|
-
'react_key_warning': {},
|
|
38
|
-
'react_numeric_key_warning': {}
|
|
39
|
-
};
|
|
40
|
-
var ownerHasMonitoredObjectMap = {};
|
|
47
|
+
var ownerHasKeyUseWarning = {};
|
|
41
48
|
|
|
42
49
|
var loggedTypeFailures = {};
|
|
43
50
|
|
|
@@ -91,7 +98,6 @@ function validateExplicitKey(element, parentType) {
|
|
|
91
98
|
element._store.validated = true;
|
|
92
99
|
|
|
93
100
|
warnAndMonitorForKeyUse(
|
|
94
|
-
'react_key_warning',
|
|
95
101
|
'Each child in an array or iterator should have a unique "key" prop.',
|
|
96
102
|
element,
|
|
97
103
|
parentType
|
|
@@ -112,7 +118,6 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
112
118
|
return;
|
|
113
119
|
}
|
|
114
120
|
warnAndMonitorForKeyUse(
|
|
115
|
-
'react_numeric_key_warning',
|
|
116
121
|
'Child objects should have non-numeric keys so ordering is preserved.',
|
|
117
122
|
element,
|
|
118
123
|
parentType
|
|
@@ -123,60 +128,48 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
123
128
|
* Shared warning and monitoring code for the key warnings.
|
|
124
129
|
*
|
|
125
130
|
* @internal
|
|
126
|
-
* @param {string} warningID The id used when logging.
|
|
127
131
|
* @param {string} message The base warning that gets output.
|
|
128
132
|
* @param {ReactElement} element Component that requires a key.
|
|
129
133
|
* @param {*} parentType element's parent's type.
|
|
130
134
|
*/
|
|
131
|
-
function warnAndMonitorForKeyUse(
|
|
135
|
+
function warnAndMonitorForKeyUse(message, element, parentType) {
|
|
132
136
|
var ownerName = getCurrentOwnerDisplayName();
|
|
133
|
-
var parentName = parentType
|
|
137
|
+
var parentName = typeof parentType === 'string' ?
|
|
138
|
+
parentType : parentType.displayName || parentType.name;
|
|
134
139
|
|
|
135
140
|
var useName = ownerName || parentName;
|
|
136
|
-
var memoizer = ownerHasKeyUseWarning[
|
|
141
|
+
var memoizer = ownerHasKeyUseWarning[message] || (
|
|
142
|
+
(ownerHasKeyUseWarning[message] = {})
|
|
143
|
+
);
|
|
137
144
|
if (memoizer.hasOwnProperty(useName)) {
|
|
138
145
|
return;
|
|
139
146
|
}
|
|
140
147
|
memoizer[useName] = true;
|
|
141
148
|
|
|
142
|
-
|
|
143
|
-
(" Check the render method of " + ownerName + ".") :
|
|
144
|
-
(" Check the React.render call using <" + parentName + ">.")
|
|
149
|
+
var parentOrOwnerAddendum =
|
|
150
|
+
ownerName ? (" Check the render method of " + ownerName + ".") :
|
|
151
|
+
parentName ? (" Check the React.render call using <" + parentName + ">.") :
|
|
152
|
+
'';
|
|
145
153
|
|
|
146
154
|
// Usually the current owner is the offender, but if it accepts children as a
|
|
147
155
|
// property, it may be the creator of the child that's responsible for
|
|
148
156
|
// assigning it a key.
|
|
149
|
-
var
|
|
157
|
+
var childOwnerAddendum = '';
|
|
150
158
|
if (element &&
|
|
151
159
|
element._owner &&
|
|
152
160
|
element._owner !== ReactCurrentOwner.current) {
|
|
153
161
|
// Name of the component that originally created this child.
|
|
154
|
-
childOwnerName = getName(element._owner);
|
|
162
|
+
var childOwnerName = getName(element._owner);
|
|
155
163
|
|
|
156
|
-
|
|
164
|
+
childOwnerAddendum = (" It was passed a child from " + childOwnerName + ".");
|
|
157
165
|
}
|
|
158
166
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Log that we're using an object map. We're considering deprecating this
|
|
169
|
-
* feature and replace it with proper Map and ImmutableMap data structures.
|
|
170
|
-
*
|
|
171
|
-
* @internal
|
|
172
|
-
*/
|
|
173
|
-
function monitorUseOfObjectMap() {
|
|
174
|
-
var currentName = getCurrentOwnerDisplayName() || '';
|
|
175
|
-
if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
ownerHasMonitoredObjectMap[currentName] = true;
|
|
179
|
-
monitorCodeUse('react_object_map_children');
|
|
167
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
168
|
+
false,
|
|
169
|
+
message + '%s%s See http://fb.me/react-warning-keys for more information.',
|
|
170
|
+
parentOrOwnerAddendum,
|
|
171
|
+
childOwnerAddendum
|
|
172
|
+
) : null);
|
|
180
173
|
}
|
|
181
174
|
|
|
182
175
|
/**
|
|
@@ -202,19 +195,21 @@ function validateChildKeys(node, parentType) {
|
|
|
202
195
|
} else if (node) {
|
|
203
196
|
var iteratorFn = getIteratorFn(node);
|
|
204
197
|
// Entry iterators provide implicit keys.
|
|
205
|
-
if (iteratorFn
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
198
|
+
if (iteratorFn) {
|
|
199
|
+
if (iteratorFn !== node.entries) {
|
|
200
|
+
var iterator = iteratorFn.call(node);
|
|
201
|
+
var step;
|
|
202
|
+
while (!(step = iterator.next()).done) {
|
|
203
|
+
if (ReactElement.isValidElement(step.value)) {
|
|
204
|
+
validateExplicitKey(step.value, parentType);
|
|
205
|
+
}
|
|
211
206
|
}
|
|
212
207
|
}
|
|
213
208
|
} else if (typeof node === 'object') {
|
|
214
|
-
|
|
215
|
-
for (var key in
|
|
216
|
-
if (
|
|
217
|
-
validatePropertyKey(key,
|
|
209
|
+
var fragment = ReactFragment.extractIfFragment(node);
|
|
210
|
+
for (var key in fragment) {
|
|
211
|
+
if (fragment.hasOwnProperty(key)) {
|
|
212
|
+
validatePropertyKey(key, fragment[key], parentType);
|
|
218
213
|
}
|
|
219
214
|
}
|
|
220
215
|
}
|
|
@@ -256,11 +251,9 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
256
251
|
// Only monitor this failure once because there tends to be a lot of the
|
|
257
252
|
// same error.
|
|
258
253
|
loggedTypeFailures[error.message] = true;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
{ message: error.message }
|
|
263
|
-
);
|
|
254
|
+
|
|
255
|
+
var addendum = getDeclarationErrorAddendum(this);
|
|
256
|
+
("production" !== process.env.NODE_ENV ? warning(false, 'Failed propType: %s%s', error.message, addendum) : null);
|
|
264
257
|
}
|
|
265
258
|
}
|
|
266
259
|
}
|
|
@@ -297,12 +290,28 @@ function warnForPropsMutation(propName, element) {
|
|
|
297
290
|
|
|
298
291
|
("production" !== process.env.NODE_ENV ? warning(
|
|
299
292
|
false,
|
|
300
|
-
'Don\'t set .props
|
|
301
|
-
|
|
302
|
-
'initially creating the element
|
|
293
|
+
'Don\'t set .props.%s of the React component%s. ' +
|
|
294
|
+
'Instead, specify the correct value when ' +
|
|
295
|
+
'initially creating the element.%s',
|
|
296
|
+
propName,
|
|
297
|
+
elementInfo,
|
|
298
|
+
ownerInfo
|
|
303
299
|
) : null);
|
|
304
300
|
}
|
|
305
301
|
|
|
302
|
+
// Inline Object.is polyfill
|
|
303
|
+
function is(a, b) {
|
|
304
|
+
if (a !== a) {
|
|
305
|
+
// NaN
|
|
306
|
+
return b !== b;
|
|
307
|
+
}
|
|
308
|
+
if (a === 0 && b === 0) {
|
|
309
|
+
// +-0
|
|
310
|
+
return 1 / a === 1 / b;
|
|
311
|
+
}
|
|
312
|
+
return a === b;
|
|
313
|
+
}
|
|
314
|
+
|
|
306
315
|
/**
|
|
307
316
|
* Given an element, check if its props have been mutated since element
|
|
308
317
|
* creation (or the last call to this function). In particular, check if any
|
|
@@ -324,7 +333,7 @@ function checkAndWarnForMutatedProps(element) {
|
|
|
324
333
|
for (var propName in props) {
|
|
325
334
|
if (props.hasOwnProperty(propName)) {
|
|
326
335
|
if (!originalProps.hasOwnProperty(propName) ||
|
|
327
|
-
originalProps[propName]
|
|
336
|
+
!is(originalProps[propName], props[propName])) {
|
|
328
337
|
warnForPropsMutation(propName, element);
|
|
329
338
|
|
|
330
339
|
// Copy over the new value so that the two props objects match again
|
|
@@ -334,6 +343,42 @@ function checkAndWarnForMutatedProps(element) {
|
|
|
334
343
|
}
|
|
335
344
|
}
|
|
336
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Given an element, validate that its props follow the propTypes definition,
|
|
348
|
+
* provided by the type.
|
|
349
|
+
*
|
|
350
|
+
* @param {ReactElement} element
|
|
351
|
+
*/
|
|
352
|
+
function validatePropTypes(element) {
|
|
353
|
+
if (element.type == null) {
|
|
354
|
+
// This has already warned. Don't throw.
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
// Extract the component class from the element. Converts string types
|
|
358
|
+
// to a composite class which may have propTypes.
|
|
359
|
+
// TODO: Validating a string's propTypes is not decoupled from the
|
|
360
|
+
// rendering target which is problematic.
|
|
361
|
+
var componentClass = ReactNativeComponent.getComponentClassForElement(
|
|
362
|
+
element
|
|
363
|
+
);
|
|
364
|
+
var name = componentClass.displayName || componentClass.name;
|
|
365
|
+
if (componentClass.propTypes) {
|
|
366
|
+
checkPropTypes(
|
|
367
|
+
name,
|
|
368
|
+
componentClass.propTypes,
|
|
369
|
+
element.props,
|
|
370
|
+
ReactPropTypeLocations.prop
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
if (typeof componentClass.getDefaultProps === 'function') {
|
|
374
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
375
|
+
componentClass.getDefaultProps.isReactClassApproved,
|
|
376
|
+
'getDefaultProps is only used on classic React.createClass ' +
|
|
377
|
+
'definitions. Use a static property named `defaultProps` instead.'
|
|
378
|
+
) : null);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
337
382
|
var ReactElementValidator = {
|
|
338
383
|
|
|
339
384
|
checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
|
|
@@ -360,32 +405,7 @@ var ReactElementValidator = {
|
|
|
360
405
|
validateChildKeys(arguments[i], type);
|
|
361
406
|
}
|
|
362
407
|
|
|
363
|
-
|
|
364
|
-
var name = type.displayName || type.name;
|
|
365
|
-
if (type.propTypes) {
|
|
366
|
-
checkPropTypes(
|
|
367
|
-
name,
|
|
368
|
-
type.propTypes,
|
|
369
|
-
element.props,
|
|
370
|
-
ReactPropTypeLocations.prop
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
if (type.contextTypes) {
|
|
374
|
-
checkPropTypes(
|
|
375
|
-
name,
|
|
376
|
-
type.contextTypes,
|
|
377
|
-
element._context,
|
|
378
|
-
ReactPropTypeLocations.context
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
if (typeof type.getDefaultProps === 'function') {
|
|
382
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
383
|
-
type.getDefaultProps.isReactClassApproved,
|
|
384
|
-
'getDefaultProps is only used on classic React.createClass ' +
|
|
385
|
-
'definitions. Use a static property named `defaultProps` instead.'
|
|
386
|
-
) : null);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
408
|
+
validatePropTypes(element);
|
|
389
409
|
|
|
390
410
|
return element;
|
|
391
411
|
},
|
|
@@ -397,7 +417,43 @@ var ReactElementValidator = {
|
|
|
397
417
|
);
|
|
398
418
|
// Legacy hook TODO: Warn if this is accessed
|
|
399
419
|
validatedFactory.type = type;
|
|
420
|
+
|
|
421
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
422
|
+
try {
|
|
423
|
+
Object.defineProperty(
|
|
424
|
+
validatedFactory,
|
|
425
|
+
'type',
|
|
426
|
+
{
|
|
427
|
+
enumerable: false,
|
|
428
|
+
get: function() {
|
|
429
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
430
|
+
false,
|
|
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
|
+
}
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
} catch (x) {
|
|
442
|
+
// IE will fail on defineProperty (es5-shim/sham too)
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
|
|
400
447
|
return validatedFactory;
|
|
448
|
+
},
|
|
449
|
+
|
|
450
|
+
cloneElement: function(element, props, children) {
|
|
451
|
+
var newElement = ReactElement.cloneElement.apply(this, arguments);
|
|
452
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
453
|
+
validateChildKeys(arguments[i], newElement.type);
|
|
454
|
+
}
|
|
455
|
+
validatePropTypes(newElement);
|
|
456
|
+
return newElement;
|
|
401
457
|
}
|
|
402
458
|
|
|
403
459
|
};
|