react 0.14.0-beta1 → 0.14.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/addons.js +8 -3
- package/dist/react-with-addons.js +5048 -4095
- package/dist/react-with-addons.min.js +6 -6
- package/dist/react.js +4555 -3729
- package/dist/react.min.js +6 -5
- package/lib/AutoFocusUtils.js +3 -3
- package/lib/BeforeInputEventPlugin.js +13 -13
- package/lib/CSSProperty.js +18 -3
- package/lib/CSSPropertyOperations.js +27 -14
- package/lib/CallbackQueue.js +4 -4
- package/lib/ChangeEventPlugin.js +15 -14
- package/lib/DOMChildrenOperations.js +22 -7
- package/lib/DOMProperty.js +8 -8
- package/lib/DOMPropertyOperations.js +23 -10
- package/lib/Danger.js +21 -16
- package/lib/DefaultEventPluginOrder.js +2 -2
- package/lib/EnterLeaveEventPlugin.js +18 -10
- package/lib/EventConstants.js +23 -1
- package/lib/EventPluginHub.js +29 -21
- package/lib/EventPluginRegistry.js +8 -8
- package/lib/EventPluginUtils.js +34 -38
- package/lib/EventPropagators.js +8 -8
- package/lib/FallbackCompositionState.js +9 -3
- package/lib/HTMLDOMPropertyConfig.js +24 -4
- package/lib/LinkedStateMixin.js +2 -2
- package/lib/LinkedValueUtils.js +8 -8
- package/lib/MetaMatchers.js +118 -0
- package/lib/OrderedMap.js +453 -0
- package/lib/PooledClass.js +3 -5
- package/lib/React.js +18 -7
- package/lib/ReactBrowserComponentMixin.js +4 -4
- package/lib/ReactBrowserEventEmitter.js +36 -7
- package/lib/ReactCSSTransitionGroup.js +35 -9
- package/lib/ReactCSSTransitionGroupChild.js +48 -30
- package/lib/ReactChildReconciler.js +24 -19
- package/lib/ReactChildren.js +72 -32
- package/lib/ReactClass.js +46 -46
- package/lib/ReactComponent.js +18 -16
- package/lib/ReactComponentBrowserEnvironment.js +2 -2
- package/lib/ReactComponentEnvironment.js +2 -2
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +95 -44
- package/lib/ReactDOM.js +74 -159
- package/lib/ReactDOMComponent.js +235 -93
- package/lib/ReactDOMFactories.js +177 -0
- package/lib/{emptyObject.js → ReactDOMFeatureFlags.js} +6 -8
- package/lib/ReactDOMIDOperations.js +8 -81
- package/lib/ReactDOMInput.js +18 -9
- package/lib/ReactDOMOption.js +7 -7
- package/lib/ReactDOMSelect.js +9 -9
- package/lib/ReactDOMSelection.js +19 -3
- package/lib/ReactDOMServer.js +5 -3
- package/lib/ReactDOMTextComponent.js +33 -20
- package/lib/ReactDOMTextarea.js +14 -12
- package/lib/ReactDefaultBatchingStrategy.js +4 -4
- package/lib/ReactDefaultInjection.js +23 -25
- package/lib/ReactDefaultPerf.js +17 -11
- package/lib/ReactDefaultPerfAnalysis.js +13 -12
- package/lib/ReactElement.js +85 -39
- package/lib/ReactElementValidator.js +47 -90
- package/lib/ReactEmptyComponent.js +26 -62
- package/lib/ReactEmptyComponentRegistry.js +48 -0
- package/lib/ReactErrorUtils.js +53 -9
- package/lib/ReactEventEmitterMixin.js +2 -2
- package/lib/ReactEventListener.js +33 -21
- package/lib/ReactFragment.js +27 -118
- package/lib/ReactInjection.js +10 -12
- package/lib/ReactInputSelection.js +4 -4
- package/lib/ReactInstanceHandles.js +10 -11
- package/lib/ReactIsomorphic.js +15 -11
- package/lib/ReactLink.js +2 -2
- package/lib/ReactMarkupChecksum.js +6 -2
- package/lib/ReactMount.js +186 -85
- package/lib/ReactMultiChild.js +119 -25
- package/lib/ReactMultiChildUpdateTypes.js +2 -1
- package/lib/ReactNativeComponent.js +3 -3
- package/lib/ReactNoopUpdateQueue.js +3 -3
- package/lib/ReactOwner.js +3 -3
- package/lib/ReactPerf.js +2 -2
- package/lib/ReactPropTransferer.js +3 -3
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +38 -9
- package/lib/ReactReconcileTransaction.js +10 -8
- package/lib/ReactReconciler.js +5 -6
- package/lib/ReactRef.js +14 -2
- package/lib/ReactServerBatchingStrategy.js +5 -5
- package/lib/ReactServerRendering.js +12 -12
- package/lib/ReactServerRenderingTransaction.js +6 -5
- package/lib/ReactTestUtils.js +47 -39
- package/lib/ReactTransitionChildMapping.js +3 -6
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +5 -6
- package/lib/ReactUpdateQueue.js +19 -19
- package/lib/ReactUpdates.js +15 -15
- package/lib/{performance.js → ReactVersion.js} +3 -12
- package/lib/ReactWithAddons.js +24 -15
- package/lib/ResponderEventPlugin.js +514 -0
- package/lib/ResponderSyntheticEvent.js +40 -0
- package/lib/ResponderTouchHistoryStore.js +180 -0
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +19 -9
- package/lib/SimpleEventPlugin.js +198 -43
- package/lib/SyntheticClipboardEvent.js +1 -1
- package/lib/SyntheticCompositionEvent.js +1 -1
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +18 -4
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +1 -1
- package/lib/SyntheticKeyboardEvent.js +4 -4
- package/lib/SyntheticMouseEvent.js +3 -3
- package/lib/SyntheticTouchEvent.js +2 -2
- package/lib/SyntheticUIEvent.js +2 -2
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/TapEventPlugin.js +119 -0
- package/lib/Transaction.js +7 -7
- package/lib/accumulate.js +44 -0
- package/lib/accumulateInto.js +2 -2
- package/lib/adler32.js +19 -7
- package/lib/cloneWithProps.js +11 -6
- package/lib/createHierarchyRenderer.js +85 -0
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/deprecated.js +7 -6
- package/lib/findDOMNode.js +9 -9
- package/lib/flattenChildren.js +4 -4
- package/lib/getEventKey.js +1 -1
- package/lib/{isTextNode.js → getTestDocument.js} +7 -11
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/instantiateReactComponent.js +15 -17
- package/lib/isEventSupported.js +1 -1
- package/lib/onlyChild.js +3 -3
- package/lib/quoteAttributeValueForBrowser.js +1 -1
- package/lib/reactComponentExpect.js +216 -0
- package/lib/renderSubtreeIntoContainer.js +1 -1
- package/lib/setInnerHTML.js +1 -1
- package/lib/setTextContent.js +3 -3
- package/lib/shallowCompare.js +1 -1
- package/lib/shouldUpdateReactComponent.js +12 -8
- package/lib/sliceChildren.js +34 -0
- package/lib/traverseAllChildren.js +25 -18
- package/lib/update.js +13 -13
- package/lib/validateDOMNesting.js +6 -6
- package/lib/webcomponents.js +6379 -0
- package/package.json +4 -6
- package/react.js +1 -51
- package/dist/JSXTransformer.js +0 -17588
- package/lib/CSSCore.js +0 -97
- package/lib/EventListener.js +0 -84
- package/lib/ExecutionEnvironment.js +0 -38
- package/lib/ReactDOMClient.js +0 -90
- package/lib/camelize.js +0 -32
- package/lib/camelizeStyleName.js +0 -40
- package/lib/containsNode.js +0 -55
- package/lib/createArrayFromMixed.js +0 -85
- package/lib/createNodesFromMarkup.js +0 -84
- package/lib/emptyFunction.js +0 -38
- package/lib/focusNode.js +0 -26
- package/lib/getActiveElement.js +0 -29
- package/lib/getMarkupWrap.js +0 -93
- package/lib/getUnboundedScrollPosition.js +0 -38
- package/lib/hyphenate.js +0 -33
- package/lib/hyphenateStyleName.js +0 -39
- package/lib/invariant.js +0 -49
- package/lib/isNode.js +0 -23
- package/lib/joinClasses.js +0 -39
- package/lib/keyMirror.js +0 -48
- package/lib/keyOf.js +0 -35
- package/lib/mapObject.js +0 -51
- package/lib/memoizeStringOnly.js +0 -31
- package/lib/performanceNow.js +0 -28
- package/lib/shallowEqual.js +0 -48
- package/lib/toArray.js +0 -57
- package/lib/warning.js +0 -57
|
@@ -18,15 +18,14 @@
|
|
|
18
18
|
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
|
-
var ReactElement = require(
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
21
|
+
var ReactElement = require('./ReactElement');
|
|
22
|
+
var ReactPropTypeLocations = require('./ReactPropTypeLocations');
|
|
23
|
+
var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
|
24
|
+
var ReactCurrentOwner = require('./ReactCurrentOwner');
|
|
26
25
|
|
|
27
|
-
var getIteratorFn = require(
|
|
28
|
-
var invariant = require(
|
|
29
|
-
var warning = require(
|
|
26
|
+
var getIteratorFn = require('./getIteratorFn');
|
|
27
|
+
var invariant = require('fbjs/lib/invariant');
|
|
28
|
+
var warning = require('fbjs/lib/warning');
|
|
30
29
|
|
|
31
30
|
function getDeclarationErrorAddendum() {
|
|
32
31
|
if (ReactCurrentOwner.current) {
|
|
@@ -47,37 +46,6 @@ var ownerHasKeyUseWarning = {};
|
|
|
47
46
|
|
|
48
47
|
var loggedTypeFailures = {};
|
|
49
48
|
|
|
50
|
-
var NUMERIC_PROPERTY_REGEX = /^\d+$/;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Gets the instance's name for use in warnings.
|
|
54
|
-
*
|
|
55
|
-
* @internal
|
|
56
|
-
* @return {?string} Display name or undefined
|
|
57
|
-
*/
|
|
58
|
-
function getName(instance) {
|
|
59
|
-
var publicInstance = instance && instance.getPublicInstance();
|
|
60
|
-
if (!publicInstance) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
var constructor = publicInstance.constructor;
|
|
64
|
-
if (!constructor) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
return constructor.displayName || constructor.name || undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Gets the current owner's displayName for use in warnings.
|
|
72
|
-
*
|
|
73
|
-
* @internal
|
|
74
|
-
* @return {?string} Display name or undefined
|
|
75
|
-
*/
|
|
76
|
-
function getCurrentOwnerDisplayName() {
|
|
77
|
-
var current = ReactCurrentOwner.current;
|
|
78
|
-
return current && getName(current) || undefined;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
49
|
/**
|
|
82
50
|
* Warn if the element doesn't have an explicit key assigned to it.
|
|
83
51
|
* This element is in an array. The array could grow and shrink or be
|
|
@@ -89,7 +57,7 @@ function getCurrentOwnerDisplayName() {
|
|
|
89
57
|
* @param {*} parentType element's parent's type.
|
|
90
58
|
*/
|
|
91
59
|
function validateExplicitKey(element, parentType) {
|
|
92
|
-
if (element._store.validated || element.key != null) {
|
|
60
|
+
if (!element._store || element._store.validated || element.key != null) {
|
|
93
61
|
return;
|
|
94
62
|
}
|
|
95
63
|
element._store.validated = true;
|
|
@@ -99,28 +67,7 @@ function validateExplicitKey(element, parentType) {
|
|
|
99
67
|
// we already showed the warning
|
|
100
68
|
return;
|
|
101
69
|
}
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Warn if the key is being defined as an object property but has an incorrect
|
|
107
|
-
* value.
|
|
108
|
-
*
|
|
109
|
-
* @internal
|
|
110
|
-
* @param {string} name Property name of the key.
|
|
111
|
-
* @param {ReactElement} element Component that requires a key.
|
|
112
|
-
* @param {*} parentType element's parent's type.
|
|
113
|
-
*/
|
|
114
|
-
function validatePropertyKey(name, element, parentType) {
|
|
115
|
-
if (!NUMERIC_PROPERTY_REGEX.test(name)) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
var addenda = getAddendaForKeyUse('numericKeys', element, parentType);
|
|
119
|
-
if (addenda === null) {
|
|
120
|
-
// we already showed the warning
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
'production' !== process.env.NODE_ENV ? warning(false, 'Child objects should have non-numeric keys so ordering is preserved.' + '%s%s%s', addenda.parentOrOwner || '', addenda.childOwner || '', addenda.url || '') : undefined;
|
|
70
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s%s', addenda.parentOrOwner || '', addenda.childOwner || '', addenda.url || '') : undefined;
|
|
124
71
|
}
|
|
125
72
|
|
|
126
73
|
/**
|
|
@@ -134,18 +81,22 @@ function validatePropertyKey(name, element, parentType) {
|
|
|
134
81
|
* if the warning has already been shown before (and shouldn't be shown again).
|
|
135
82
|
*/
|
|
136
83
|
function getAddendaForKeyUse(messageType, element, parentType) {
|
|
137
|
-
var
|
|
138
|
-
|
|
84
|
+
var addendum = getDeclarationErrorAddendum();
|
|
85
|
+
if (!addendum) {
|
|
86
|
+
var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
|
87
|
+
if (parentName) {
|
|
88
|
+
addendum = ' Check the top-level render call using <' + parentName + '>.';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
139
91
|
|
|
140
|
-
var useName = ownerName || parentName;
|
|
141
92
|
var memoizer = ownerHasKeyUseWarning[messageType] || (ownerHasKeyUseWarning[messageType] = {});
|
|
142
|
-
if (memoizer[
|
|
93
|
+
if (memoizer[addendum]) {
|
|
143
94
|
return null;
|
|
144
95
|
}
|
|
145
|
-
memoizer[
|
|
96
|
+
memoizer[addendum] = true;
|
|
146
97
|
|
|
147
98
|
var addenda = {
|
|
148
|
-
parentOrOwner:
|
|
99
|
+
parentOrOwner: addendum,
|
|
149
100
|
url: ' See https://fb.me/react-warning-keys for more information.',
|
|
150
101
|
childOwner: null
|
|
151
102
|
};
|
|
@@ -155,7 +106,7 @@ function getAddendaForKeyUse(messageType, element, parentType) {
|
|
|
155
106
|
// assigning it a key.
|
|
156
107
|
if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
|
|
157
108
|
// Give the component that originally created this child.
|
|
158
|
-
addenda.childOwner = ' It was passed a child from ' +
|
|
109
|
+
addenda.childOwner = ' It was passed a child from ' + element._owner.getName() + '.';
|
|
159
110
|
}
|
|
160
111
|
|
|
161
112
|
return addenda;
|
|
@@ -171,6 +122,9 @@ function getAddendaForKeyUse(messageType, element, parentType) {
|
|
|
171
122
|
* @param {*} parentType node's parent's type.
|
|
172
123
|
*/
|
|
173
124
|
function validateChildKeys(node, parentType) {
|
|
125
|
+
if (typeof node !== 'object') {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
174
128
|
if (Array.isArray(node)) {
|
|
175
129
|
for (var i = 0; i < node.length; i++) {
|
|
176
130
|
var child = node[i];
|
|
@@ -180,7 +134,9 @@ function validateChildKeys(node, parentType) {
|
|
|
180
134
|
}
|
|
181
135
|
} else if (ReactElement.isValidElement(node)) {
|
|
182
136
|
// This element was passed in a valid location.
|
|
183
|
-
node._store
|
|
137
|
+
if (node._store) {
|
|
138
|
+
node._store.validated = true;
|
|
139
|
+
}
|
|
184
140
|
} else if (node) {
|
|
185
141
|
var iteratorFn = getIteratorFn(node);
|
|
186
142
|
// Entry iterators provide implicit keys.
|
|
@@ -194,13 +150,6 @@ function validateChildKeys(node, parentType) {
|
|
|
194
150
|
}
|
|
195
151
|
}
|
|
196
152
|
}
|
|
197
|
-
} else if (typeof node === 'object') {
|
|
198
|
-
var fragment = ReactFragment.extractIfFragment(node);
|
|
199
|
-
for (var key in fragment) {
|
|
200
|
-
if (fragment.hasOwnProperty(key)) {
|
|
201
|
-
validatePropertyKey(key, fragment[key], parentType);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
153
|
}
|
|
205
154
|
}
|
|
206
155
|
}
|
|
@@ -224,19 +173,19 @@ function checkPropTypes(componentName, propTypes, props, location) {
|
|
|
224
173
|
try {
|
|
225
174
|
// This is intentionally an invariant that gets caught. It's the same
|
|
226
175
|
// behavior as without this statement except with a better message.
|
|
227
|
-
!(typeof propTypes[propName] === 'function') ?
|
|
176
|
+
!(typeof propTypes[propName] === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(false) : undefined;
|
|
228
177
|
error = propTypes[propName](props, propName, componentName, location);
|
|
229
178
|
} catch (ex) {
|
|
230
179
|
error = ex;
|
|
231
180
|
}
|
|
232
|
-
|
|
181
|
+
process.env.NODE_ENV !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], propName, typeof error) : undefined;
|
|
233
182
|
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
234
183
|
// Only monitor this failure once because there tends to be a lot of the
|
|
235
184
|
// same error.
|
|
236
185
|
loggedTypeFailures[error.message] = true;
|
|
237
186
|
|
|
238
187
|
var addendum = getDeclarationErrorAddendum();
|
|
239
|
-
|
|
188
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Failed propType: %s%s', error.message, addendum) : undefined;
|
|
240
189
|
}
|
|
241
190
|
}
|
|
242
191
|
}
|
|
@@ -258,16 +207,17 @@ function validatePropTypes(element) {
|
|
|
258
207
|
checkPropTypes(name, componentClass.propTypes, element.props, ReactPropTypeLocations.prop);
|
|
259
208
|
}
|
|
260
209
|
if (typeof componentClass.getDefaultProps === 'function') {
|
|
261
|
-
|
|
210
|
+
process.env.NODE_ENV !== 'production' ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : undefined;
|
|
262
211
|
}
|
|
263
212
|
}
|
|
264
213
|
|
|
265
214
|
var ReactElementValidator = {
|
|
266
215
|
|
|
267
216
|
createElement: function (type, props, children) {
|
|
217
|
+
var validType = typeof type === 'string' || typeof type === 'function';
|
|
268
218
|
// We warn in this case but don't throw. We expect the element creation to
|
|
269
219
|
// succeed and there will likely be errors in render.
|
|
270
|
-
|
|
220
|
+
process.env.NODE_ENV !== 'production' ? warning(validType, 'React.createElement: type should not be null, undefined, boolean, or ' + 'number. It should be a string (for DOM elements) or a ReactClass ' + '(for composite components).%s', getDeclarationErrorAddendum()) : undefined;
|
|
271
221
|
|
|
272
222
|
var element = ReactElement.createElement.apply(this, arguments);
|
|
273
223
|
|
|
@@ -277,8 +227,15 @@ var ReactElementValidator = {
|
|
|
277
227
|
return element;
|
|
278
228
|
}
|
|
279
229
|
|
|
280
|
-
|
|
281
|
-
|
|
230
|
+
// Skip key warning if the type isn't valid since our key validation logic
|
|
231
|
+
// doesn't expect a non-string/function type and can throw confusing errors.
|
|
232
|
+
// We don't want exception behavior to differ between dev and prod.
|
|
233
|
+
// (Rendering will throw with a helpful message and as soon as the type is
|
|
234
|
+
// fixed, the key warnings will appear.)
|
|
235
|
+
if (validType) {
|
|
236
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
237
|
+
validateChildKeys(arguments[i], type);
|
|
238
|
+
}
|
|
282
239
|
}
|
|
283
240
|
|
|
284
241
|
validatePropTypes(element);
|
|
@@ -291,19 +248,21 @@ var ReactElementValidator = {
|
|
|
291
248
|
// Legacy hook TODO: Warn if this is accessed
|
|
292
249
|
validatedFactory.type = type;
|
|
293
250
|
|
|
294
|
-
if (
|
|
251
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
295
252
|
try {
|
|
296
253
|
Object.defineProperty(validatedFactory, 'type', {
|
|
297
254
|
enumerable: false,
|
|
298
255
|
get: function () {
|
|
299
|
-
|
|
256
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : undefined;
|
|
300
257
|
Object.defineProperty(this, 'type', {
|
|
301
258
|
value: type
|
|
302
259
|
});
|
|
303
260
|
return type;
|
|
304
261
|
}
|
|
305
262
|
});
|
|
306
|
-
} catch (x) {
|
|
263
|
+
} catch (x) {
|
|
264
|
+
// IE will fail on defineProperty (es5-shim/sham too)
|
|
265
|
+
}
|
|
307
266
|
}
|
|
308
267
|
|
|
309
268
|
return validatedFactory;
|
|
@@ -320,6 +279,4 @@ var ReactElementValidator = {
|
|
|
320
279
|
|
|
321
280
|
};
|
|
322
281
|
|
|
323
|
-
module.exports = ReactElementValidator;
|
|
324
|
-
|
|
325
|
-
// IE will fail on defineProperty (es5-shim/sham too)
|
|
282
|
+
module.exports = ReactElementValidator;
|
|
@@ -11,77 +11,41 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var ReactElement = require(
|
|
15
|
-
var
|
|
14
|
+
var ReactElement = require('./ReactElement');
|
|
15
|
+
var ReactEmptyComponentRegistry = require('./ReactEmptyComponentRegistry');
|
|
16
|
+
var ReactReconciler = require('./ReactReconciler');
|
|
16
17
|
|
|
17
|
-
var
|
|
18
|
+
var assign = require('./Object.assign');
|
|
18
19
|
|
|
19
|
-
var
|
|
20
|
-
// This registry keeps track of the React IDs of the components that rendered to
|
|
21
|
-
// `null` (in reality a placeholder such as `noscript`)
|
|
22
|
-
var nullComponentIDsRegistry = {};
|
|
20
|
+
var placeholderElement;
|
|
23
21
|
|
|
24
22
|
var ReactEmptyComponentInjection = {
|
|
25
|
-
injectEmptyComponent: function (
|
|
26
|
-
|
|
23
|
+
injectEmptyComponent: function (component) {
|
|
24
|
+
placeholderElement = ReactElement.createElement(component);
|
|
27
25
|
}
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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);
|
|
28
|
+
var ReactEmptyComponent = function (instantiate) {
|
|
29
|
+
this._currentElement = null;
|
|
30
|
+
this._rootNodeID = null;
|
|
31
|
+
this._renderedComponent = instantiate(placeholderElement);
|
|
41
32
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
assign(ReactEmptyComponent.prototype, {
|
|
34
|
+
construct: function (element) {},
|
|
35
|
+
mountComponent: function (rootID, transaction, context) {
|
|
36
|
+
ReactEmptyComponentRegistry.registerNullComponentID(rootID);
|
|
37
|
+
this._rootNodeID = rootID;
|
|
38
|
+
return ReactReconciler.mountComponent(this._renderedComponent, rootID, transaction, context);
|
|
39
|
+
},
|
|
40
|
+
receiveComponent: function () {},
|
|
41
|
+
unmountComponent: function (rootID, transaction, context) {
|
|
42
|
+
ReactReconciler.unmountComponent(this._renderedComponent);
|
|
43
|
+
ReactEmptyComponentRegistry.deregisterNullComponentID(this._rootNodeID);
|
|
44
|
+
this._rootNodeID = null;
|
|
45
|
+
this._renderedComponent = null;
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
ReactEmptyComponentType.prototype.render = function () {
|
|
51
|
-
!component ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Trying to return null from a render, but no null placeholder component ' + 'was injected.') : invariant(false) : undefined;
|
|
52
|
-
return component();
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
var emptyElement = ReactElement.createElement(ReactEmptyComponentType);
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Mark the component as having rendered to null.
|
|
59
|
-
* @param {string} id Component's `_rootNodeID`.
|
|
60
|
-
*/
|
|
61
|
-
function registerNullComponentID(id) {
|
|
62
|
-
nullComponentIDsRegistry[id] = true;
|
|
63
|
-
}
|
|
47
|
+
});
|
|
64
48
|
|
|
65
|
-
|
|
66
|
-
* Unmark the component as having rendered to null: it renders to something now.
|
|
67
|
-
* @param {string} id Component's `_rootNodeID`.
|
|
68
|
-
*/
|
|
69
|
-
function deregisterNullComponentID(id) {
|
|
70
|
-
delete nullComponentIDsRegistry[id];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @param {string} id Component's `_rootNodeID`.
|
|
75
|
-
* @return {boolean} True if the component is rendered to null.
|
|
76
|
-
*/
|
|
77
|
-
function isNullComponentID(id) {
|
|
78
|
-
return !!nullComponentIDsRegistry[id];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var ReactEmptyComponent = {
|
|
82
|
-
emptyElement: emptyElement,
|
|
83
|
-
injection: ReactEmptyComponentInjection,
|
|
84
|
-
isNullComponentID: isNullComponentID
|
|
85
|
-
};
|
|
49
|
+
ReactEmptyComponent.injection = ReactEmptyComponentInjection;
|
|
86
50
|
|
|
87
51
|
module.exports = ReactEmptyComponent;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014-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 ReactEmptyComponentRegistry
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
// This registry keeps track of the React IDs of the components that rendered to
|
|
15
|
+
// `null` (in reality a placeholder such as `noscript`)
|
|
16
|
+
var nullComponentIDsRegistry = {};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} id Component's `_rootNodeID`.
|
|
20
|
+
* @return {boolean} True if the component is rendered to null.
|
|
21
|
+
*/
|
|
22
|
+
function isNullComponentID(id) {
|
|
23
|
+
return !!nullComponentIDsRegistry[id];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Mark the component as having rendered to null.
|
|
28
|
+
* @param {string} id Component's `_rootNodeID`.
|
|
29
|
+
*/
|
|
30
|
+
function registerNullComponentID(id) {
|
|
31
|
+
nullComponentIDsRegistry[id] = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Unmark the component as having rendered to null: it renders to something now.
|
|
36
|
+
* @param {string} id Component's `_rootNodeID`.
|
|
37
|
+
*/
|
|
38
|
+
function deregisterNullComponentID(id) {
|
|
39
|
+
delete nullComponentIDsRegistry[id];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var ReactEmptyComponentRegistry = {
|
|
43
|
+
isNullComponentID: isNullComponentID,
|
|
44
|
+
registerNullComponentID: registerNullComponentID,
|
|
45
|
+
deregisterNullComponentID: deregisterNullComponentID
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = ReactEmptyComponentRegistry;
|
package/lib/ReactErrorUtils.js
CHANGED
|
@@ -12,19 +12,63 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
+
var caughtError = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Call a function while guarding against errors that happens within it.
|
|
19
|
+
*
|
|
20
|
+
* @param {?String} name of the guard to use for logging or debugging
|
|
21
|
+
* @param {Function} func The function to invoke
|
|
22
|
+
* @param {*} a First argument
|
|
23
|
+
* @param {*} b Second argument
|
|
24
|
+
*/
|
|
25
|
+
function invokeGuardedCallback(name, func, a, b) {
|
|
26
|
+
try {
|
|
27
|
+
return func(a, b);
|
|
28
|
+
} catch (x) {
|
|
29
|
+
if (caughtError === null) {
|
|
30
|
+
caughtError = x;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
var ReactErrorUtils = {
|
|
37
|
+
invokeGuardedCallback: invokeGuardedCallback,
|
|
38
|
+
|
|
16
39
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* this currently simply returns the original function.
|
|
20
|
-
*
|
|
21
|
-
* @param {function} func Function to be executed
|
|
22
|
-
* @param {string} name The name of the guard
|
|
23
|
-
* @return {function}
|
|
40
|
+
* Invoked by ReactTestUtils.Simulate so that any errors thrown by the event
|
|
41
|
+
* handler are sure to be rethrown by rethrowCaughtError.
|
|
24
42
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
invokeGuardedCallbackWithCatch: invokeGuardedCallback,
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* During execution of guarded functions we will capture the first error which
|
|
47
|
+
* we will rethrow to be handled by the top level error handler.
|
|
48
|
+
*/
|
|
49
|
+
rethrowCaughtError: function () {
|
|
50
|
+
if (caughtError) {
|
|
51
|
+
var error = caughtError;
|
|
52
|
+
caughtError = null;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
27
55
|
}
|
|
28
56
|
};
|
|
29
57
|
|
|
58
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
59
|
+
/**
|
|
60
|
+
* To help development we can get better devtools integration by simulating a
|
|
61
|
+
* real browser event.
|
|
62
|
+
*/
|
|
63
|
+
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof Event === 'function') {
|
|
64
|
+
var fakeNode = document.createElement('react');
|
|
65
|
+
ReactErrorUtils.invokeGuardedCallback = function (name, func, a, b) {
|
|
66
|
+
var boundFunc = func.bind(null, a, b);
|
|
67
|
+
fakeNode.addEventListener(name, boundFunc, false);
|
|
68
|
+
fakeNode.dispatchEvent(new Event(name));
|
|
69
|
+
fakeNode.removeEventListener(name, boundFunc, false);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
30
74
|
module.exports = ReactErrorUtils;
|