react 0.13.0-alpha.1 → 0.13.0-rc1
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 +1376 -596
- package/dist/react-with-addons.js +3256 -2363
- package/dist/react-with-addons.min.js +7 -7
- package/dist/react.js +3092 -2266
- package/dist/react.min.js +6 -7
- package/lib/AutoFocusMixin.js +2 -2
- package/lib/BeforeInputEventPlugin.js +5 -9
- package/lib/CSSCore.js +1 -1
- package/lib/CSSProperty.js +4 -2
- package/lib/CSSPropertyOperations.js +44 -17
- package/lib/CallbackQueue.js +3 -3
- package/lib/ChangeEventPlugin.js +2 -2
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +10 -47
- package/lib/DOMProperty.js +2 -2
- package/lib/DOMPropertyOperations.js +11 -16
- package/lib/Danger.js +7 -6
- package/lib/DefaultEventPluginOrder.js +3 -3
- package/lib/EnterLeaveEventPlugin.js +2 -2
- package/lib/EventConstants.js +2 -2
- package/lib/EventListener.js +1 -1
- package/lib/EventPluginHub.js +10 -8
- package/lib/EventPluginRegistry.js +2 -2
- package/lib/EventPluginUtils.js +4 -4
- package/lib/EventPropagators.js +2 -2
- package/lib/ExecutionEnvironment.js +1 -1
- package/lib/FallbackCompositionState.js +7 -5
- package/lib/HTMLDOMPropertyConfig.js +22 -10
- package/lib/LinkedStateMixin.js +2 -2
- package/lib/LinkedValueUtils.js +4 -4
- package/lib/LocalEventTrapMixin.js +10 -3
- package/lib/MobileSafariClickEventPlugin.js +2 -2
- package/lib/Object.assign.js +2 -2
- package/lib/PooledClass.js +2 -2
- package/lib/React.js +9 -13
- package/lib/ReactBrowserComponentMixin.js +2 -2
- package/lib/ReactBrowserEventEmitter.js +4 -4
- package/lib/ReactCSSTransitionGroup.js +2 -2
- package/lib/ReactCSSTransitionGroupChild.js +12 -7
- package/lib/ReactChildReconciler.js +11 -7
- package/lib/ReactChildren.js +13 -10
- package/lib/ReactClass.js +161 -135
- package/lib/ReactComponent.js +100 -158
- package/lib/ReactComponentBrowserEnvironment.js +2 -2
- package/lib/ReactComponentEnvironment.js +3 -3
- package/lib/ReactComponentWithPureRenderMixin.js +2 -2
- package/lib/ReactCompositeComponent.js +336 -484
- package/lib/ReactContext.js +14 -4
- package/lib/ReactCurrentOwner.js +2 -2
- package/lib/ReactDOM.js +2 -2
- package/lib/ReactDOMButton.js +2 -2
- package/lib/ReactDOMComponent.js +42 -52
- package/lib/ReactDOMForm.js +2 -2
- package/lib/ReactDOMIDOperations.js +4 -4
- package/lib/ReactDOMIframe.js +43 -0
- package/lib/ReactDOMImg.js +2 -2
- package/lib/ReactDOMInput.js +2 -2
- package/lib/ReactDOMOption.js +2 -2
- package/lib/ReactDOMSelect.js +3 -3
- package/lib/ReactDOMSelection.js +2 -2
- package/lib/ReactDOMTextComponent.js +4 -13
- package/lib/ReactDOMTextarea.js +2 -2
- package/lib/ReactDefaultBatchingStrategy.js +5 -5
- package/lib/ReactDefaultInjection.js +26 -2
- package/lib/ReactDefaultPerf.js +12 -4
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +7 -5
- package/lib/ReactElementValidator.js +185 -65
- package/lib/ReactEmptyComponent.js +17 -6
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +2 -2
- package/lib/ReactEventListener.js +4 -5
- package/lib/ReactFragment.js +180 -0
- package/lib/ReactInjection.js +2 -2
- package/lib/ReactInputSelection.js +2 -2
- package/lib/ReactInstanceHandles.js +4 -3
- package/lib/ReactInstanceMap.js +2 -2
- package/lib/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +2 -2
- package/lib/ReactMarkupChecksum.js +2 -2
- package/lib/ReactMount.js +87 -23
- package/lib/ReactMultiChild.js +19 -7
- package/lib/ReactMultiChildUpdateTypes.js +2 -2
- package/lib/ReactNativeComponent.js +34 -37
- package/lib/ReactOwner.js +2 -2
- package/lib/ReactPerf.js +2 -2
- package/lib/ReactPropTransferer.js +3 -3
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +2 -2
- package/lib/ReactPropTypes.js +16 -8
- package/lib/ReactPutListenerQueue.js +2 -2
- package/lib/ReactReconcileTransaction.js +2 -2
- package/lib/ReactReconciler.js +121 -0
- package/lib/ReactRef.js +41 -68
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +4 -3
- package/lib/ReactServerRenderingTransaction.js +2 -2
- package/lib/ReactStateSetters.js +2 -2
- package/lib/ReactTestUtils.js +49 -8
- package/lib/ReactTransitionChildMapping.js +8 -4
- package/lib/ReactTransitionEvents.js +2 -2
- package/lib/ReactTransitionGroup.js +6 -6
- package/lib/ReactUpdateQueue.js +295 -0
- package/lib/ReactUpdates.js +13 -22
- package/lib/ReactWithAddons.js +4 -2
- package/lib/SVGDOMPropertyConfig.js +2 -2
- package/lib/SelectEventPlugin.js +4 -4
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +4 -4
- package/lib/SyntheticClipboardEvent.js +2 -3
- package/lib/SyntheticCompositionEvent.js +2 -3
- package/lib/SyntheticDragEvent.js +2 -2
- package/lib/SyntheticEvent.js +12 -4
- package/lib/SyntheticFocusEvent.js +2 -2
- package/lib/SyntheticInputEvent.js +2 -3
- package/lib/SyntheticKeyboardEvent.js +2 -2
- package/lib/SyntheticMouseEvent.js +2 -2
- package/lib/SyntheticTouchEvent.js +2 -2
- package/lib/SyntheticUIEvent.js +2 -2
- package/lib/SyntheticWheelEvent.js +2 -2
- package/lib/Transaction.js +5 -5
- package/lib/ViewportMetrics.js +2 -2
- package/lib/accumulateInto.js +2 -2
- package/lib/adler32.js +2 -2
- 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 +2 -2
- package/lib/createNodesFromMarkup.js +4 -4
- package/lib/cx.js +16 -1
- package/lib/dangerousStyleValue.js +2 -2
- package/lib/emptyFunction.js +1 -1
- package/lib/emptyObject.js +1 -1
- package/lib/{escapeTextForBrowser.js → escapeTextContentForBrowser.js} +10 -11
- package/lib/findDOMNode.js +26 -9
- package/lib/flattenChildren.js +11 -9
- package/lib/focusNode.js +1 -1
- package/lib/forEachAccumulated.js +2 -2
- package/lib/getActiveElement.js +1 -1
- package/lib/getEventCharCode.js +2 -2
- package/lib/getEventKey.js +2 -2
- package/lib/getEventModifierState.js +2 -2
- package/lib/getEventTarget.js +2 -2
- package/lib/getIteratorFn.js +2 -2
- package/lib/getMarkupWrap.js +1 -1
- package/lib/getNodeForCharacterOffset.js +3 -3
- package/lib/getReactRootElementInContainer.js +2 -2
- package/lib/getTextContentAccessor.js +2 -2
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +1 -1
- package/lib/hyphenateStyleName.js +1 -1
- package/lib/instantiateReactComponent.js +21 -21
- package/lib/invariant.js +1 -1
- package/lib/isEventSupported.js +2 -2
- package/lib/isNode.js +1 -1
- package/lib/isTextInputElement.js +2 -2
- package/lib/isTextNode.js +1 -1
- package/lib/joinClasses.js +2 -2
- package/lib/keyMirror.js +2 -2
- package/lib/keyOf.js +1 -1
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +5 -6
- package/lib/onlyChild.js +2 -2
- package/lib/performance.js +1 -1
- package/lib/performanceNow.js +1 -1
- package/lib/quoteAttributeValueForBrowser.js +26 -0
- package/lib/setInnerHTML.js +13 -2
- package/lib/setTextContent.js +40 -0
- package/lib/shallowEqual.js +2 -2
- package/lib/shouldUpdateReactComponent.js +64 -8
- package/lib/toArray.js +2 -2
- package/lib/traverseAllChildren.js +19 -5
- package/lib/update.js +2 -2
- package/lib/warning.js +20 -2
- package/package.json +1 -1
- 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
|
@@ -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
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @typechecks static-only
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var DOMPropertyOperations = require("./DOMPropertyOperations");
|
|
16
16
|
var ReactComponentBrowserEnvironment =
|
|
@@ -18,8 +18,7 @@ var ReactComponentBrowserEnvironment =
|
|
|
18
18
|
var ReactDOMComponent = require("./ReactDOMComponent");
|
|
19
19
|
|
|
20
20
|
var assign = require("./Object.assign");
|
|
21
|
-
var
|
|
22
|
-
var invariant = require("./invariant");
|
|
21
|
+
var escapeTextContentForBrowser = require("./escapeTextContentForBrowser");
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* Text nodes violate a couple assumptions that React makes about components:
|
|
@@ -67,7 +66,7 @@ assign(ReactDOMTextComponent.prototype, {
|
|
|
67
66
|
*/
|
|
68
67
|
mountComponent: function(rootID, transaction, context) {
|
|
69
68
|
this._rootNodeID = rootID;
|
|
70
|
-
var escapedText =
|
|
69
|
+
var escapedText = escapeTextContentForBrowser(this._stringText);
|
|
71
70
|
|
|
72
71
|
if (transaction.renderToStaticMarkup) {
|
|
73
72
|
// Normally we'd wrap this in a `span` for the reasons stated above, but
|
|
@@ -107,15 +106,7 @@ assign(ReactDOMTextComponent.prototype, {
|
|
|
107
106
|
}
|
|
108
107
|
},
|
|
109
108
|
|
|
110
|
-
updateComponent: function() {
|
|
111
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
112
|
-
false,
|
|
113
|
-
'ReactDOMTextComponent: updateComponent() should never be called'
|
|
114
|
-
) : invariant(false));
|
|
115
|
-
},
|
|
116
|
-
|
|
117
109
|
unmountComponent: function() {
|
|
118
|
-
// TODO: Is this necessary?
|
|
119
110
|
ReactComponentBrowserEnvironment.unmountIDFromEnvironment(this._rootNodeID);
|
|
120
111
|
}
|
|
121
112
|
|
package/lib/ReactDOMTextarea.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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactDOMTextarea
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var AutoFocusMixin = require("./AutoFocusMixin");
|
|
15
15
|
var DOMPropertyOperations = require("./DOMPropertyOperations");
|
|
@@ -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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactDefaultBatchingStrategy
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactUpdates = require("./ReactUpdates");
|
|
15
15
|
var Transaction = require("./Transaction");
|
|
@@ -54,16 +54,16 @@ var ReactDefaultBatchingStrategy = {
|
|
|
54
54
|
* Call the provided function in a context within which calls to `setState`
|
|
55
55
|
* and friends are batched such that components aren't updated unnecessarily.
|
|
56
56
|
*/
|
|
57
|
-
batchedUpdates: function(callback, a, b) {
|
|
57
|
+
batchedUpdates: function(callback, a, b, c, d) {
|
|
58
58
|
var alreadyBatchingUpdates = ReactDefaultBatchingStrategy.isBatchingUpdates;
|
|
59
59
|
|
|
60
60
|
ReactDefaultBatchingStrategy.isBatchingUpdates = true;
|
|
61
61
|
|
|
62
62
|
// The code is written this way to avoid extra allocations
|
|
63
63
|
if (alreadyBatchingUpdates) {
|
|
64
|
-
callback(a, b);
|
|
64
|
+
callback(a, b, c, d);
|
|
65
65
|
} else {
|
|
66
|
-
transaction.perform(callback, null, a, b);
|
|
66
|
+
transaction.perform(callback, null, a, b, c, d);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
};
|
|
@@ -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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactDefaultInjection
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var BeforeInputEventPlugin = require("./BeforeInputEventPlugin");
|
|
15
15
|
var ChangeEventPlugin = require("./ChangeEventPlugin");
|
|
@@ -20,6 +20,7 @@ var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
|
20
20
|
var HTMLDOMPropertyConfig = require("./HTMLDOMPropertyConfig");
|
|
21
21
|
var MobileSafariClickEventPlugin = require("./MobileSafariClickEventPlugin");
|
|
22
22
|
var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
|
|
23
|
+
var ReactClass = require("./ReactClass");
|
|
23
24
|
var ReactComponentBrowserEnvironment =
|
|
24
25
|
require("./ReactComponentBrowserEnvironment");
|
|
25
26
|
var ReactDefaultBatchingStrategy = require("./ReactDefaultBatchingStrategy");
|
|
@@ -28,11 +29,13 @@ var ReactDOMButton = require("./ReactDOMButton");
|
|
|
28
29
|
var ReactDOMForm = require("./ReactDOMForm");
|
|
29
30
|
var ReactDOMImg = require("./ReactDOMImg");
|
|
30
31
|
var ReactDOMIDOperations = require("./ReactDOMIDOperations");
|
|
32
|
+
var ReactDOMIframe = require("./ReactDOMIframe");
|
|
31
33
|
var ReactDOMInput = require("./ReactDOMInput");
|
|
32
34
|
var ReactDOMOption = require("./ReactDOMOption");
|
|
33
35
|
var ReactDOMSelect = require("./ReactDOMSelect");
|
|
34
36
|
var ReactDOMTextarea = require("./ReactDOMTextarea");
|
|
35
37
|
var ReactDOMTextComponent = require("./ReactDOMTextComponent");
|
|
38
|
+
var ReactElement = require("./ReactElement");
|
|
36
39
|
var ReactEventListener = require("./ReactEventListener");
|
|
37
40
|
var ReactInjection = require("./ReactInjection");
|
|
38
41
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
@@ -45,6 +48,22 @@ var SVGDOMPropertyConfig = require("./SVGDOMPropertyConfig");
|
|
|
45
48
|
|
|
46
49
|
var createFullPageComponent = require("./createFullPageComponent");
|
|
47
50
|
|
|
51
|
+
function autoGenerateWrapperClass(type) {
|
|
52
|
+
return ReactClass.createClass({
|
|
53
|
+
tagName: type.toUpperCase(),
|
|
54
|
+
render: function() {
|
|
55
|
+
return new ReactElement(
|
|
56
|
+
type,
|
|
57
|
+
null,
|
|
58
|
+
null,
|
|
59
|
+
null,
|
|
60
|
+
null,
|
|
61
|
+
this.props
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
function inject() {
|
|
49
68
|
ReactInjection.EventEmitter.injectReactEventListener(
|
|
50
69
|
ReactEventListener
|
|
@@ -78,6 +97,10 @@ function inject() {
|
|
|
78
97
|
ReactDOMTextComponent
|
|
79
98
|
);
|
|
80
99
|
|
|
100
|
+
ReactInjection.NativeComponent.injectAutoWrapper(
|
|
101
|
+
autoGenerateWrapperClass
|
|
102
|
+
);
|
|
103
|
+
|
|
81
104
|
// This needs to happen before createFullPageComponent() otherwise the mixin
|
|
82
105
|
// won't be included.
|
|
83
106
|
ReactInjection.Class.injectMixin(ReactBrowserComponentMixin);
|
|
@@ -85,6 +108,7 @@ function inject() {
|
|
|
85
108
|
ReactInjection.NativeComponent.injectComponentClasses({
|
|
86
109
|
'button': ReactDOMButton,
|
|
87
110
|
'form': ReactDOMForm,
|
|
111
|
+
'iframe': ReactDOMIframe,
|
|
88
112
|
'img': ReactDOMImg,
|
|
89
113
|
'input': ReactDOMInput,
|
|
90
114
|
'option': ReactDOMOption,
|
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
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @typechecks static-only
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var DOMProperty = require("./DOMProperty");
|
|
16
16
|
var ReactDefaultPerfAnalysis = require("./ReactDefaultPerfAnalysis");
|
|
@@ -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
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
* @providesModule ReactElement
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactContext = require("./ReactContext");
|
|
15
15
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
16
16
|
|
|
17
|
+
var assign = require("./Object.assign");
|
|
17
18
|
var warning = require("./warning");
|
|
18
19
|
|
|
19
20
|
var RESERVED_PROPS = {
|
|
@@ -44,8 +45,9 @@ function defineWarningProperty(object, key) {
|
|
|
44
45
|
set: function(value) {
|
|
45
46
|
("production" !== process.env.NODE_ENV ? warning(
|
|
46
47
|
false,
|
|
47
|
-
'Don\'t set the
|
|
48
|
-
'
|
|
48
|
+
'Don\'t set the %s property of the React element. Instead, ' +
|
|
49
|
+
'specify the correct value when initially creating the element.',
|
|
50
|
+
key
|
|
49
51
|
) : null);
|
|
50
52
|
this._store[key] = value;
|
|
51
53
|
}
|
|
@@ -106,7 +108,7 @@ var ReactElement = function(type, key, ref, owner, context, props) {
|
|
|
106
108
|
// an external backing store so that we can freeze the whole object.
|
|
107
109
|
// This can be replaced with a WeakMap once they are implemented in
|
|
108
110
|
// commonly used development environments.
|
|
109
|
-
this._store = {
|
|
111
|
+
this._store = {props: props, originalProps: assign({}, props)};
|
|
110
112
|
|
|
111
113
|
// To make comparing ReactElements easier for testing purposes, we make
|
|
112
114
|
// the validation flag non-enumerable (where possible, which should
|
|
@@ -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
|
|
@@ -16,26 +16,35 @@
|
|
|
16
16
|
* that support it.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
'use strict';
|
|
20
20
|
|
|
21
21
|
var ReactElement = require("./ReactElement");
|
|
22
|
+
var ReactFragment = require("./ReactFragment");
|
|
22
23
|
var ReactPropTypeLocations = require("./ReactPropTypeLocations");
|
|
24
|
+
var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
|
|
23
25
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
26
|
+
var ReactNativeComponent = require("./ReactNativeComponent");
|
|
24
27
|
|
|
25
28
|
var getIteratorFn = require("./getIteratorFn");
|
|
26
|
-
var
|
|
29
|
+
var invariant = require("./invariant");
|
|
27
30
|
var warning = require("./warning");
|
|
28
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
|
+
|
|
29
42
|
/**
|
|
30
43
|
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
31
44
|
* object keys are not valid. This allows us to keep track of children between
|
|
32
45
|
* updates.
|
|
33
46
|
*/
|
|
34
|
-
var ownerHasKeyUseWarning = {
|
|
35
|
-
'react_key_warning': {},
|
|
36
|
-
'react_numeric_key_warning': {}
|
|
37
|
-
};
|
|
38
|
-
var ownerHasMonitoredObjectMap = {};
|
|
47
|
+
var ownerHasKeyUseWarning = {};
|
|
39
48
|
|
|
40
49
|
var loggedTypeFailures = {};
|
|
41
50
|
|
|
@@ -89,7 +98,6 @@ function validateExplicitKey(element, parentType) {
|
|
|
89
98
|
element._store.validated = true;
|
|
90
99
|
|
|
91
100
|
warnAndMonitorForKeyUse(
|
|
92
|
-
'react_key_warning',
|
|
93
101
|
'Each child in an array or iterator should have a unique "key" prop.',
|
|
94
102
|
element,
|
|
95
103
|
parentType
|
|
@@ -110,7 +118,6 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
110
118
|
return;
|
|
111
119
|
}
|
|
112
120
|
warnAndMonitorForKeyUse(
|
|
113
|
-
'react_numeric_key_warning',
|
|
114
121
|
'Child objects should have non-numeric keys so ordering is preserved.',
|
|
115
122
|
element,
|
|
116
123
|
parentType
|
|
@@ -121,17 +128,18 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
121
128
|
* Shared warning and monitoring code for the key warnings.
|
|
122
129
|
*
|
|
123
130
|
* @internal
|
|
124
|
-
* @param {string} warningID The id used when logging.
|
|
125
131
|
* @param {string} message The base warning that gets output.
|
|
126
132
|
* @param {ReactElement} element Component that requires a key.
|
|
127
133
|
* @param {*} parentType element's parent's type.
|
|
128
134
|
*/
|
|
129
|
-
function warnAndMonitorForKeyUse(
|
|
135
|
+
function warnAndMonitorForKeyUse(message, element, parentType) {
|
|
130
136
|
var ownerName = getCurrentOwnerDisplayName();
|
|
131
137
|
var parentName = parentType.displayName || parentType.name;
|
|
132
138
|
|
|
133
139
|
var useName = ownerName || parentName;
|
|
134
|
-
var memoizer = ownerHasKeyUseWarning[
|
|
140
|
+
var memoizer = ownerHasKeyUseWarning[message] || (
|
|
141
|
+
(ownerHasKeyUseWarning[message] = {})
|
|
142
|
+
);
|
|
135
143
|
if (memoizer.hasOwnProperty(useName)) {
|
|
136
144
|
return;
|
|
137
145
|
}
|
|
@@ -144,37 +152,17 @@ function warnAndMonitorForKeyUse(warningID, message, element, parentType) {
|
|
|
144
152
|
// Usually the current owner is the offender, but if it accepts children as a
|
|
145
153
|
// property, it may be the creator of the child that's responsible for
|
|
146
154
|
// assigning it a key.
|
|
147
|
-
var childOwnerName = null;
|
|
148
155
|
if (element &&
|
|
149
156
|
element._owner &&
|
|
150
157
|
element._owner !== ReactCurrentOwner.current) {
|
|
151
158
|
// Name of the component that originally created this child.
|
|
152
|
-
childOwnerName = getName(element._owner);
|
|
159
|
+
var childOwnerName = getName(element._owner);
|
|
153
160
|
|
|
154
161
|
message += (" It was passed a child from " + childOwnerName + ".");
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
message += ' See http://fb.me/react-warning-keys for more information.';
|
|
158
|
-
|
|
159
|
-
component: useName,
|
|
160
|
-
componentOwner: childOwnerName
|
|
161
|
-
});
|
|
162
|
-
console.warn(message);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Log that we're using an object map. We're considering deprecating this
|
|
167
|
-
* feature and replace it with proper Map and ImmutableMap data structures.
|
|
168
|
-
*
|
|
169
|
-
* @internal
|
|
170
|
-
*/
|
|
171
|
-
function monitorUseOfObjectMap() {
|
|
172
|
-
var currentName = getCurrentOwnerDisplayName() || '';
|
|
173
|
-
if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
ownerHasMonitoredObjectMap[currentName] = true;
|
|
177
|
-
monitorCodeUse('react_object_map_children');
|
|
165
|
+
("production" !== process.env.NODE_ENV ? warning(false, message) : null);
|
|
178
166
|
}
|
|
179
167
|
|
|
180
168
|
/**
|
|
@@ -200,19 +188,21 @@ function validateChildKeys(node, parentType) {
|
|
|
200
188
|
} else if (node) {
|
|
201
189
|
var iteratorFn = getIteratorFn(node);
|
|
202
190
|
// Entry iterators provide implicit keys.
|
|
203
|
-
if (iteratorFn
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
191
|
+
if (iteratorFn) {
|
|
192
|
+
if (iteratorFn !== node.entries) {
|
|
193
|
+
var iterator = iteratorFn.call(node);
|
|
194
|
+
var step;
|
|
195
|
+
while (!(step = iterator.next()).done) {
|
|
196
|
+
if (ReactElement.isValidElement(step.value)) {
|
|
197
|
+
validateExplicitKey(step.value, parentType);
|
|
198
|
+
}
|
|
209
199
|
}
|
|
210
200
|
}
|
|
211
201
|
} else if (typeof node === 'object') {
|
|
212
|
-
|
|
213
|
-
for (var key in
|
|
214
|
-
if (
|
|
215
|
-
validatePropertyKey(key,
|
|
202
|
+
var fragment = ReactFragment.extractIfFragment(node);
|
|
203
|
+
for (var key in fragment) {
|
|
204
|
+
if (fragment.hasOwnProperty(key)) {
|
|
205
|
+
validatePropertyKey(key, fragment[key], parentType);
|
|
216
206
|
}
|
|
217
207
|
}
|
|
218
208
|
}
|
|
@@ -236,6 +226,16 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
236
226
|
// fail the render phase where it didn't fail before. So we log it.
|
|
237
227
|
// After these have been cleaned up, we'll let them throw.
|
|
238
228
|
try {
|
|
229
|
+
// This is intentionally an invariant that gets caught. It's the same
|
|
230
|
+
// behavior as without this statement except with a better message.
|
|
231
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
232
|
+
typeof propTypes[propName] === 'function',
|
|
233
|
+
'%s: %s type `%s` is invalid; it must be a function, usually from ' +
|
|
234
|
+
'React.PropTypes.',
|
|
235
|
+
componentName || 'React class',
|
|
236
|
+
ReactPropTypeLocationNames[location],
|
|
237
|
+
propName
|
|
238
|
+
) : invariant(typeof propTypes[propName] === 'function'));
|
|
239
239
|
error = propTypes[propName](props, propName, componentName, location);
|
|
240
240
|
} catch (ex) {
|
|
241
241
|
error = ex;
|
|
@@ -244,11 +244,93 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
244
244
|
// Only monitor this failure once because there tends to be a lot of the
|
|
245
245
|
// same error.
|
|
246
246
|
loggedTypeFailures[error.message] = true;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
247
|
+
|
|
248
|
+
var addendum = getDeclarationErrorAddendum(this);
|
|
249
|
+
("production" !== process.env.NODE_ENV ? warning(false, 'Failed propType: ' + error.message + addendum) : null);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
var warnedPropsMutations = {};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Warn about mutating props when setting `propName` on `element`.
|
|
259
|
+
*
|
|
260
|
+
* @param {string} propName The string key within props that was set
|
|
261
|
+
* @param {ReactElement} element
|
|
262
|
+
*/
|
|
263
|
+
function warnForPropsMutation(propName, element) {
|
|
264
|
+
var type = element.type;
|
|
265
|
+
var elementName = typeof type === 'string' ? type : type.displayName;
|
|
266
|
+
var ownerName = element._owner ?
|
|
267
|
+
element._owner.getPublicInstance().constructor.displayName : null;
|
|
268
|
+
|
|
269
|
+
var warningKey = propName + '|' + elementName + '|' + ownerName;
|
|
270
|
+
if (warnedPropsMutations.hasOwnProperty(warningKey)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
warnedPropsMutations[warningKey] = true;
|
|
274
|
+
|
|
275
|
+
var elementInfo = '';
|
|
276
|
+
if (elementName) {
|
|
277
|
+
elementInfo = ' <' + elementName + ' />';
|
|
278
|
+
}
|
|
279
|
+
var ownerInfo = '';
|
|
280
|
+
if (ownerName) {
|
|
281
|
+
ownerInfo = ' The element was created by ' + ownerName + '.';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
285
|
+
false,
|
|
286
|
+
'Don\'t set .props.%s of the React component%s. ' +
|
|
287
|
+
'Instead, specify the correct value when ' +
|
|
288
|
+
'initially creating the element.%s',
|
|
289
|
+
propName,
|
|
290
|
+
elementInfo,
|
|
291
|
+
ownerInfo
|
|
292
|
+
) : null);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Inline Object.is polyfill
|
|
296
|
+
function is(a, b) {
|
|
297
|
+
if (a !== a) {
|
|
298
|
+
// NaN
|
|
299
|
+
return b !== b;
|
|
300
|
+
}
|
|
301
|
+
if (a === 0 && b === 0) {
|
|
302
|
+
// +-0
|
|
303
|
+
return 1 / a === 1 / b;
|
|
304
|
+
}
|
|
305
|
+
return a === b;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Given an element, check if its props have been mutated since element
|
|
310
|
+
* creation (or the last call to this function). In particular, check if any
|
|
311
|
+
* new props have been added, which we can't directly catch by defining warning
|
|
312
|
+
* properties on the props object.
|
|
313
|
+
*
|
|
314
|
+
* @param {ReactElement} element
|
|
315
|
+
*/
|
|
316
|
+
function checkAndWarnForMutatedProps(element) {
|
|
317
|
+
if (!element._store) {
|
|
318
|
+
// Element was created using `new ReactElement` directly or with
|
|
319
|
+
// `ReactElement.createElement`; skip mutation checking
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
var originalProps = element._store.originalProps;
|
|
324
|
+
var props = element.props;
|
|
325
|
+
|
|
326
|
+
for (var propName in props) {
|
|
327
|
+
if (props.hasOwnProperty(propName)) {
|
|
328
|
+
if (!originalProps.hasOwnProperty(propName) ||
|
|
329
|
+
!is(originalProps[propName], props[propName])) {
|
|
330
|
+
warnForPropsMutation(propName, element);
|
|
331
|
+
|
|
332
|
+
// Copy over the new value so that the two props objects match again
|
|
333
|
+
originalProps[propName] = props[propName];
|
|
252
334
|
}
|
|
253
335
|
}
|
|
254
336
|
}
|
|
@@ -256,6 +338,8 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
256
338
|
|
|
257
339
|
var ReactElementValidator = {
|
|
258
340
|
|
|
341
|
+
checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
|
|
342
|
+
|
|
259
343
|
createElement: function(type, props, children) {
|
|
260
344
|
// We warn in this case but don't throw. We expect the element creation to
|
|
261
345
|
// succeed and there will likely be errors in render.
|
|
@@ -279,24 +363,33 @@ var ReactElementValidator = {
|
|
|
279
363
|
}
|
|
280
364
|
|
|
281
365
|
if (type) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
366
|
+
// Extract the component class from the element. Converts string types
|
|
367
|
+
// to a composite class which may have propTypes.
|
|
368
|
+
// TODO: Validating a string's propTypes is not decoupled from the
|
|
369
|
+
// rendering target which is problematic.
|
|
370
|
+
var componentClass = ReactNativeComponent.getComponentClassForElement(
|
|
371
|
+
element
|
|
372
|
+
);
|
|
373
|
+
var name = componentClass.displayName || componentClass.name;
|
|
374
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
375
|
+
if (componentClass.propTypes) {
|
|
376
|
+
checkPropTypes(
|
|
377
|
+
name,
|
|
378
|
+
componentClass.propTypes,
|
|
379
|
+
element.props,
|
|
380
|
+
ReactPropTypeLocations.prop
|
|
381
|
+
);
|
|
382
|
+
}
|
|
290
383
|
}
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
);
|
|
384
|
+
if (typeof componentClass.getDefaultProps === 'function') {
|
|
385
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
386
|
+
componentClass.getDefaultProps.isReactClassApproved,
|
|
387
|
+
'getDefaultProps is only used on classic React.createClass ' +
|
|
388
|
+
'definitions. Use a static property named `defaultProps` instead.'
|
|
389
|
+
) : null);
|
|
298
390
|
}
|
|
299
391
|
}
|
|
392
|
+
|
|
300
393
|
return element;
|
|
301
394
|
},
|
|
302
395
|
|
|
@@ -307,6 +400,33 @@ var ReactElementValidator = {
|
|
|
307
400
|
);
|
|
308
401
|
// Legacy hook TODO: Warn if this is accessed
|
|
309
402
|
validatedFactory.type = type;
|
|
403
|
+
|
|
404
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
405
|
+
try {
|
|
406
|
+
Object.defineProperty(
|
|
407
|
+
validatedFactory,
|
|
408
|
+
'type',
|
|
409
|
+
{
|
|
410
|
+
enumerable: false,
|
|
411
|
+
get: function() {
|
|
412
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
413
|
+
false,
|
|
414
|
+
'Factory.type is deprecated. Access the class directly ' +
|
|
415
|
+
'before passing it to createFactory.'
|
|
416
|
+
) : null);
|
|
417
|
+
Object.defineProperty(this, 'type', {
|
|
418
|
+
value: type
|
|
419
|
+
});
|
|
420
|
+
return type;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
} catch (x) {
|
|
425
|
+
// IE will fail on defineProperty (es5-shim/sham too)
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
310
430
|
return validatedFactory;
|
|
311
431
|
}
|
|
312
432
|
|