react 0.12.2 → 0.13.0-alpha.1
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 +6 -4
- package/dist/react-with-addons.js +4022 -3267
- package/dist/react-with-addons.min.js +6 -6
- package/dist/react.js +3853 -3358
- package/dist/react.min.js +6 -6
- package/lib/BeforeInputEventPlugin.js +388 -111
- package/lib/CSSPropertyOperations.js +20 -0
- package/lib/ChangeEventPlugin.js +2 -2
- package/lib/Danger.js +1 -1
- package/lib/DefaultEventPluginOrder.js +0 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +87 -0
- package/lib/HTMLDOMPropertyConfig.js +1 -0
- package/lib/Object.assign.js +3 -1
- package/lib/React.js +14 -49
- package/lib/ReactBrowserComponentMixin.js +2 -12
- package/lib/ReactBrowserEventEmitter.js +2 -4
- package/lib/ReactCSSTransitionGroup.js +3 -0
- package/lib/ReactCSSTransitionGroupChild.js +8 -0
- package/lib/ReactChildReconciler.js +121 -0
- package/lib/ReactClass.js +916 -0
- package/lib/ReactComponent.js +36 -286
- package/lib/ReactComponentBrowserEnvironment.js +9 -82
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactCompositeComponent.js +608 -1026
- package/lib/ReactContext.js +5 -1
- package/lib/ReactDOM.js +2 -7
- package/lib/ReactDOMButton.js +4 -5
- package/lib/ReactDOMComponent.js +97 -69
- package/lib/ReactDOMForm.js +4 -5
- package/lib/ReactDOMIDOperations.js +55 -73
- package/lib/ReactDOMImg.js +3 -5
- package/lib/ReactDOMInput.js +4 -5
- package/lib/ReactDOMOption.js +4 -5
- package/lib/ReactDOMSelect.js +55 -63
- package/lib/ReactDOMSelection.js +5 -1
- package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +54 -34
- package/lib/ReactDOMTextarea.js +4 -5
- package/lib/ReactDefaultInjection.js +13 -7
- package/lib/ReactDefaultPerf.js +6 -5
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +17 -11
- package/lib/ReactElementValidator.js +74 -37
- package/lib/ReactEmptyComponent.js +17 -10
- package/lib/ReactInjection.js +6 -4
- package/lib/ReactInputSelection.js +2 -3
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactMount.js +193 -64
- package/lib/ReactMultiChild.js +32 -42
- package/lib/ReactNativeComponent.js +45 -8
- package/lib/ReactOwner.js +3 -47
- package/lib/ReactPerf.js +20 -0
- package/lib/ReactPropTransferer.js +0 -55
- package/lib/ReactPropTypes.js +1 -17
- package/lib/ReactRef.js +96 -0
- package/lib/ReactServerRendering.js +3 -2
- package/lib/ReactTestUtils.js +82 -25
- package/lib/ReactTransitionGroup.js +47 -6
- package/lib/ReactUpdates.js +43 -42
- package/lib/SyntheticMouseEvent.js +1 -3
- package/lib/ViewportMetrics.js +1 -4
- package/lib/accumulate.js +47 -0
- package/lib/cloneWithProps.js +2 -2
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +2 -2
- package/lib/findDOMNode.js +52 -0
- package/lib/flattenChildren.js +1 -14
- package/lib/getIteratorFn.js +42 -0
- package/lib/instantiateReactComponent.js +88 -65
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +1 -2
- package/lib/shouldUpdateReactComponent.js +13 -5
- package/lib/traverseAllChildren.js +110 -54
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/deprecated.js +0 -47
package/lib/ReactComponent.js
CHANGED
|
@@ -11,50 +11,26 @@
|
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
13
13
|
|
|
14
|
-
var ReactElement = require("./ReactElement");
|
|
15
14
|
var ReactOwner = require("./ReactOwner");
|
|
16
|
-
var
|
|
15
|
+
var ReactRef = require("./ReactRef");
|
|
17
16
|
|
|
18
|
-
var assign = require("./Object.assign");
|
|
19
17
|
var invariant = require("./invariant");
|
|
20
|
-
var keyMirror = require("./keyMirror");
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
MOUNTED: null,
|
|
31
|
-
/**
|
|
32
|
-
* Unmounted components are inactive and cannot receive new props.
|
|
33
|
-
*/
|
|
34
|
-
UNMOUNTED: null
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
var injected = false;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Optionally injectable environment dependent cleanup hook. (server vs.
|
|
41
|
-
* browser etc). Example: A browser system caches DOM nodes based on component
|
|
42
|
-
* ID and must remove that cache entry when this instance is unmounted.
|
|
43
|
-
*
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
var unmountIDFromEnvironment = null;
|
|
19
|
+
function attachRef(ref, component, owner) {
|
|
20
|
+
if (ref instanceof ReactRef) {
|
|
21
|
+
ReactRef.attachRef(ref, component);
|
|
22
|
+
} else {
|
|
23
|
+
ReactOwner.addComponentAsRefTo(component, ref, owner);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
47
26
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @private
|
|
56
|
-
*/
|
|
57
|
-
var mountImageIntoNode = null;
|
|
27
|
+
function detachRef(ref, component, owner) {
|
|
28
|
+
if (ref instanceof ReactRef) {
|
|
29
|
+
ReactRef.detachRef(ref, component);
|
|
30
|
+
} else {
|
|
31
|
+
ReactOwner.removeComponentAsRefFrom(component, ref, owner);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
58
34
|
|
|
59
35
|
/**
|
|
60
36
|
* Components are the basic units of composition in React.
|
|
@@ -83,26 +59,6 @@ var mountImageIntoNode = null;
|
|
|
83
59
|
*/
|
|
84
60
|
var ReactComponent = {
|
|
85
61
|
|
|
86
|
-
injection: {
|
|
87
|
-
injectEnvironment: function(ReactComponentEnvironment) {
|
|
88
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
89
|
-
!injected,
|
|
90
|
-
'ReactComponent: injectEnvironment() can only be called once.'
|
|
91
|
-
) : invariant(!injected));
|
|
92
|
-
mountImageIntoNode = ReactComponentEnvironment.mountImageIntoNode;
|
|
93
|
-
unmountIDFromEnvironment =
|
|
94
|
-
ReactComponentEnvironment.unmountIDFromEnvironment;
|
|
95
|
-
ReactComponent.BackendIDOperations =
|
|
96
|
-
ReactComponentEnvironment.BackendIDOperations;
|
|
97
|
-
injected = true;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
LifeCycle: ComponentLifeCycle,
|
|
105
|
-
|
|
106
62
|
/**
|
|
107
63
|
* Injected module that provides ability to mutate individual properties.
|
|
108
64
|
* Injected into the base class because many different subclasses need access
|
|
@@ -120,84 +76,6 @@ var ReactComponent = {
|
|
|
120
76
|
*/
|
|
121
77
|
Mixin: {
|
|
122
78
|
|
|
123
|
-
/**
|
|
124
|
-
* Checks whether or not this component is mounted.
|
|
125
|
-
*
|
|
126
|
-
* @return {boolean} True if mounted, false otherwise.
|
|
127
|
-
* @final
|
|
128
|
-
* @protected
|
|
129
|
-
*/
|
|
130
|
-
isMounted: function() {
|
|
131
|
-
return this._lifeCycleState === ComponentLifeCycle.MOUNTED;
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Sets a subset of the props.
|
|
136
|
-
*
|
|
137
|
-
* @param {object} partialProps Subset of the next props.
|
|
138
|
-
* @param {?function} callback Called after props are updated.
|
|
139
|
-
* @final
|
|
140
|
-
* @public
|
|
141
|
-
*/
|
|
142
|
-
setProps: function(partialProps, callback) {
|
|
143
|
-
// Merge with the pending element if it exists, otherwise with existing
|
|
144
|
-
// element props.
|
|
145
|
-
var element = this._pendingElement || this._currentElement;
|
|
146
|
-
this.replaceProps(
|
|
147
|
-
assign({}, element.props, partialProps),
|
|
148
|
-
callback
|
|
149
|
-
);
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Replaces all of the props.
|
|
154
|
-
*
|
|
155
|
-
* @param {object} props New props.
|
|
156
|
-
* @param {?function} callback Called after props are updated.
|
|
157
|
-
* @final
|
|
158
|
-
* @public
|
|
159
|
-
*/
|
|
160
|
-
replaceProps: function(props, callback) {
|
|
161
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
162
|
-
this.isMounted(),
|
|
163
|
-
'replaceProps(...): Can only update a mounted component.'
|
|
164
|
-
) : invariant(this.isMounted()));
|
|
165
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
166
|
-
this._mountDepth === 0,
|
|
167
|
-
'replaceProps(...): You called `setProps` or `replaceProps` on a ' +
|
|
168
|
-
'component with a parent. This is an anti-pattern since props will ' +
|
|
169
|
-
'get reactively updated when rendered. Instead, change the owner\'s ' +
|
|
170
|
-
'`render` method to pass the correct value as props to the component ' +
|
|
171
|
-
'where it is created.'
|
|
172
|
-
) : invariant(this._mountDepth === 0));
|
|
173
|
-
// This is a deoptimized path. We optimize for always having a element.
|
|
174
|
-
// This creates an extra internal element.
|
|
175
|
-
this._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
176
|
-
this._pendingElement || this._currentElement,
|
|
177
|
-
props
|
|
178
|
-
);
|
|
179
|
-
ReactUpdates.enqueueUpdate(this, callback);
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Schedule a partial update to the props. Only used for internal testing.
|
|
184
|
-
*
|
|
185
|
-
* @param {object} partialProps Subset of the next props.
|
|
186
|
-
* @param {?function} callback Called after props are updated.
|
|
187
|
-
* @final
|
|
188
|
-
* @internal
|
|
189
|
-
*/
|
|
190
|
-
_setPropsInternal: function(partialProps, callback) {
|
|
191
|
-
// This is a deoptimized path. We optimize for always having a element.
|
|
192
|
-
// This creates an extra internal element.
|
|
193
|
-
var element = this._pendingElement || this._currentElement;
|
|
194
|
-
this._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
195
|
-
element,
|
|
196
|
-
assign({}, element.props, partialProps)
|
|
197
|
-
);
|
|
198
|
-
ReactUpdates.enqueueUpdate(this, callback);
|
|
199
|
-
},
|
|
200
|
-
|
|
201
79
|
/**
|
|
202
80
|
* Base constructor for all React components.
|
|
203
81
|
*
|
|
@@ -208,26 +86,14 @@ var ReactComponent = {
|
|
|
208
86
|
* @internal
|
|
209
87
|
*/
|
|
210
88
|
construct: function(element) {
|
|
211
|
-
// This is the public exposed props object after it has been processed
|
|
212
|
-
// with default props. The element's props represents the true internal
|
|
213
|
-
// state of the props.
|
|
214
|
-
this.props = element.props;
|
|
215
|
-
// Record the component responsible for creating this component.
|
|
216
|
-
// This is accessible through the element but we maintain an extra
|
|
217
|
-
// field for compatibility with devtools and as a way to make an
|
|
218
|
-
// incremental update. TODO: Consider deprecating this field.
|
|
219
|
-
this._owner = element._owner;
|
|
220
|
-
|
|
221
|
-
// All components start unmounted.
|
|
222
|
-
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
223
|
-
|
|
224
|
-
// See ReactUpdates.
|
|
225
|
-
this._pendingCallbacks = null;
|
|
226
|
-
|
|
227
89
|
// We keep the old element and a reference to the pending element
|
|
228
90
|
// to track updates.
|
|
229
91
|
this._currentElement = element;
|
|
230
|
-
|
|
92
|
+
// These two fields are used by the DOM and ART diffing algorithms
|
|
93
|
+
// respectively. Instead of using expandos on components, we should be
|
|
94
|
+
// storing the state needed by the diffing algorithms elsewhere.
|
|
95
|
+
this._mountIndex = 0;
|
|
96
|
+
this._mountImage = null;
|
|
231
97
|
},
|
|
232
98
|
|
|
233
99
|
/**
|
|
@@ -240,26 +106,15 @@ var ReactComponent = {
|
|
|
240
106
|
*
|
|
241
107
|
* @param {string} rootID DOM ID of the root node.
|
|
242
108
|
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
|
243
|
-
* @param {number} mountDepth number of components in the owner hierarchy.
|
|
244
109
|
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
245
110
|
* @internal
|
|
246
111
|
*/
|
|
247
|
-
mountComponent: function(rootID, transaction,
|
|
248
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
249
|
-
!this.isMounted(),
|
|
250
|
-
'mountComponent(%s, ...): Can only mount an unmounted component. ' +
|
|
251
|
-
'Make sure to avoid storing components between renders or reusing a ' +
|
|
252
|
-
'single component instance in multiple places.',
|
|
253
|
-
rootID
|
|
254
|
-
) : invariant(!this.isMounted()));
|
|
112
|
+
mountComponent: function(rootID, transaction, context) {
|
|
255
113
|
var ref = this._currentElement.ref;
|
|
256
114
|
if (ref != null) {
|
|
257
115
|
var owner = this._currentElement._owner;
|
|
258
|
-
|
|
116
|
+
attachRef(ref, this, owner);
|
|
259
117
|
}
|
|
260
|
-
this._rootNodeID = rootID;
|
|
261
|
-
this._lifeCycleState = ComponentLifeCycle.MOUNTED;
|
|
262
|
-
this._mountDepth = mountDepth;
|
|
263
118
|
// Effectively: return '';
|
|
264
119
|
},
|
|
265
120
|
|
|
@@ -274,56 +129,10 @@ var ReactComponent = {
|
|
|
274
129
|
* @internal
|
|
275
130
|
*/
|
|
276
131
|
unmountComponent: function() {
|
|
277
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
278
|
-
this.isMounted(),
|
|
279
|
-
'unmountComponent(): Can only unmount a mounted component.'
|
|
280
|
-
) : invariant(this.isMounted()));
|
|
281
132
|
var ref = this._currentElement.ref;
|
|
282
133
|
if (ref != null) {
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
unmountIDFromEnvironment(this._rootNodeID);
|
|
286
|
-
this._rootNodeID = null;
|
|
287
|
-
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
288
|
-
},
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Given a new instance of this component, updates the rendered DOM nodes
|
|
292
|
-
* as if that instance was rendered instead.
|
|
293
|
-
*
|
|
294
|
-
* Subclasses that override this method should make sure to invoke
|
|
295
|
-
* `ReactComponent.Mixin.receiveComponent.call(this, ...)`.
|
|
296
|
-
*
|
|
297
|
-
* @param {object} nextComponent Next set of properties.
|
|
298
|
-
* @param {ReactReconcileTransaction} transaction
|
|
299
|
-
* @internal
|
|
300
|
-
*/
|
|
301
|
-
receiveComponent: function(nextElement, transaction) {
|
|
302
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
303
|
-
this.isMounted(),
|
|
304
|
-
'receiveComponent(...): Can only update a mounted component.'
|
|
305
|
-
) : invariant(this.isMounted()));
|
|
306
|
-
this._pendingElement = nextElement;
|
|
307
|
-
this.performUpdateIfNecessary(transaction);
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* If `_pendingElement` is set, update the component.
|
|
312
|
-
*
|
|
313
|
-
* @param {ReactReconcileTransaction} transaction
|
|
314
|
-
* @internal
|
|
315
|
-
*/
|
|
316
|
-
performUpdateIfNecessary: function(transaction) {
|
|
317
|
-
if (this._pendingElement == null) {
|
|
318
|
-
return;
|
|
134
|
+
detachRef(ref, this, this._currentElement._owner);
|
|
319
135
|
}
|
|
320
|
-
var prevElement = this._currentElement;
|
|
321
|
-
var nextElement = this._pendingElement;
|
|
322
|
-
this._currentElement = nextElement;
|
|
323
|
-
this.props = nextElement.props;
|
|
324
|
-
this._owner = nextElement._owner;
|
|
325
|
-
this._pendingElement = null;
|
|
326
|
-
this.updateComponent(transaction, prevElement);
|
|
327
136
|
},
|
|
328
137
|
|
|
329
138
|
/**
|
|
@@ -331,11 +140,10 @@ var ReactComponent = {
|
|
|
331
140
|
*
|
|
332
141
|
* @param {ReactReconcileTransaction} transaction
|
|
333
142
|
* @param {object} prevElement
|
|
143
|
+
* @param {object} nextElement
|
|
334
144
|
* @internal
|
|
335
145
|
*/
|
|
336
|
-
updateComponent: function(transaction, prevElement) {
|
|
337
|
-
var nextElement = this._currentElement;
|
|
338
|
-
|
|
146
|
+
updateComponent: function(transaction, prevElement, nextElement, context) {
|
|
339
147
|
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
340
148
|
// has stored a reference to `this`, and the previous owner (if different)
|
|
341
149
|
// has forgotten the reference to `this`. We use the element instead
|
|
@@ -351,87 +159,29 @@ var ReactComponent = {
|
|
|
351
159
|
if (nextElement._owner !== prevElement._owner ||
|
|
352
160
|
nextElement.ref !== prevElement.ref) {
|
|
353
161
|
if (prevElement.ref != null) {
|
|
354
|
-
|
|
355
|
-
this, prevElement.ref, prevElement._owner
|
|
356
|
-
);
|
|
162
|
+
detachRef(prevElement.ref, this, prevElement._owner);
|
|
357
163
|
}
|
|
358
164
|
// Correct, even if the owner is the same, and only the ref has changed.
|
|
359
165
|
if (nextElement.ref != null) {
|
|
360
|
-
|
|
361
|
-
this,
|
|
362
|
-
nextElement.ref,
|
|
363
|
-
nextElement._owner
|
|
364
|
-
);
|
|
166
|
+
attachRef(nextElement.ref, this, nextElement._owner);
|
|
365
167
|
}
|
|
366
168
|
}
|
|
367
169
|
},
|
|
368
170
|
|
|
369
171
|
/**
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* @param {DOMElement} container DOM element to mount into.
|
|
374
|
-
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
375
|
-
* @final
|
|
376
|
-
* @internal
|
|
377
|
-
* @see {ReactMount.render}
|
|
378
|
-
*/
|
|
379
|
-
mountComponentIntoNode: function(rootID, container, shouldReuseMarkup) {
|
|
380
|
-
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
381
|
-
transaction.perform(
|
|
382
|
-
this._mountComponentIntoNode,
|
|
383
|
-
this,
|
|
384
|
-
rootID,
|
|
385
|
-
container,
|
|
386
|
-
transaction,
|
|
387
|
-
shouldReuseMarkup
|
|
388
|
-
);
|
|
389
|
-
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
390
|
-
},
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* @param {string} rootID DOM ID of the root node.
|
|
394
|
-
* @param {DOMElement} container DOM element to mount into.
|
|
395
|
-
* @param {ReactReconcileTransaction} transaction
|
|
396
|
-
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
397
|
-
* @final
|
|
398
|
-
* @private
|
|
399
|
-
*/
|
|
400
|
-
_mountComponentIntoNode: function(
|
|
401
|
-
rootID,
|
|
402
|
-
container,
|
|
403
|
-
transaction,
|
|
404
|
-
shouldReuseMarkup) {
|
|
405
|
-
var markup = this.mountComponent(rootID, transaction, 0);
|
|
406
|
-
mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
407
|
-
},
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Checks if this component is owned by the supplied `owner` component.
|
|
172
|
+
* Get the publicly accessible representation of this component - i.e. what
|
|
173
|
+
* is exposed by refs and returned by React.render. Can be null for
|
|
174
|
+
* stateless components.
|
|
411
175
|
*
|
|
412
|
-
* @param {ReactComponent} owner Component to check.
|
|
413
|
-
* @return {boolean} True if `owners` owns this component.
|
|
414
|
-
* @final
|
|
415
|
-
* @internal
|
|
416
|
-
*/
|
|
417
|
-
isOwnedBy: function(owner) {
|
|
418
|
-
return this._owner === owner;
|
|
419
|
-
},
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Gets another component, that shares the same owner as this one, by ref.
|
|
423
|
-
*
|
|
424
|
-
* @param {string} ref of a sibling Component.
|
|
425
176
|
* @return {?ReactComponent} the actual sibling Component.
|
|
426
|
-
* @final
|
|
427
177
|
* @internal
|
|
428
178
|
*/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
179
|
+
getPublicInstance: function() {
|
|
180
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
181
|
+
false,
|
|
182
|
+
'getPublicInstance should never be called on the base class. It must ' +
|
|
183
|
+
'be overridden.'
|
|
184
|
+
) : invariant(false));
|
|
435
185
|
}
|
|
436
186
|
}
|
|
437
187
|
};
|
|
@@ -14,28 +14,20 @@
|
|
|
14
14
|
"use strict";
|
|
15
15
|
|
|
16
16
|
var ReactDOMIDOperations = require("./ReactDOMIDOperations");
|
|
17
|
-
var ReactMarkupChecksum = require("./ReactMarkupChecksum");
|
|
18
17
|
var ReactMount = require("./ReactMount");
|
|
19
|
-
var ReactPerf = require("./ReactPerf");
|
|
20
|
-
var ReactReconcileTransaction = require("./ReactReconcileTransaction");
|
|
21
|
-
|
|
22
|
-
var getReactRootElementInContainer = require("./getReactRootElementInContainer");
|
|
23
|
-
var invariant = require("./invariant");
|
|
24
|
-
var setInnerHTML = require("./setInnerHTML");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var ELEMENT_NODE_TYPE = 1;
|
|
28
|
-
var DOC_NODE_TYPE = 9;
|
|
29
|
-
|
|
30
18
|
|
|
31
19
|
/**
|
|
32
|
-
* Abstracts away all functionality of
|
|
33
|
-
* the browser context.
|
|
20
|
+
* Abstracts away all functionality of the reconciler that requires knowledge of
|
|
21
|
+
* the browser context. TODO: These callers should be refactored to avoid the
|
|
22
|
+
* need for this injection.
|
|
34
23
|
*/
|
|
35
24
|
var ReactComponentBrowserEnvironment = {
|
|
36
|
-
ReactReconcileTransaction: ReactReconcileTransaction,
|
|
37
25
|
|
|
38
|
-
|
|
26
|
+
processChildrenUpdates:
|
|
27
|
+
ReactDOMIDOperations.dangerouslyProcessChildrenUpdates,
|
|
28
|
+
|
|
29
|
+
replaceNodeWithMarkupByID:
|
|
30
|
+
ReactDOMIDOperations.dangerouslyReplaceNodeWithMarkupByID,
|
|
39
31
|
|
|
40
32
|
/**
|
|
41
33
|
* If a particular environment requires that some resources be cleaned up,
|
|
@@ -46,73 +38,8 @@ var ReactComponentBrowserEnvironment = {
|
|
|
46
38
|
*/
|
|
47
39
|
unmountIDFromEnvironment: function(rootNodeID) {
|
|
48
40
|
ReactMount.purgeID(rootNodeID);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param {string} markup Markup string to place into the DOM Element.
|
|
53
|
-
* @param {DOMElement} container DOM Element to insert markup into.
|
|
54
|
-
* @param {boolean} shouldReuseMarkup Should reuse the existing markup in the
|
|
55
|
-
* container if possible.
|
|
56
|
-
*/
|
|
57
|
-
mountImageIntoNode: ReactPerf.measure(
|
|
58
|
-
'ReactComponentBrowserEnvironment',
|
|
59
|
-
'mountImageIntoNode',
|
|
60
|
-
function(markup, container, shouldReuseMarkup) {
|
|
61
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
62
|
-
container && (
|
|
63
|
-
container.nodeType === ELEMENT_NODE_TYPE ||
|
|
64
|
-
container.nodeType === DOC_NODE_TYPE
|
|
65
|
-
),
|
|
66
|
-
'mountComponentIntoNode(...): Target container is not valid.'
|
|
67
|
-
) : invariant(container && (
|
|
68
|
-
container.nodeType === ELEMENT_NODE_TYPE ||
|
|
69
|
-
container.nodeType === DOC_NODE_TYPE
|
|
70
|
-
)));
|
|
71
|
-
|
|
72
|
-
if (shouldReuseMarkup) {
|
|
73
|
-
if (ReactMarkupChecksum.canReuseMarkup(
|
|
74
|
-
markup,
|
|
75
|
-
getReactRootElementInContainer(container))) {
|
|
76
|
-
return;
|
|
77
|
-
} else {
|
|
78
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
79
|
-
container.nodeType !== DOC_NODE_TYPE,
|
|
80
|
-
'You\'re trying to render a component to the document using ' +
|
|
81
|
-
'server rendering but the checksum was invalid. This usually ' +
|
|
82
|
-
'means you rendered a different component type or props on ' +
|
|
83
|
-
'the client from the one on the server, or your render() ' +
|
|
84
|
-
'methods are impure. React cannot handle this case due to ' +
|
|
85
|
-
'cross-browser quirks by rendering at the document root. You ' +
|
|
86
|
-
'should look for environment dependent code in your components ' +
|
|
87
|
-
'and ensure the props are the same client and server side.'
|
|
88
|
-
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
89
|
-
|
|
90
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
91
|
-
console.warn(
|
|
92
|
-
'React attempted to use reuse markup in a container but the ' +
|
|
93
|
-
'checksum was invalid. This generally means that you are ' +
|
|
94
|
-
'using server rendering and the markup generated on the ' +
|
|
95
|
-
'server was not what the client was expecting. React injected ' +
|
|
96
|
-
'new markup to compensate which works but you have lost many ' +
|
|
97
|
-
'of the benefits of server rendering. Instead, figure out ' +
|
|
98
|
-
'why the markup being generated is different on the client ' +
|
|
99
|
-
'or server.'
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
106
|
-
container.nodeType !== DOC_NODE_TYPE,
|
|
107
|
-
'You\'re trying to render a component to the document but ' +
|
|
108
|
-
'you didn\'t use server rendering. We can\'t do this ' +
|
|
109
|
-
'without using server rendering due to cross-browser quirks. ' +
|
|
110
|
-
'See renderComponentToString() for server rendering.'
|
|
111
|
-
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
41
|
+
}
|
|
112
42
|
|
|
113
|
-
setInnerHTML(container, markup);
|
|
114
|
-
}
|
|
115
|
-
)
|
|
116
43
|
};
|
|
117
44
|
|
|
118
45
|
module.exports = ReactComponentBrowserEnvironment;
|