react 0.13.0-beta.1 → 0.13.0
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 +1919 -1295
- package/dist/react-with-addons.js +1690 -1090
- package/dist/react-with-addons.min.js +7 -6
- package/dist/react.js +1574 -1010
- 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 +1 -1
- 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 +7 -14
- 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 +1 -1
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +7 -9
- 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 +1 -1
- package/lib/ReactChildren.js +3 -2
- package/lib/ReactClass.js +49 -23
- package/lib/ReactComponent.js +35 -19
- package/lib/ReactComponentBrowserEnvironment.js +1 -1
- package/lib/ReactComponentEnvironment.js +1 -1
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +89 -40
- 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 +19 -19
- 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 -5
- package/lib/ReactDOMTextarea.js +1 -1
- package/lib/ReactDefaultBatchingStrategy.js +1 -1
- package/lib/ReactDefaultInjection.js +25 -1
- package/lib/ReactDefaultPerf.js +5 -10
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +56 -2
- package/lib/ReactElementValidator.js +122 -79
- package/lib/ReactEmptyComponent.js +5 -5
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +1 -1
- 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 +1 -1
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +32 -10
- package/lib/ReactMultiChild.js +1 -1
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +7 -20
- 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 +7 -4
- package/lib/ReactPutListenerQueue.js +1 -1
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactReconciler.js +15 -2
- package/lib/ReactRef.js +2 -3
- 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 +19 -7
- package/lib/ReactTransitionChildMapping.js +7 -3
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +5 -5
- package/lib/ReactUpdateQueue.js +63 -32
- package/lib/ReactUpdates.js +7 -2
- 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 +6 -1
- 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 +9 -2
- package/package.json +1 -1
- package/lib/copyProperties.js +0 -56
- package/lib/merge.js +0 -34
- package/lib/mergeInto.js +0 -24
- package/lib/monitorCodeUse.js +0 -30
|
@@ -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,13 +19,13 @@
|
|
|
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");
|
|
25
26
|
var ReactNativeComponent = require("./ReactNativeComponent");
|
|
26
27
|
|
|
27
28
|
var getIteratorFn = require("./getIteratorFn");
|
|
28
|
-
var monitorCodeUse = require("./monitorCodeUse");
|
|
29
29
|
var invariant = require("./invariant");
|
|
30
30
|
var warning = require("./warning");
|
|
31
31
|
|
|
@@ -44,11 +44,7 @@ function getDeclarationErrorAddendum() {
|
|
|
44
44
|
* object keys are not valid. This allows us to keep track of children between
|
|
45
45
|
* updates.
|
|
46
46
|
*/
|
|
47
|
-
var ownerHasKeyUseWarning = {
|
|
48
|
-
'react_key_warning': {},
|
|
49
|
-
'react_numeric_key_warning': {}
|
|
50
|
-
};
|
|
51
|
-
var ownerHasMonitoredObjectMap = {};
|
|
47
|
+
var ownerHasKeyUseWarning = {};
|
|
52
48
|
|
|
53
49
|
var loggedTypeFailures = {};
|
|
54
50
|
|
|
@@ -102,7 +98,6 @@ function validateExplicitKey(element, parentType) {
|
|
|
102
98
|
element._store.validated = true;
|
|
103
99
|
|
|
104
100
|
warnAndMonitorForKeyUse(
|
|
105
|
-
'react_key_warning',
|
|
106
101
|
'Each child in an array or iterator should have a unique "key" prop.',
|
|
107
102
|
element,
|
|
108
103
|
parentType
|
|
@@ -123,7 +118,6 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
123
118
|
return;
|
|
124
119
|
}
|
|
125
120
|
warnAndMonitorForKeyUse(
|
|
126
|
-
'react_numeric_key_warning',
|
|
127
121
|
'Child objects should have non-numeric keys so ordering is preserved.',
|
|
128
122
|
element,
|
|
129
123
|
parentType
|
|
@@ -134,60 +128,48 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
134
128
|
* Shared warning and monitoring code for the key warnings.
|
|
135
129
|
*
|
|
136
130
|
* @internal
|
|
137
|
-
* @param {string} warningID The id used when logging.
|
|
138
131
|
* @param {string} message The base warning that gets output.
|
|
139
132
|
* @param {ReactElement} element Component that requires a key.
|
|
140
133
|
* @param {*} parentType element's parent's type.
|
|
141
134
|
*/
|
|
142
|
-
function warnAndMonitorForKeyUse(
|
|
135
|
+
function warnAndMonitorForKeyUse(message, element, parentType) {
|
|
143
136
|
var ownerName = getCurrentOwnerDisplayName();
|
|
144
|
-
var parentName = parentType
|
|
137
|
+
var parentName = typeof parentType === 'string' ?
|
|
138
|
+
parentType : parentType.displayName || parentType.name;
|
|
145
139
|
|
|
146
140
|
var useName = ownerName || parentName;
|
|
147
|
-
var memoizer = ownerHasKeyUseWarning[
|
|
141
|
+
var memoizer = ownerHasKeyUseWarning[message] || (
|
|
142
|
+
(ownerHasKeyUseWarning[message] = {})
|
|
143
|
+
);
|
|
148
144
|
if (memoizer.hasOwnProperty(useName)) {
|
|
149
145
|
return;
|
|
150
146
|
}
|
|
151
147
|
memoizer[useName] = true;
|
|
152
148
|
|
|
153
|
-
|
|
154
|
-
(" Check the render method of " + ownerName + ".") :
|
|
155
|
-
(" 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
|
+
'';
|
|
156
153
|
|
|
157
154
|
// Usually the current owner is the offender, but if it accepts children as a
|
|
158
155
|
// property, it may be the creator of the child that's responsible for
|
|
159
156
|
// assigning it a key.
|
|
160
|
-
var
|
|
157
|
+
var childOwnerAddendum = '';
|
|
161
158
|
if (element &&
|
|
162
159
|
element._owner &&
|
|
163
160
|
element._owner !== ReactCurrentOwner.current) {
|
|
164
161
|
// Name of the component that originally created this child.
|
|
165
|
-
childOwnerName = getName(element._owner);
|
|
162
|
+
var childOwnerName = getName(element._owner);
|
|
166
163
|
|
|
167
|
-
|
|
164
|
+
childOwnerAddendum = (" It was passed a child from " + childOwnerName + ".");
|
|
168
165
|
}
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Log that we're using an object map. We're considering deprecating this
|
|
180
|
-
* feature and replace it with proper Map and ImmutableMap data structures.
|
|
181
|
-
*
|
|
182
|
-
* @internal
|
|
183
|
-
*/
|
|
184
|
-
function monitorUseOfObjectMap() {
|
|
185
|
-
var currentName = getCurrentOwnerDisplayName() || '';
|
|
186
|
-
if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
ownerHasMonitoredObjectMap[currentName] = true;
|
|
190
|
-
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);
|
|
191
173
|
}
|
|
192
174
|
|
|
193
175
|
/**
|
|
@@ -213,19 +195,21 @@ function validateChildKeys(node, parentType) {
|
|
|
213
195
|
} else if (node) {
|
|
214
196
|
var iteratorFn = getIteratorFn(node);
|
|
215
197
|
// Entry iterators provide implicit keys.
|
|
216
|
-
if (iteratorFn
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
}
|
|
222
206
|
}
|
|
223
207
|
}
|
|
224
208
|
} else if (typeof node === 'object') {
|
|
225
|
-
|
|
226
|
-
for (var key in
|
|
227
|
-
if (
|
|
228
|
-
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);
|
|
229
213
|
}
|
|
230
214
|
}
|
|
231
215
|
}
|
|
@@ -269,7 +253,7 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
269
253
|
loggedTypeFailures[error.message] = true;
|
|
270
254
|
|
|
271
255
|
var addendum = getDeclarationErrorAddendum(this);
|
|
272
|
-
("production" !== process.env.NODE_ENV ? warning(false, error.message
|
|
256
|
+
("production" !== process.env.NODE_ENV ? warning(false, 'Failed propType: %s%s', error.message, addendum) : null);
|
|
273
257
|
}
|
|
274
258
|
}
|
|
275
259
|
}
|
|
@@ -315,6 +299,19 @@ function warnForPropsMutation(propName, element) {
|
|
|
315
299
|
) : null);
|
|
316
300
|
}
|
|
317
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
|
+
|
|
318
315
|
/**
|
|
319
316
|
* Given an element, check if its props have been mutated since element
|
|
320
317
|
* creation (or the last call to this function). In particular, check if any
|
|
@@ -336,7 +333,7 @@ function checkAndWarnForMutatedProps(element) {
|
|
|
336
333
|
for (var propName in props) {
|
|
337
334
|
if (props.hasOwnProperty(propName)) {
|
|
338
335
|
if (!originalProps.hasOwnProperty(propName) ||
|
|
339
|
-
originalProps[propName]
|
|
336
|
+
!is(originalProps[propName], props[propName])) {
|
|
340
337
|
warnForPropsMutation(propName, element);
|
|
341
338
|
|
|
342
339
|
// Copy over the new value so that the two props objects match again
|
|
@@ -346,6 +343,42 @@ function checkAndWarnForMutatedProps(element) {
|
|
|
346
343
|
}
|
|
347
344
|
}
|
|
348
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
|
+
|
|
349
382
|
var ReactElementValidator = {
|
|
350
383
|
|
|
351
384
|
checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
|
|
@@ -372,33 +405,7 @@ var ReactElementValidator = {
|
|
|
372
405
|
validateChildKeys(arguments[i], type);
|
|
373
406
|
}
|
|
374
407
|
|
|
375
|
-
|
|
376
|
-
// Extract the component class from the element. Converts string types
|
|
377
|
-
// to a composite class which may have propTypes.
|
|
378
|
-
// TODO: Validating a string's propTypes is not decoupled from the
|
|
379
|
-
// rendering target which is problematic.
|
|
380
|
-
var componentClass = ReactNativeComponent.getComponentClassForElement(
|
|
381
|
-
element
|
|
382
|
-
);
|
|
383
|
-
var name = componentClass.displayName || componentClass.name;
|
|
384
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
385
|
-
if (componentClass.propTypes) {
|
|
386
|
-
checkPropTypes(
|
|
387
|
-
name,
|
|
388
|
-
componentClass.propTypes,
|
|
389
|
-
element.props,
|
|
390
|
-
ReactPropTypeLocations.prop
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
if (typeof componentClass.getDefaultProps === 'function') {
|
|
395
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
396
|
-
componentClass.getDefaultProps.isReactClassApproved,
|
|
397
|
-
'getDefaultProps is only used on classic React.createClass ' +
|
|
398
|
-
'definitions. Use a static property named `defaultProps` instead.'
|
|
399
|
-
) : null);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
408
|
+
validatePropTypes(element);
|
|
402
409
|
|
|
403
410
|
return element;
|
|
404
411
|
},
|
|
@@ -410,7 +417,43 @@ var ReactElementValidator = {
|
|
|
410
417
|
);
|
|
411
418
|
// Legacy hook TODO: Warn if this is accessed
|
|
412
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
|
+
|
|
413
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;
|
|
414
457
|
}
|
|
415
458
|
|
|
416
459
|
};
|
|
@@ -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,7 +19,7 @@ var invariant = require("./invariant");
|
|
|
19
19
|
var component;
|
|
20
20
|
// This registry keeps track of the React IDs of the components that rendered to
|
|
21
21
|
// `null` (in reality a placeholder such as `noscript`)
|
|
22
|
-
var
|
|
22
|
+
var nullComponentIDsRegistry = {};
|
|
23
23
|
|
|
24
24
|
var ReactEmptyComponentInjection = {
|
|
25
25
|
injectEmptyComponent: function(emptyComponent) {
|
|
@@ -63,7 +63,7 @@ var emptyElement = ReactElement.createElement(ReactEmptyComponentType);
|
|
|
63
63
|
* @param {string} id Component's `_rootNodeID`.
|
|
64
64
|
*/
|
|
65
65
|
function registerNullComponentID(id) {
|
|
66
|
-
|
|
66
|
+
nullComponentIDsRegistry[id] = true;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -71,7 +71,7 @@ function registerNullComponentID(id) {
|
|
|
71
71
|
* @param {string} id Component's `_rootNodeID`.
|
|
72
72
|
*/
|
|
73
73
|
function deregisterNullComponentID(id) {
|
|
74
|
-
delete
|
|
74
|
+
delete nullComponentIDsRegistry[id];
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -79,7 +79,7 @@ function deregisterNullComponentID(id) {
|
|
|
79
79
|
* @return {boolean} True if the component is rendered to null.
|
|
80
80
|
*/
|
|
81
81
|
function isNullComponentID(id) {
|
|
82
|
-
return !!
|
|
82
|
+
return !!nullComponentIDsRegistry[id];
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
var ReactEmptyComponent = {
|
package/lib/ReactErrorUtils.js
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2015, 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 ReactFragment
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactElement = require("./ReactElement");
|
|
15
|
+
|
|
16
|
+
var warning = require("./warning");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* We used to allow keyed objects to serve as a collection of ReactElements,
|
|
20
|
+
* or nested sets. This allowed us a way to explicitly key a set a fragment of
|
|
21
|
+
* components. This is now being replaced with an opaque data structure.
|
|
22
|
+
* The upgrade path is to call React.addons.createFragment({ key: value }) to
|
|
23
|
+
* create a keyed fragment. The resulting data structure is opaque, for now.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
27
|
+
var fragmentKey = '_reactFragment';
|
|
28
|
+
var didWarnKey = '_reactDidWarn';
|
|
29
|
+
var canWarnForReactFragment = false;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Feature test. Don't even try to issue this warning if we can't use
|
|
33
|
+
// enumerable: false.
|
|
34
|
+
|
|
35
|
+
var dummy = function() {
|
|
36
|
+
return 1;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Object.defineProperty(
|
|
40
|
+
{},
|
|
41
|
+
fragmentKey,
|
|
42
|
+
{enumerable: false, value: true}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
Object.defineProperty(
|
|
46
|
+
{},
|
|
47
|
+
'key',
|
|
48
|
+
{enumerable: true, get: dummy}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
canWarnForReactFragment = true;
|
|
52
|
+
} catch (x) { }
|
|
53
|
+
|
|
54
|
+
var proxyPropertyAccessWithWarning = function(obj, key) {
|
|
55
|
+
Object.defineProperty(obj, key, {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function() {
|
|
58
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
59
|
+
this[didWarnKey],
|
|
60
|
+
'A ReactFragment is an opaque type. Accessing any of its ' +
|
|
61
|
+
'properties is deprecated. Pass it to one of the React.Children ' +
|
|
62
|
+
'helpers.'
|
|
63
|
+
) : null);
|
|
64
|
+
this[didWarnKey] = true;
|
|
65
|
+
return this[fragmentKey][key];
|
|
66
|
+
},
|
|
67
|
+
set: function(value) {
|
|
68
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
69
|
+
this[didWarnKey],
|
|
70
|
+
'A ReactFragment is an immutable opaque type. Mutating its ' +
|
|
71
|
+
'properties is deprecated.'
|
|
72
|
+
) : null);
|
|
73
|
+
this[didWarnKey] = true;
|
|
74
|
+
this[fragmentKey][key] = value;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
var issuedWarnings = {};
|
|
80
|
+
|
|
81
|
+
var didWarnForFragment = function(fragment) {
|
|
82
|
+
// We use the keys and the type of the value as a heuristic to dedupe the
|
|
83
|
+
// warning to avoid spamming too much.
|
|
84
|
+
var fragmentCacheKey = '';
|
|
85
|
+
for (var key in fragment) {
|
|
86
|
+
fragmentCacheKey += key + ':' + (typeof fragment[key]) + ',';
|
|
87
|
+
}
|
|
88
|
+
var alreadyWarnedOnce = !!issuedWarnings[fragmentCacheKey];
|
|
89
|
+
issuedWarnings[fragmentCacheKey] = true;
|
|
90
|
+
return alreadyWarnedOnce;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var ReactFragment = {
|
|
95
|
+
// Wrap a keyed object in an opaque proxy that warns you if you access any
|
|
96
|
+
// of its properties.
|
|
97
|
+
create: function(object) {
|
|
98
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
99
|
+
if (typeof object !== 'object' || !object || Array.isArray(object)) {
|
|
100
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
101
|
+
false,
|
|
102
|
+
'React.addons.createFragment only accepts a single object.',
|
|
103
|
+
object
|
|
104
|
+
) : null);
|
|
105
|
+
return object;
|
|
106
|
+
}
|
|
107
|
+
if (ReactElement.isValidElement(object)) {
|
|
108
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
109
|
+
false,
|
|
110
|
+
'React.addons.createFragment does not accept a ReactElement ' +
|
|
111
|
+
'without a wrapper object.'
|
|
112
|
+
) : null);
|
|
113
|
+
return object;
|
|
114
|
+
}
|
|
115
|
+
if (canWarnForReactFragment) {
|
|
116
|
+
var proxy = {};
|
|
117
|
+
Object.defineProperty(proxy, fragmentKey, {
|
|
118
|
+
enumerable: false,
|
|
119
|
+
value: object
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(proxy, didWarnKey, {
|
|
122
|
+
writable: true,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
value: false
|
|
125
|
+
});
|
|
126
|
+
for (var key in object) {
|
|
127
|
+
proxyPropertyAccessWithWarning(proxy, key);
|
|
128
|
+
}
|
|
129
|
+
Object.preventExtensions(proxy);
|
|
130
|
+
return proxy;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return object;
|
|
134
|
+
},
|
|
135
|
+
// Extract the original keyed object from the fragment opaque type. Warn if
|
|
136
|
+
// a plain object is passed here.
|
|
137
|
+
extract: function(fragment) {
|
|
138
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
139
|
+
if (canWarnForReactFragment) {
|
|
140
|
+
if (!fragment[fragmentKey]) {
|
|
141
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
142
|
+
didWarnForFragment(fragment),
|
|
143
|
+
'Any use of a keyed object should be wrapped in ' +
|
|
144
|
+
'React.addons.createFragment(object) before being passed as a ' +
|
|
145
|
+
'child.'
|
|
146
|
+
) : null);
|
|
147
|
+
return fragment;
|
|
148
|
+
}
|
|
149
|
+
return fragment[fragmentKey];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return fragment;
|
|
153
|
+
},
|
|
154
|
+
// Check if this is a fragment and if so, extract the keyed object. If it
|
|
155
|
+
// is a fragment-like object, warn that it should be wrapped. Ignore if we
|
|
156
|
+
// can't determine what kind of object this is.
|
|
157
|
+
extractIfFragment: function(fragment) {
|
|
158
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
159
|
+
if (canWarnForReactFragment) {
|
|
160
|
+
// If it is the opaque type, return the keyed object.
|
|
161
|
+
if (fragment[fragmentKey]) {
|
|
162
|
+
return fragment[fragmentKey];
|
|
163
|
+
}
|
|
164
|
+
// Otherwise, check each property if it has an element, if it does
|
|
165
|
+
// it is probably meant as a fragment, so we can warn early. Defer,
|
|
166
|
+
// the warning to extract.
|
|
167
|
+
for (var key in fragment) {
|
|
168
|
+
if (fragment.hasOwnProperty(key) &&
|
|
169
|
+
ReactElement.isValidElement(fragment[key])) {
|
|
170
|
+
// This looks like a fragment object, we should provide an
|
|
171
|
+
// early warning.
|
|
172
|
+
return ReactFragment.extract(fragment);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return fragment;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
module.exports = ReactFragment;
|