react 0.11.2 → 0.12.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 +2714 -7859
- package/dist/react-with-addons.js +3139 -3593
- package/dist/react-with-addons.min.js +11 -17
- package/dist/react.js +2940 -3308
- package/dist/react.min.js +11 -16
- package/lib/AutoFocusMixin.js +5 -12
- package/lib/BeforeInputEventPlugin.js +12 -14
- package/lib/CSSCore.js +6 -13
- package/lib/CSSProperty.js +10 -14
- package/lib/CSSPropertyOperations.js +46 -12
- package/lib/CallbackQueue.js +7 -14
- package/lib/ChangeEventPlugin.js +5 -12
- package/lib/ClientReactRootIndex.js +5 -12
- package/lib/CompositionEventPlugin.js +5 -12
- package/lib/DOMChildrenOperations.js +8 -15
- package/lib/DOMProperty.js +16 -19
- package/lib/DOMPropertyOperations.js +14 -14
- package/lib/Danger.js +12 -17
- package/lib/DefaultEventPluginOrder.js +5 -12
- package/lib/EnterLeaveEventPlugin.js +5 -12
- package/lib/EventConstants.js +5 -12
- package/lib/EventListener.js +14 -0
- package/lib/EventPluginHub.js +8 -26
- package/lib/EventPluginRegistry.js +5 -12
- package/lib/EventPluginUtils.js +5 -12
- package/lib/EventPropagators.js +12 -17
- package/lib/ExecutionEnvironment.js +5 -12
- package/lib/HTMLDOMPropertyConfig.js +16 -15
- package/lib/LinkedStateMixin.js +5 -12
- package/lib/LinkedValueUtils.js +5 -12
- package/lib/LocalEventTrapMixin.js +8 -14
- package/lib/MobileSafariClickEventPlugin.js +5 -12
- package/lib/Object.assign.js +45 -0
- package/lib/PooledClass.js +5 -12
- package/lib/React.js +87 -54
- package/lib/ReactBrowserComponentMixin.js +5 -12
- package/lib/ReactBrowserEventEmitter.js +7 -14
- package/lib/ReactCSSTransitionGroup.js +15 -17
- package/lib/ReactCSSTransitionGroupChild.js +9 -13
- package/lib/ReactChildren.js +5 -12
- package/lib/ReactComponent.js +61 -68
- package/lib/ReactComponentBrowserEnvironment.js +5 -12
- package/lib/ReactComponentWithPureRenderMixin.js +5 -12
- package/lib/ReactCompositeComponent.js +191 -180
- package/lib/ReactContext.js +8 -15
- package/lib/ReactCurrentOwner.js +5 -12
- package/lib/ReactDOM.js +145 -177
- package/lib/ReactDOMButton.js +8 -14
- package/lib/ReactDOMComponent.js +103 -38
- package/lib/ReactDOMForm.js +9 -15
- package/lib/ReactDOMIDOperations.js +5 -12
- package/lib/ReactDOMImg.js +8 -14
- package/lib/ReactDOMInput.js +30 -38
- package/lib/ReactDOMOption.js +8 -14
- package/lib/ReactDOMSelect.js +25 -24
- package/lib/ReactDOMSelection.js +11 -18
- package/lib/ReactDOMTextarea.js +19 -24
- package/lib/ReactDefaultBatchingStrategy.js +14 -18
- package/lib/ReactDefaultInjection.js +23 -26
- package/lib/ReactDefaultPerf.js +14 -17
- package/lib/ReactDefaultPerfAnalysis.js +18 -17
- package/lib/ReactElement.js +242 -0
- package/lib/{ReactDescriptorValidator.js → ReactElementValidator.js} +51 -56
- package/lib/ReactEmptyComponent.js +8 -13
- package/lib/ReactErrorUtils.js +5 -12
- package/lib/ReactEventEmitterMixin.js +5 -12
- package/lib/ReactEventListener.js +7 -14
- package/lib/ReactInjection.js +7 -14
- package/lib/ReactInputSelection.js +5 -12
- package/lib/ReactInstanceHandles.js +5 -12
- package/lib/ReactLegacyElement.js +243 -0
- package/lib/ReactLink.js +5 -12
- package/lib/ReactMarkupChecksum.js +5 -12
- package/lib/ReactMount.js +45 -32
- package/lib/ReactMultiChild.js +14 -18
- package/lib/ReactMultiChildUpdateTypes.js +5 -12
- package/lib/ReactNativeComponent.js +69 -0
- package/lib/ReactOwner.js +5 -12
- package/lib/ReactPerf.js +8 -13
- package/lib/ReactPropTransferer.js +34 -33
- package/lib/ReactPropTypeLocationNames.js +5 -12
- package/lib/ReactPropTypeLocations.js +5 -12
- package/lib/ReactPropTypes.js +38 -29
- package/lib/ReactPutListenerQueue.js +7 -14
- package/lib/ReactReconcileTransaction.js +7 -15
- package/lib/ReactRootIndex.js +5 -12
- package/lib/ReactServerRendering.js +21 -34
- package/lib/ReactServerRenderingTransaction.js +11 -15
- package/lib/ReactStateSetters.js +5 -12
- package/lib/ReactTestUtils.js +31 -33
- package/lib/ReactTextComponent.js +18 -21
- package/lib/ReactTransitionChildMapping.js +6 -13
- package/lib/ReactTransitionEvents.js +5 -12
- package/lib/ReactTransitionGroup.js +14 -17
- package/lib/ReactUpdates.js +43 -22
- package/lib/ReactWithAddons.js +7 -13
- package/lib/SVGDOMPropertyConfig.js +5 -12
- package/lib/SelectEventPlugin.js +13 -20
- package/lib/ServerReactRootIndex.js +5 -12
- package/lib/SimpleEventPlugin.js +20 -15
- package/lib/SyntheticClipboardEvent.js +5 -12
- package/lib/SyntheticCompositionEvent.js +5 -12
- package/lib/SyntheticDragEvent.js +5 -12
- package/lib/SyntheticEvent.js +9 -17
- package/lib/SyntheticFocusEvent.js +5 -12
- package/lib/SyntheticInputEvent.js +4 -11
- package/lib/SyntheticKeyboardEvent.js +17 -19
- package/lib/SyntheticMouseEvent.js +5 -12
- package/lib/SyntheticTouchEvent.js +5 -12
- package/lib/SyntheticUIEvent.js +5 -12
- package/lib/SyntheticWheelEvent.js +5 -12
- package/lib/Transaction.js +5 -12
- package/lib/ViewportMetrics.js +5 -12
- package/lib/accumulateInto.js +62 -0
- package/lib/adler32.js +6 -13
- package/lib/camelize.js +30 -0
- package/lib/camelizeStyleName.js +40 -0
- package/lib/cloneWithProps.js +9 -15
- package/lib/containsNode.js +5 -12
- package/lib/copyProperties.js +12 -12
- package/lib/createArrayFrom.js +5 -12
- package/lib/createFullPageComponent.js +12 -18
- package/lib/createNodesFromMarkup.js +5 -12
- package/lib/cx.js +5 -12
- package/lib/dangerousStyleValue.js +5 -12
- package/lib/deprecated.js +47 -0
- package/lib/emptyFunction.js +11 -22
- package/lib/emptyObject.js +5 -12
- package/lib/escapeTextForBrowser.js +5 -12
- package/lib/flattenChildren.js +19 -13
- package/lib/focusNode.js +10 -16
- package/lib/forEachAccumulated.js +5 -12
- package/lib/getActiveElement.js +5 -12
- package/lib/getEventCharCode.js +50 -0
- package/lib/getEventKey.js +9 -21
- package/lib/getEventModifierState.js +4 -11
- package/lib/getEventTarget.js +5 -12
- package/lib/getMarkupWrap.js +5 -12
- package/lib/getNodeForCharacterOffset.js +5 -12
- package/lib/getReactRootElementInContainer.js +5 -12
- package/lib/getTextContentAccessor.js +5 -12
- package/lib/getUnboundedScrollPosition.js +5 -12
- package/lib/hyphenate.js +5 -12
- package/lib/hyphenateStyleName.js +8 -15
- package/lib/instantiateReactComponent.js +90 -42
- package/lib/invariant.js +5 -12
- package/lib/isEventSupported.js +5 -12
- package/lib/isNode.js +5 -12
- package/lib/isTextInputElement.js +5 -12
- package/lib/isTextNode.js +5 -12
- package/lib/joinClasses.js +8 -13
- package/lib/keyMirror.js +5 -12
- package/lib/keyOf.js +5 -12
- package/lib/mapObject.js +35 -36
- package/lib/memoizeStringOnly.js +5 -12
- package/lib/merge.js +14 -17
- package/lib/mergeInto.js +13 -35
- package/lib/monitorCodeUse.js +5 -12
- package/lib/onlyChild.js +8 -15
- package/lib/performance.js +5 -12
- package/lib/performanceNow.js +5 -12
- package/lib/setInnerHTML.js +10 -19
- package/lib/shallowEqual.js +6 -13
- package/lib/shouldUpdateReactComponent.js +14 -22
- package/lib/toArray.js +5 -12
- package/lib/traverseAllChildren.js +34 -48
- package/lib/update.js +8 -15
- package/lib/warning.js +6 -13
- package/package.json +3 -8
- package/lib/ReactDescriptor.js +0 -251
- package/lib/accumulate.js +0 -54
- package/lib/mergeHelpers.js +0 -147
- package/lib/mixInto.js +0 -34
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-2014 Facebook, Inc.
|
|
2
|
+
* Copyright 2013-2014, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
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.
|
|
15
8
|
*
|
|
16
9
|
* @providesModule ReactDefaultPerfAnalysis
|
|
17
10
|
*/
|
|
18
11
|
|
|
19
|
-
var
|
|
12
|
+
var assign = require("./Object.assign");
|
|
20
13
|
|
|
21
14
|
// Don't try to save users less than 1.2ms (a number I made up)
|
|
22
15
|
var DONT_CARE_THRESHOLD = 1.2;
|
|
@@ -71,7 +64,11 @@ function getExclusiveSummary(measurements) {
|
|
|
71
64
|
|
|
72
65
|
for (var i = 0; i < measurements.length; i++) {
|
|
73
66
|
var measurement = measurements[i];
|
|
74
|
-
var allIDs =
|
|
67
|
+
var allIDs = assign(
|
|
68
|
+
{},
|
|
69
|
+
measurement.exclusive,
|
|
70
|
+
measurement.inclusive
|
|
71
|
+
);
|
|
75
72
|
|
|
76
73
|
for (var id in allIDs) {
|
|
77
74
|
displayName = measurement.displayNames[id].current;
|
|
@@ -119,7 +116,11 @@ function getInclusiveSummary(measurements, onlyClean) {
|
|
|
119
116
|
|
|
120
117
|
for (var i = 0; i < measurements.length; i++) {
|
|
121
118
|
var measurement = measurements[i];
|
|
122
|
-
var allIDs =
|
|
119
|
+
var allIDs = assign(
|
|
120
|
+
{},
|
|
121
|
+
measurement.exclusive,
|
|
122
|
+
measurement.inclusive
|
|
123
|
+
);
|
|
123
124
|
var cleanComponents;
|
|
124
125
|
|
|
125
126
|
if (onlyClean) {
|
|
@@ -174,11 +175,11 @@ function getUnchangedComponents(measurement) {
|
|
|
174
175
|
// the amount of time it took to render the entire subtree.
|
|
175
176
|
var cleanComponents = {};
|
|
176
177
|
var dirtyLeafIDs = Object.keys(measurement.writes);
|
|
177
|
-
var allIDs =
|
|
178
|
+
var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
|
|
178
179
|
|
|
179
180
|
for (var id in allIDs) {
|
|
180
181
|
var isDirty = false;
|
|
181
|
-
// For each component that rendered, see if a component that
|
|
182
|
+
// For each component that rendered, see if a component that triggered
|
|
182
183
|
// a DOM op is in its subtree.
|
|
183
184
|
for (var i = 0; i < dirtyLeafIDs.length; i++) {
|
|
184
185
|
if (dirtyLeafIDs[i].indexOf(id) === 0) {
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014, 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 ReactElement
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
var ReactContext = require("./ReactContext");
|
|
15
|
+
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
16
|
+
|
|
17
|
+
var warning = require("./warning");
|
|
18
|
+
|
|
19
|
+
var RESERVED_PROPS = {
|
|
20
|
+
key: true,
|
|
21
|
+
ref: true
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Warn for mutations.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
* @param {object} object
|
|
29
|
+
* @param {string} key
|
|
30
|
+
*/
|
|
31
|
+
function defineWarningProperty(object, key) {
|
|
32
|
+
Object.defineProperty(object, key, {
|
|
33
|
+
|
|
34
|
+
configurable: false,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
|
|
37
|
+
get: function() {
|
|
38
|
+
if (!this._store) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return this._store[key];
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
set: function(value) {
|
|
45
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
46
|
+
false,
|
|
47
|
+
'Don\'t set the ' + key + ' property of the component. ' +
|
|
48
|
+
'Mutate the existing props object instead.'
|
|
49
|
+
) : null);
|
|
50
|
+
this._store[key] = value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This is updated to true if the membrane is successfully created.
|
|
58
|
+
*/
|
|
59
|
+
var useMutationMembrane = false;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Warn for mutations.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
* @param {object} element
|
|
66
|
+
*/
|
|
67
|
+
function defineMutationMembrane(prototype) {
|
|
68
|
+
try {
|
|
69
|
+
var pseudoFrozenProperties = {
|
|
70
|
+
props: true
|
|
71
|
+
};
|
|
72
|
+
for (var key in pseudoFrozenProperties) {
|
|
73
|
+
defineWarningProperty(prototype, key);
|
|
74
|
+
}
|
|
75
|
+
useMutationMembrane = true;
|
|
76
|
+
} catch (x) {
|
|
77
|
+
// IE will fail on defineProperty
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Base constructor for all React elements. This is only used to make this
|
|
83
|
+
* work with a dynamic instanceof check. Nothing should live on this prototype.
|
|
84
|
+
*
|
|
85
|
+
* @param {*} type
|
|
86
|
+
* @param {string|object} ref
|
|
87
|
+
* @param {*} key
|
|
88
|
+
* @param {*} props
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
var ReactElement = function(type, key, ref, owner, context, props) {
|
|
92
|
+
// Built-in properties that belong on the element
|
|
93
|
+
this.type = type;
|
|
94
|
+
this.key = key;
|
|
95
|
+
this.ref = ref;
|
|
96
|
+
|
|
97
|
+
// Record the component responsible for creating this element.
|
|
98
|
+
this._owner = owner;
|
|
99
|
+
|
|
100
|
+
// TODO: Deprecate withContext, and then the context becomes accessible
|
|
101
|
+
// through the owner.
|
|
102
|
+
this._context = context;
|
|
103
|
+
|
|
104
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
105
|
+
// The validation flag and props are currently mutative. We put them on
|
|
106
|
+
// an external backing store so that we can freeze the whole object.
|
|
107
|
+
// This can be replaced with a WeakMap once they are implemented in
|
|
108
|
+
// commonly used development environments.
|
|
109
|
+
this._store = { validated: false, props: props };
|
|
110
|
+
|
|
111
|
+
// We're not allowed to set props directly on the object so we early
|
|
112
|
+
// return and rely on the prototype membrane to forward to the backing
|
|
113
|
+
// store.
|
|
114
|
+
if (useMutationMembrane) {
|
|
115
|
+
Object.freeze(this);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.props = props;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// We intentionally don't expose the function on the constructor property.
|
|
124
|
+
// ReactElement should be indistinguishable from a plain object.
|
|
125
|
+
ReactElement.prototype = {
|
|
126
|
+
_isReactElement: true
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
130
|
+
defineMutationMembrane(ReactElement.prototype);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
ReactElement.createElement = function(type, config, children) {
|
|
134
|
+
var propName;
|
|
135
|
+
|
|
136
|
+
// Reserved names are extracted
|
|
137
|
+
var props = {};
|
|
138
|
+
|
|
139
|
+
var key = null;
|
|
140
|
+
var ref = null;
|
|
141
|
+
|
|
142
|
+
if (config != null) {
|
|
143
|
+
ref = config.ref === undefined ? null : config.ref;
|
|
144
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
145
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
146
|
+
config.key !== null,
|
|
147
|
+
'createElement(...): Encountered component with a `key` of null. In ' +
|
|
148
|
+
'a future version, this will be treated as equivalent to the string ' +
|
|
149
|
+
'\'null\'; instead, provide an explicit key or use undefined.'
|
|
150
|
+
) : null);
|
|
151
|
+
}
|
|
152
|
+
// TODO: Change this back to `config.key === undefined`
|
|
153
|
+
key = config.key == null ? null : '' + config.key;
|
|
154
|
+
// Remaining properties are added to a new props object
|
|
155
|
+
for (propName in config) {
|
|
156
|
+
if (config.hasOwnProperty(propName) &&
|
|
157
|
+
!RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
158
|
+
props[propName] = config[propName];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Children can be more than one argument, and those are transferred onto
|
|
164
|
+
// the newly allocated props object.
|
|
165
|
+
var childrenLength = arguments.length - 2;
|
|
166
|
+
if (childrenLength === 1) {
|
|
167
|
+
props.children = children;
|
|
168
|
+
} else if (childrenLength > 1) {
|
|
169
|
+
var childArray = Array(childrenLength);
|
|
170
|
+
for (var i = 0; i < childrenLength; i++) {
|
|
171
|
+
childArray[i] = arguments[i + 2];
|
|
172
|
+
}
|
|
173
|
+
props.children = childArray;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Resolve default props
|
|
177
|
+
if (type && type.defaultProps) {
|
|
178
|
+
var defaultProps = type.defaultProps;
|
|
179
|
+
for (propName in defaultProps) {
|
|
180
|
+
if (typeof props[propName] === 'undefined') {
|
|
181
|
+
props[propName] = defaultProps[propName];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return new ReactElement(
|
|
187
|
+
type,
|
|
188
|
+
key,
|
|
189
|
+
ref,
|
|
190
|
+
ReactCurrentOwner.current,
|
|
191
|
+
ReactContext.current,
|
|
192
|
+
props
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
ReactElement.createFactory = function(type) {
|
|
197
|
+
var factory = ReactElement.createElement.bind(null, type);
|
|
198
|
+
// Expose the type on the factory and the prototype so that it can be
|
|
199
|
+
// easily accessed on elements. E.g. <Foo />.type === Foo.type.
|
|
200
|
+
// This should not be named `constructor` since this may not be the function
|
|
201
|
+
// that created the element, and it may not even be a constructor.
|
|
202
|
+
factory.type = type;
|
|
203
|
+
return factory;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
ReactElement.cloneAndReplaceProps = function(oldElement, newProps) {
|
|
207
|
+
var newElement = new ReactElement(
|
|
208
|
+
oldElement.type,
|
|
209
|
+
oldElement.key,
|
|
210
|
+
oldElement.ref,
|
|
211
|
+
oldElement._owner,
|
|
212
|
+
oldElement._context,
|
|
213
|
+
newProps
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
217
|
+
// If the key on the original is valid, then the clone is valid
|
|
218
|
+
newElement._store.validated = oldElement._store.validated;
|
|
219
|
+
}
|
|
220
|
+
return newElement;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @param {?object} object
|
|
225
|
+
* @return {boolean} True if `object` is a valid component.
|
|
226
|
+
* @final
|
|
227
|
+
*/
|
|
228
|
+
ReactElement.isValidElement = function(object) {
|
|
229
|
+
// ReactTestUtils is often used outside of beforeEach where as React is
|
|
230
|
+
// within it. This leads to two different instances of React on the same
|
|
231
|
+
// page. To identify a element from a different React instance we use
|
|
232
|
+
// a flag instead of an instanceof check.
|
|
233
|
+
var isElement = !!(object && object._isReactElement);
|
|
234
|
+
// if (isElement && !(object instanceof ReactElement)) {
|
|
235
|
+
// This is an indicator that you're using multiple versions of React at the
|
|
236
|
+
// same time. This will screw with ownership and stuff. Fix it, please.
|
|
237
|
+
// TODO: We could possibly warn here.
|
|
238
|
+
// }
|
|
239
|
+
return isElement;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
module.exports = ReactElement;
|
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2014 Facebook, Inc.
|
|
2
|
+
* Copyright 2014, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*
|
|
16
|
-
* @providesModule ReactDescriptorValidator
|
|
9
|
+
* @providesModule ReactElementValidator
|
|
17
10
|
*/
|
|
18
11
|
|
|
19
12
|
/**
|
|
20
|
-
*
|
|
21
|
-
* which validates the props passed to the
|
|
13
|
+
* ReactElementValidator provides a wrapper around a element factory
|
|
14
|
+
* which validates the props passed to the element. This is intended to be
|
|
22
15
|
* used only in DEV and could be replaced by a static type checker for languages
|
|
23
16
|
* that support it.
|
|
24
17
|
*/
|
|
25
18
|
|
|
26
19
|
"use strict";
|
|
27
20
|
|
|
28
|
-
var
|
|
21
|
+
var ReactElement = require("./ReactElement");
|
|
29
22
|
var ReactPropTypeLocations = require("./ReactPropTypeLocations");
|
|
30
23
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
31
24
|
|
|
32
25
|
var monitorCodeUse = require("./monitorCodeUse");
|
|
26
|
+
var warning = require("./warning");
|
|
33
27
|
|
|
34
28
|
/**
|
|
35
29
|
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
@@ -68,7 +62,7 @@ function getCurrentOwnerDisplayName() {
|
|
|
68
62
|
* @param {*} parentType component's parent's type.
|
|
69
63
|
*/
|
|
70
64
|
function validateExplicitKey(component, parentType) {
|
|
71
|
-
if (component._store.validated || component.
|
|
65
|
+
if (component._store.validated || component.key != null) {
|
|
72
66
|
return;
|
|
73
67
|
}
|
|
74
68
|
component._store.validated = true;
|
|
@@ -174,11 +168,11 @@ function validateChildKeys(component, parentType) {
|
|
|
174
168
|
if (Array.isArray(component)) {
|
|
175
169
|
for (var i = 0; i < component.length; i++) {
|
|
176
170
|
var child = component[i];
|
|
177
|
-
if (
|
|
171
|
+
if (ReactElement.isValidElement(child)) {
|
|
178
172
|
validateExplicitKey(child, parentType);
|
|
179
173
|
}
|
|
180
174
|
}
|
|
181
|
-
} else if (
|
|
175
|
+
} else if (ReactElement.isValidElement(component)) {
|
|
182
176
|
// This component was passed in a valid location.
|
|
183
177
|
component._store.validated = true;
|
|
184
178
|
} else if (component && typeof component === 'object') {
|
|
@@ -224,60 +218,61 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
224
218
|
}
|
|
225
219
|
}
|
|
226
220
|
|
|
227
|
-
var
|
|
221
|
+
var ReactElementValidator = {
|
|
228
222
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
* @private
|
|
239
|
-
*/
|
|
240
|
-
createFactory: function(factory, propTypes, contextTypes) {
|
|
241
|
-
var validatedFactory = function(props, children) {
|
|
242
|
-
var descriptor = factory.apply(this, arguments);
|
|
223
|
+
createElement: function(type, props, children) {
|
|
224
|
+
// We warn in this case but don't throw. We expect the element creation to
|
|
225
|
+
// succeed and there will likely be errors in render.
|
|
226
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
227
|
+
type != null,
|
|
228
|
+
'React.createElement: type should not be null or undefined. It should ' +
|
|
229
|
+
'be a string (for DOM elements) or a ReactClass (for composite ' +
|
|
230
|
+
'components).'
|
|
231
|
+
) : null);
|
|
243
232
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
233
|
+
var element = ReactElement.createElement.apply(this, arguments);
|
|
234
|
+
|
|
235
|
+
// The result can be nullish if a mock or a custom function is used.
|
|
236
|
+
// TODO: Drop this when these are no longer allowed as the type argument.
|
|
237
|
+
if (element == null) {
|
|
238
|
+
return element;
|
|
239
|
+
}
|
|
247
240
|
|
|
248
|
-
|
|
249
|
-
|
|
241
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
242
|
+
validateChildKeys(arguments[i], type);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (type) {
|
|
246
|
+
var name = type.displayName;
|
|
247
|
+
if (type.propTypes) {
|
|
250
248
|
checkPropTypes(
|
|
251
249
|
name,
|
|
252
|
-
propTypes,
|
|
253
|
-
|
|
250
|
+
type.propTypes,
|
|
251
|
+
element.props,
|
|
254
252
|
ReactPropTypeLocations.prop
|
|
255
253
|
);
|
|
256
254
|
}
|
|
257
|
-
if (contextTypes) {
|
|
255
|
+
if (type.contextTypes) {
|
|
258
256
|
checkPropTypes(
|
|
259
257
|
name,
|
|
260
|
-
contextTypes,
|
|
261
|
-
|
|
258
|
+
type.contextTypes,
|
|
259
|
+
element._context,
|
|
262
260
|
ReactPropTypeLocations.context
|
|
263
261
|
);
|
|
264
262
|
}
|
|
265
|
-
return descriptor;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
validatedFactory.prototype = factory.prototype;
|
|
269
|
-
validatedFactory.type = factory.type;
|
|
270
|
-
|
|
271
|
-
// Copy static properties
|
|
272
|
-
for (var key in factory) {
|
|
273
|
-
if (factory.hasOwnProperty(key)) {
|
|
274
|
-
validatedFactory[key] = factory[key];
|
|
275
|
-
}
|
|
276
263
|
}
|
|
264
|
+
return element;
|
|
265
|
+
},
|
|
277
266
|
|
|
267
|
+
createFactory: function(type) {
|
|
268
|
+
var validatedFactory = ReactElementValidator.createElement.bind(
|
|
269
|
+
null,
|
|
270
|
+
type
|
|
271
|
+
);
|
|
272
|
+
validatedFactory.type = type;
|
|
278
273
|
return validatedFactory;
|
|
279
274
|
}
|
|
280
275
|
|
|
281
276
|
};
|
|
282
277
|
|
|
283
|
-
module.exports =
|
|
278
|
+
module.exports = ReactElementValidator;
|