react 0.12.2 → 0.13.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/JSXTransformer.js +986 -511
- package/dist/react-with-addons.js +6076 -4560
- package/dist/react-with-addons.min.js +6 -7
- package/dist/react.js +5386 -4170
- package/dist/react.min.js +6 -7
- package/lib/AutoFocusMixin.js +2 -2
- package/lib/BeforeInputEventPlugin.js +388 -115
- package/lib/CSSCore.js +1 -1
- package/lib/CSSProperty.js +2 -2
- package/lib/CSSPropertyOperations.js +58 -11
- package/lib/CallbackQueue.js +3 -3
- package/lib/ChangeEventPlugin.js +4 -4
- 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 +8 -7
- package/lib/DefaultEventPluginOrder.js +3 -4
- 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 +3 -4
- package/lib/FallbackCompositionState.js +89 -0
- package/lib/HTMLDOMPropertyConfig.js +23 -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 +4 -2
- package/lib/PooledClass.js +2 -2
- package/lib/React.js +19 -58
- package/lib/ReactBrowserComponentMixin.js +4 -14
- package/lib/ReactBrowserEventEmitter.js +6 -8
- package/lib/ReactCSSTransitionGroup.js +5 -2
- package/lib/ReactCSSTransitionGroupChild.js +20 -7
- package/lib/ReactChildReconciler.js +125 -0
- package/lib/ReactChildren.js +13 -10
- package/lib/ReactClass.js +918 -0
- package/lib/ReactComponent.js +98 -406
- package/lib/ReactComponentBrowserEnvironment.js +11 -84
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +2 -2
- package/lib/ReactCompositeComponent.js +574 -1140
- package/lib/ReactContext.js +17 -3
- package/lib/ReactCurrentOwner.js +2 -2
- package/lib/ReactDOM.js +4 -9
- package/lib/ReactDOMButton.js +6 -7
- package/lib/ReactDOMComponent.js +123 -105
- package/lib/ReactDOMForm.js +6 -7
- package/lib/ReactDOMIDOperations.js +59 -77
- package/lib/ReactDOMIframe.js +43 -0
- package/lib/ReactDOMImg.js +5 -7
- package/lib/ReactDOMInput.js +6 -7
- package/lib/ReactDOMOption.js +6 -7
- package/lib/ReactDOMSelect.js +58 -66
- package/lib/ReactDOMSelection.js +7 -3
- package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -37
- package/lib/ReactDOMTextarea.js +6 -7
- package/lib/ReactDefaultBatchingStrategy.js +5 -5
- package/lib/ReactDefaultInjection.js +39 -9
- package/lib/ReactDefaultPerf.js +17 -8
- package/lib/ReactDefaultPerfAnalysis.js +2 -2
- package/lib/ReactElement.js +23 -15
- package/lib/ReactElementValidator.js +206 -89
- package/lib/ReactEmptyComponent.js +33 -15
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +2 -2
- package/lib/ReactEventListener.js +4 -5
- package/lib/ReactFragment.js +172 -0
- package/lib/ReactInjection.js +8 -6
- package/lib/ReactInputSelection.js +4 -5
- package/lib/ReactInstanceHandles.js +4 -3
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +2 -2
- package/lib/ReactMarkupChecksum.js +2 -2
- package/lib/ReactMount.js +264 -71
- package/lib/ReactMultiChild.js +50 -48
- package/lib/ReactMultiChildUpdateTypes.js +2 -2
- package/lib/ReactNativeComponent.js +59 -25
- package/lib/ReactOwner.js +5 -49
- package/lib/ReactPerf.js +22 -2
- package/lib/ReactPropTransferer.js +3 -58
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +2 -2
- package/lib/ReactPropTypes.js +17 -25
- package/lib/ReactPutListenerQueue.js +2 -2
- package/lib/ReactReconcileTransaction.js +2 -2
- package/lib/ReactReconciler.js +121 -0
- package/lib/ReactRef.js +69 -0
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +6 -4
- package/lib/ReactServerRenderingTransaction.js +2 -2
- package/lib/ReactStateSetters.js +2 -2
- package/lib/ReactTestUtils.js +113 -27
- package/lib/ReactTransitionChildMapping.js +8 -4
- package/lib/ReactTransitionEvents.js +2 -2
- package/lib/ReactTransitionGroup.js +53 -12
- package/lib/ReactUpdateQueue.js +295 -0
- package/lib/ReactUpdates.js +54 -62
- 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 +3 -5
- package/lib/SyntheticTouchEvent.js +2 -2
- package/lib/SyntheticUIEvent.js +2 -2
- package/lib/SyntheticWheelEvent.js +2 -2
- package/lib/Transaction.js +4 -4
- package/lib/ViewportMetrics.js +3 -6
- 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 +4 -4
- package/lib/createNodesFromMarkup.js +4 -4
- package/lib/cx.js +1 -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 +51 -0
- package/lib/flattenChildren.js +12 -23
- 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 +42 -0
- 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 +90 -68
- package/lib/invariant.js +1 -1
- package/lib/isEventSupported.js +2 -2
- package/lib/isNode.js +4 -5
- package/lib/isTextInputElement.js +3 -4
- 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 +71 -7
- package/lib/toArray.js +2 -2
- package/lib/traverseAllChildren.js +114 -56
- package/lib/update.js +2 -2
- package/lib/warning.js +20 -2
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/copyProperties.js +0 -54
- package/lib/deprecated.js +0 -47
- 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
|
|
@@ -16,30 +16,58 @@
|
|
|
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
|
-
var
|
|
28
|
+
var getIteratorFn = require("./getIteratorFn");
|
|
29
|
+
var invariant = require("./invariant");
|
|
26
30
|
var warning = require("./warning");
|
|
27
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
|
+
|
|
28
42
|
/**
|
|
29
43
|
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
30
44
|
* object keys are not valid. This allows us to keep track of children between
|
|
31
45
|
* updates.
|
|
32
46
|
*/
|
|
33
|
-
var ownerHasKeyUseWarning = {
|
|
34
|
-
'react_key_warning': {},
|
|
35
|
-
'react_numeric_key_warning': {}
|
|
36
|
-
};
|
|
37
|
-
var ownerHasMonitoredObjectMap = {};
|
|
47
|
+
var ownerHasKeyUseWarning = {};
|
|
38
48
|
|
|
39
49
|
var loggedTypeFailures = {};
|
|
40
50
|
|
|
41
51
|
var NUMERIC_PROPERTY_REGEX = /^\d+$/;
|
|
42
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Gets the instance's name for use in warnings.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
* @return {?string} Display name or undefined
|
|
58
|
+
*/
|
|
59
|
+
function getName(instance) {
|
|
60
|
+
var publicInstance = instance && instance.getPublicInstance();
|
|
61
|
+
if (!publicInstance) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
var constructor = publicInstance.constructor;
|
|
65
|
+
if (!constructor) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
return constructor.displayName || constructor.name || undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
43
71
|
/**
|
|
44
72
|
* Gets the current owner's displayName for use in warnings.
|
|
45
73
|
*
|
|
@@ -48,29 +76,30 @@ var NUMERIC_PROPERTY_REGEX = /^\d+$/;
|
|
|
48
76
|
*/
|
|
49
77
|
function getCurrentOwnerDisplayName() {
|
|
50
78
|
var current = ReactCurrentOwner.current;
|
|
51
|
-
return
|
|
79
|
+
return (
|
|
80
|
+
current && getName(current) || undefined
|
|
81
|
+
);
|
|
52
82
|
}
|
|
53
83
|
|
|
54
84
|
/**
|
|
55
|
-
* Warn if the
|
|
56
|
-
* This
|
|
85
|
+
* Warn if the element doesn't have an explicit key assigned to it.
|
|
86
|
+
* This element is in an array. The array could grow and shrink or be
|
|
57
87
|
* reordered. All children that haven't already been validated are required to
|
|
58
88
|
* have a "key" property assigned to it.
|
|
59
89
|
*
|
|
60
90
|
* @internal
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {*} parentType
|
|
91
|
+
* @param {ReactElement} element Element that requires a key.
|
|
92
|
+
* @param {*} parentType element's parent's type.
|
|
63
93
|
*/
|
|
64
|
-
function validateExplicitKey(
|
|
65
|
-
if (
|
|
94
|
+
function validateExplicitKey(element, parentType) {
|
|
95
|
+
if (element._store.validated || element.key != null) {
|
|
66
96
|
return;
|
|
67
97
|
}
|
|
68
|
-
|
|
98
|
+
element._store.validated = true;
|
|
69
99
|
|
|
70
100
|
warnAndMonitorForKeyUse(
|
|
71
|
-
'
|
|
72
|
-
|
|
73
|
-
component,
|
|
101
|
+
'Each child in an array or iterator should have a unique "key" prop.',
|
|
102
|
+
element,
|
|
74
103
|
parentType
|
|
75
104
|
);
|
|
76
105
|
}
|
|
@@ -81,17 +110,16 @@ function validateExplicitKey(component, parentType) {
|
|
|
81
110
|
*
|
|
82
111
|
* @internal
|
|
83
112
|
* @param {string} name Property name of the key.
|
|
84
|
-
* @param {
|
|
85
|
-
* @param {*} parentType
|
|
113
|
+
* @param {ReactElement} element Component that requires a key.
|
|
114
|
+
* @param {*} parentType element's parent's type.
|
|
86
115
|
*/
|
|
87
|
-
function validatePropertyKey(name,
|
|
116
|
+
function validatePropertyKey(name, element, parentType) {
|
|
88
117
|
if (!NUMERIC_PROPERTY_REGEX.test(name)) {
|
|
89
118
|
return;
|
|
90
119
|
}
|
|
91
120
|
warnAndMonitorForKeyUse(
|
|
92
|
-
'react_numeric_key_warning',
|
|
93
121
|
'Child objects should have non-numeric keys so ordering is preserved.',
|
|
94
|
-
|
|
122
|
+
element,
|
|
95
123
|
parentType
|
|
96
124
|
);
|
|
97
125
|
}
|
|
@@ -100,17 +128,18 @@ function validatePropertyKey(name, component, parentType) {
|
|
|
100
128
|
* Shared warning and monitoring code for the key warnings.
|
|
101
129
|
*
|
|
102
130
|
* @internal
|
|
103
|
-
* @param {string} warningID The id used when logging.
|
|
104
131
|
* @param {string} message The base warning that gets output.
|
|
105
|
-
* @param {
|
|
106
|
-
* @param {*} parentType
|
|
132
|
+
* @param {ReactElement} element Component that requires a key.
|
|
133
|
+
* @param {*} parentType element's parent's type.
|
|
107
134
|
*/
|
|
108
|
-
function warnAndMonitorForKeyUse(
|
|
135
|
+
function warnAndMonitorForKeyUse(message, element, parentType) {
|
|
109
136
|
var ownerName = getCurrentOwnerDisplayName();
|
|
110
|
-
var parentName = parentType.displayName;
|
|
137
|
+
var parentName = parentType.displayName || parentType.name;
|
|
111
138
|
|
|
112
139
|
var useName = ownerName || parentName;
|
|
113
|
-
var memoizer = ownerHasKeyUseWarning[
|
|
140
|
+
var memoizer = ownerHasKeyUseWarning[message] || (
|
|
141
|
+
(ownerHasKeyUseWarning[message] = {})
|
|
142
|
+
);
|
|
114
143
|
if (memoizer.hasOwnProperty(useName)) {
|
|
115
144
|
return;
|
|
116
145
|
}
|
|
@@ -118,67 +147,64 @@ function warnAndMonitorForKeyUse(warningID, message, component, parentType) {
|
|
|
118
147
|
|
|
119
148
|
message += ownerName ?
|
|
120
149
|
(" Check the render method of " + ownerName + ".") :
|
|
121
|
-
(" Check the
|
|
150
|
+
(" Check the React.render call using <" + parentName + ">.");
|
|
122
151
|
|
|
123
152
|
// Usually the current owner is the offender, but if it accepts children as a
|
|
124
153
|
// property, it may be the creator of the child that's responsible for
|
|
125
154
|
// assigning it a key.
|
|
126
|
-
|
|
127
|
-
|
|
155
|
+
if (element &&
|
|
156
|
+
element._owner &&
|
|
157
|
+
element._owner !== ReactCurrentOwner.current) {
|
|
128
158
|
// Name of the component that originally created this child.
|
|
129
|
-
childOwnerName =
|
|
159
|
+
var childOwnerName = getName(element._owner);
|
|
130
160
|
|
|
131
161
|
message += (" It was passed a child from " + childOwnerName + ".");
|
|
132
162
|
}
|
|
133
163
|
|
|
134
164
|
message += ' See http://fb.me/react-warning-keys for more information.';
|
|
135
|
-
|
|
136
|
-
component: useName,
|
|
137
|
-
componentOwner: childOwnerName
|
|
138
|
-
});
|
|
139
|
-
console.warn(message);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Log that we're using an object map. We're considering deprecating this
|
|
144
|
-
* feature and replace it with proper Map and ImmutableMap data structures.
|
|
145
|
-
*
|
|
146
|
-
* @internal
|
|
147
|
-
*/
|
|
148
|
-
function monitorUseOfObjectMap() {
|
|
149
|
-
var currentName = getCurrentOwnerDisplayName() || '';
|
|
150
|
-
if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
ownerHasMonitoredObjectMap[currentName] = true;
|
|
154
|
-
monitorCodeUse('react_object_map_children');
|
|
165
|
+
("production" !== process.env.NODE_ENV ? warning(false, message) : null);
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
/**
|
|
158
|
-
* Ensure that every
|
|
169
|
+
* Ensure that every element either is passed in a static location, in an
|
|
159
170
|
* array with an explicit keys property defined, or in an object literal
|
|
160
171
|
* with valid key property.
|
|
161
172
|
*
|
|
162
173
|
* @internal
|
|
163
|
-
* @param {
|
|
164
|
-
* @param {*} parentType
|
|
165
|
-
* @return {boolean}
|
|
174
|
+
* @param {ReactNode} node Statically passed child of any type.
|
|
175
|
+
* @param {*} parentType node's parent's type.
|
|
166
176
|
*/
|
|
167
|
-
function validateChildKeys(
|
|
168
|
-
if (Array.isArray(
|
|
169
|
-
for (var i = 0; i <
|
|
170
|
-
var child =
|
|
177
|
+
function validateChildKeys(node, parentType) {
|
|
178
|
+
if (Array.isArray(node)) {
|
|
179
|
+
for (var i = 0; i < node.length; i++) {
|
|
180
|
+
var child = node[i];
|
|
171
181
|
if (ReactElement.isValidElement(child)) {
|
|
172
182
|
validateExplicitKey(child, parentType);
|
|
173
183
|
}
|
|
174
184
|
}
|
|
175
|
-
} else if (ReactElement.isValidElement(
|
|
176
|
-
// This
|
|
177
|
-
|
|
178
|
-
} else if (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
} else if (ReactElement.isValidElement(node)) {
|
|
186
|
+
// This element was passed in a valid location.
|
|
187
|
+
node._store.validated = true;
|
|
188
|
+
} else if (node) {
|
|
189
|
+
var iteratorFn = getIteratorFn(node);
|
|
190
|
+
// Entry iterators provide implicit keys.
|
|
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
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} else if (typeof node === 'object') {
|
|
202
|
+
var fragment = ReactFragment.extractIfFragment(node);
|
|
203
|
+
for (var key in fragment) {
|
|
204
|
+
if (fragment.hasOwnProperty(key)) {
|
|
205
|
+
validatePropertyKey(key, fragment[key], parentType);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
182
208
|
}
|
|
183
209
|
}
|
|
184
210
|
}
|
|
@@ -200,6 +226,16 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
200
226
|
// fail the render phase where it didn't fail before. So we log it.
|
|
201
227
|
// After these have been cleaned up, we'll let them throw.
|
|
202
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'));
|
|
203
239
|
error = propTypes[propName](props, propName, componentName, location);
|
|
204
240
|
} catch (ex) {
|
|
205
241
|
error = ex;
|
|
@@ -208,11 +244,80 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
208
244
|
// Only monitor this failure once because there tends to be a lot of the
|
|
209
245
|
// same error.
|
|
210
246
|
loggedTypeFailures[error.message] = true;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
+
/**
|
|
296
|
+
* Given an element, check if its props have been mutated since element
|
|
297
|
+
* creation (or the last call to this function). In particular, check if any
|
|
298
|
+
* new props have been added, which we can't directly catch by defining warning
|
|
299
|
+
* properties on the props object.
|
|
300
|
+
*
|
|
301
|
+
* @param {ReactElement} element
|
|
302
|
+
*/
|
|
303
|
+
function checkAndWarnForMutatedProps(element) {
|
|
304
|
+
if (!element._store) {
|
|
305
|
+
// Element was created using `new ReactElement` directly or with
|
|
306
|
+
// `ReactElement.createElement`; skip mutation checking
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var originalProps = element._store.originalProps;
|
|
311
|
+
var props = element.props;
|
|
312
|
+
|
|
313
|
+
for (var propName in props) {
|
|
314
|
+
if (props.hasOwnProperty(propName)) {
|
|
315
|
+
if (!originalProps.hasOwnProperty(propName) ||
|
|
316
|
+
originalProps[propName] !== props[propName]) {
|
|
317
|
+
warnForPropsMutation(propName, element);
|
|
318
|
+
|
|
319
|
+
// Copy over the new value so that the two props objects match again
|
|
320
|
+
originalProps[propName] = props[propName];
|
|
216
321
|
}
|
|
217
322
|
}
|
|
218
323
|
}
|
|
@@ -220,6 +325,8 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
220
325
|
|
|
221
326
|
var ReactElementValidator = {
|
|
222
327
|
|
|
328
|
+
checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
|
|
329
|
+
|
|
223
330
|
createElement: function(type, props, children) {
|
|
224
331
|
// We warn in this case but don't throw. We expect the element creation to
|
|
225
332
|
// succeed and there will likely be errors in render.
|
|
@@ -243,24 +350,33 @@ var ReactElementValidator = {
|
|
|
243
350
|
}
|
|
244
351
|
|
|
245
352
|
if (type) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
353
|
+
// Extract the component class from the element. Converts string types
|
|
354
|
+
// to a composite class which may have propTypes.
|
|
355
|
+
// TODO: Validating a string's propTypes is not decoupled from the
|
|
356
|
+
// rendering target which is problematic.
|
|
357
|
+
var componentClass = ReactNativeComponent.getComponentClassForElement(
|
|
358
|
+
element
|
|
359
|
+
);
|
|
360
|
+
var name = componentClass.displayName || componentClass.name;
|
|
361
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
362
|
+
if (componentClass.propTypes) {
|
|
363
|
+
checkPropTypes(
|
|
364
|
+
name,
|
|
365
|
+
componentClass.propTypes,
|
|
366
|
+
element.props,
|
|
367
|
+
ReactPropTypeLocations.prop
|
|
368
|
+
);
|
|
369
|
+
}
|
|
254
370
|
}
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
);
|
|
371
|
+
if (typeof componentClass.getDefaultProps === 'function') {
|
|
372
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
373
|
+
componentClass.getDefaultProps.isReactClassApproved,
|
|
374
|
+
'getDefaultProps is only used on classic React.createClass ' +
|
|
375
|
+
'definitions. Use a static property named `defaultProps` instead.'
|
|
376
|
+
) : null);
|
|
262
377
|
}
|
|
263
378
|
}
|
|
379
|
+
|
|
264
380
|
return element;
|
|
265
381
|
},
|
|
266
382
|
|
|
@@ -269,6 +385,7 @@ var ReactElementValidator = {
|
|
|
269
385
|
null,
|
|
270
386
|
type
|
|
271
387
|
);
|
|
388
|
+
// Legacy hook TODO: Warn if this is accessed
|
|
272
389
|
validatedFactory.type = type;
|
|
273
390
|
return validatedFactory;
|
|
274
391
|
}
|
|
@@ -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,16 +9,17 @@
|
|
|
9
9
|
* @providesModule ReactEmptyComponent
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
|
+
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
15
16
|
|
|
16
17
|
var invariant = require("./invariant");
|
|
17
18
|
|
|
18
19
|
var component;
|
|
19
20
|
// This registry keeps track of the React IDs of the components that rendered to
|
|
20
21
|
// `null` (in reality a placeholder such as `noscript`)
|
|
21
|
-
var
|
|
22
|
+
var nullComponentIDsRegistry = {};
|
|
22
23
|
|
|
23
24
|
var ReactEmptyComponentInjection = {
|
|
24
25
|
injectEmptyComponent: function(emptyComponent) {
|
|
@@ -26,24 +27,43 @@ var ReactEmptyComponentInjection = {
|
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
var ReactEmptyComponentType = function() {};
|
|
31
|
+
ReactEmptyComponentType.prototype.componentDidMount = function() {
|
|
32
|
+
var internalInstance = ReactInstanceMap.get(this);
|
|
33
|
+
// TODO: Make sure we run these methods in the correct order, we shouldn't
|
|
34
|
+
// need this check. We're going to assume if we're here it means we ran
|
|
35
|
+
// componentWillUnmount already so there is no internal instance (it gets
|
|
36
|
+
// removed as part of the unmounting process).
|
|
37
|
+
if (!internalInstance) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
registerNullComponentID(internalInstance._rootNodeID);
|
|
41
|
+
};
|
|
42
|
+
ReactEmptyComponentType.prototype.componentWillUnmount = function() {
|
|
43
|
+
var internalInstance = ReactInstanceMap.get(this);
|
|
44
|
+
// TODO: Get rid of this check. See TODO in componentDidMount.
|
|
45
|
+
if (!internalInstance) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
deregisterNullComponentID(internalInstance._rootNodeID);
|
|
49
|
+
};
|
|
50
|
+
ReactEmptyComponentType.prototype.render = function() {
|
|
33
51
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
34
52
|
component,
|
|
35
53
|
'Trying to return null from a render, but no null placeholder component ' +
|
|
36
54
|
'was injected.'
|
|
37
55
|
) : invariant(component));
|
|
38
56
|
return component();
|
|
39
|
-
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var emptyElement = ReactElement.createElement(ReactEmptyComponentType);
|
|
40
60
|
|
|
41
61
|
/**
|
|
42
62
|
* Mark the component as having rendered to null.
|
|
43
63
|
* @param {string} id Component's `_rootNodeID`.
|
|
44
64
|
*/
|
|
45
65
|
function registerNullComponentID(id) {
|
|
46
|
-
|
|
66
|
+
nullComponentIDsRegistry[id] = true;
|
|
47
67
|
}
|
|
48
68
|
|
|
49
69
|
/**
|
|
@@ -51,7 +71,7 @@ function registerNullComponentID(id) {
|
|
|
51
71
|
* @param {string} id Component's `_rootNodeID`.
|
|
52
72
|
*/
|
|
53
73
|
function deregisterNullComponentID(id) {
|
|
54
|
-
delete
|
|
74
|
+
delete nullComponentIDsRegistry[id];
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
/**
|
|
@@ -59,15 +79,13 @@ function deregisterNullComponentID(id) {
|
|
|
59
79
|
* @return {boolean} True if the component is rendered to null.
|
|
60
80
|
*/
|
|
61
81
|
function isNullComponentID(id) {
|
|
62
|
-
return
|
|
82
|
+
return !!nullComponentIDsRegistry[id];
|
|
63
83
|
}
|
|
64
84
|
|
|
65
85
|
var ReactEmptyComponent = {
|
|
66
|
-
|
|
67
|
-
getEmptyComponent: getEmptyComponent,
|
|
86
|
+
emptyElement: emptyElement,
|
|
68
87
|
injection: ReactEmptyComponentInjection,
|
|
69
|
-
isNullComponentID: isNullComponentID
|
|
70
|
-
registerNullComponentID: registerNullComponentID
|
|
88
|
+
isNullComponentID: isNullComponentID
|
|
71
89
|
};
|
|
72
90
|
|
|
73
91
|
module.exports = ReactEmptyComponent;
|