react 0.12.0 → 0.13.0-alpha.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 +2345 -910
- package/dist/react-with-addons.js +5273 -4111
- package/dist/react-with-addons.min.js +5 -6
- package/dist/react.js +4840 -3940
- package/dist/react.min.js +5 -6
- package/lib/AutoFocusMixin.js +1 -1
- package/lib/BeforeInputEventPlugin.js +389 -112
- package/lib/CSSProperty.js +6 -3
- package/lib/CSSPropertyOperations.js +21 -1
- package/lib/CallbackQueue.js +2 -2
- package/lib/ChangeEventPlugin.js +3 -3
- package/lib/ClientReactRootIndex.js +1 -1
- package/lib/DOMChildrenOperations.js +6 -4
- package/lib/DOMProperty.js +1 -1
- package/lib/DOMPropertyOperations.js +1 -1
- package/lib/Danger.js +7 -6
- package/lib/DefaultEventPluginOrder.js +1 -2
- package/lib/EnterLeaveEventPlugin.js +1 -1
- package/lib/EventConstants.js +1 -1
- package/lib/EventPluginHub.js +9 -7
- package/lib/EventPluginRegistry.js +1 -1
- package/lib/EventPluginUtils.js +1 -1
- package/lib/EventPropagators.js +1 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +89 -0
- package/lib/HTMLDOMPropertyConfig.js +19 -7
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +3 -3
- package/lib/LocalEventTrapMixin.js +1 -1
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +3 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +17 -50
- package/lib/ReactBrowserComponentMixin.js +3 -13
- package/lib/ReactBrowserEventEmitter.js +4 -6
- package/lib/ReactCSSTransitionGroup.js +4 -1
- package/lib/ReactCSSTransitionGroupChild.js +12 -2
- package/lib/ReactChildReconciler.js +121 -0
- package/lib/ReactChildren.js +10 -8
- package/lib/ReactClass.js +874 -0
- package/lib/ReactComponent.js +45 -286
- package/lib/ReactComponentBase.js +126 -0
- package/lib/ReactComponentBrowserEnvironment.js +10 -83
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +700 -1045
- package/lib/ReactContext.js +6 -2
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +3 -8
- package/lib/ReactDOMButton.js +5 -6
- package/lib/ReactDOMComponent.js +120 -77
- package/lib/ReactDOMForm.js +5 -6
- package/lib/ReactDOMIDOperations.js +56 -74
- package/lib/ReactDOMImg.js +4 -6
- package/lib/ReactDOMInput.js +5 -6
- package/lib/ReactDOMOption.js +5 -6
- package/lib/ReactDOMSelect.js +57 -65
- package/lib/ReactDOMSelection.js +6 -2
- package/lib/ReactDOMTextComponent.js +124 -0
- package/lib/ReactDOMTextarea.js +5 -6
- package/lib/ReactDefaultBatchingStrategy.js +1 -1
- package/lib/ReactDefaultInjection.js +14 -8
- package/lib/ReactDefaultPerf.js +8 -7
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +22 -15
- package/lib/ReactElementValidator.js +192 -53
- package/lib/ReactEmptyComponent.js +29 -11
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +3 -3
- package/lib/ReactInjection.js +7 -5
- package/lib/ReactInputSelection.js +3 -4
- package/lib/ReactInstanceHandles.js +3 -2
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +202 -66
- package/lib/ReactMultiChild.js +44 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +47 -10
- package/lib/ReactOwner.js +4 -48
- package/lib/ReactPerf.js +21 -1
- package/lib/ReactPropTransferer.js +2 -57
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +14 -22
- package/lib/ReactPutListenerQueue.js +1 -1
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactRef.js +96 -0
- package/lib/ReactRootIndex.js +1 -1
- package/lib/ReactServerRendering.js +5 -3
- package/lib/ReactServerRenderingTransaction.js +1 -1
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +83 -26
- package/lib/ReactTransitionChildMapping.js +1 -1
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +48 -7
- package/lib/ReactUpdates.js +46 -45
- package/lib/ReactWithAddons.js +1 -1
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +3 -3
- package/lib/ServerReactRootIndex.js +1 -1
- package/lib/SimpleEventPlugin.js +1 -1
- package/lib/SyntheticClipboardEvent.js +1 -2
- package/lib/SyntheticCompositionEvent.js +1 -2
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +11 -3
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +1 -2
- package/lib/SyntheticKeyboardEvent.js +1 -1
- package/lib/SyntheticMouseEvent.js +2 -4
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/Transaction.js +3 -3
- package/lib/ViewportMetrics.js +2 -5
- package/lib/accumulate.js +47 -0
- package/lib/accumulateInto.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/cloneWithProps.js +3 -3
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +3 -3
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/escapeTextForBrowser.js +6 -6
- package/lib/findDOMNode.js +51 -0
- package/lib/flattenChildren.js +11 -22
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +42 -0
- package/lib/getNodeForCharacterOffset.js +2 -2
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/instantiateReactComponent.js +89 -66
- package/lib/isEventSupported.js +1 -1
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +2 -3
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/memoizeStringOnly.js +4 -5
- package/lib/onlyChild.js +1 -1
- package/lib/setInnerHTML.js +12 -1
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +48 -6
- package/lib/traverseAllChildren.js +111 -55
- package/lib/update.js +1 -1
- package/lib/warning.js +9 -2
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/ReactTextComponent.js +0 -104
- package/lib/deprecated.js +0 -47
|
@@ -9,9 +9,10 @@
|
|
|
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
|
|
|
@@ -26,17 +27,36 @@ 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.
|
|
@@ -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 nullComponentIdsRegistry[id];
|
|
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;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @typechecks static-only
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var EventListener = require("./EventListener");
|
|
16
16
|
var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
@@ -123,7 +123,7 @@ var ReactEventListener = {
|
|
|
123
123
|
trapBubbledEvent: function(topLevelType, handlerBaseName, handle) {
|
|
124
124
|
var element = handle;
|
|
125
125
|
if (!element) {
|
|
126
|
-
return;
|
|
126
|
+
return null;
|
|
127
127
|
}
|
|
128
128
|
return EventListener.listen(
|
|
129
129
|
element,
|
|
@@ -145,7 +145,7 @@ var ReactEventListener = {
|
|
|
145
145
|
trapCapturedEvent: function(topLevelType, handlerBaseName, handle) {
|
|
146
146
|
var element = handle;
|
|
147
147
|
if (!element) {
|
|
148
|
-
return;
|
|
148
|
+
return null;
|
|
149
149
|
}
|
|
150
150
|
return EventListener.capture(
|
|
151
151
|
element,
|
package/lib/ReactInjection.js
CHANGED
|
@@ -9,22 +9,24 @@
|
|
|
9
9
|
* @providesModule ReactInjection
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var DOMProperty = require("./DOMProperty");
|
|
15
15
|
var EventPluginHub = require("./EventPluginHub");
|
|
16
|
-
var
|
|
17
|
-
var
|
|
16
|
+
var ReactComponentEnvironment = require("./ReactComponentEnvironment");
|
|
17
|
+
var ReactClass = require("./ReactClass");
|
|
18
18
|
var ReactEmptyComponent = require("./ReactEmptyComponent");
|
|
19
19
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
20
20
|
var ReactNativeComponent = require("./ReactNativeComponent");
|
|
21
|
+
var ReactDOMComponent = require("./ReactDOMComponent");
|
|
21
22
|
var ReactPerf = require("./ReactPerf");
|
|
22
23
|
var ReactRootIndex = require("./ReactRootIndex");
|
|
23
24
|
var ReactUpdates = require("./ReactUpdates");
|
|
24
25
|
|
|
25
26
|
var ReactInjection = {
|
|
26
|
-
Component:
|
|
27
|
-
|
|
27
|
+
Component: ReactComponentEnvironment.injection,
|
|
28
|
+
Class: ReactClass.injection,
|
|
29
|
+
DOMComponent: ReactDOMComponent.injection,
|
|
28
30
|
DOMProperty: DOMProperty.injection,
|
|
29
31
|
EmptyComponent: ReactEmptyComponent.injection,
|
|
30
32
|
EventPluginHub: EventPluginHub.injection,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactInputSelection
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactDOMSelection = require("./ReactDOMSelection");
|
|
15
15
|
|
|
@@ -31,9 +31,8 @@ var ReactInputSelection = {
|
|
|
31
31
|
|
|
32
32
|
hasSelectionCapabilities: function(elem) {
|
|
33
33
|
return elem && (
|
|
34
|
-
(elem.nodeName === 'INPUT' && elem.type === 'text') ||
|
|
35
|
-
elem.nodeName === 'TEXTAREA' ||
|
|
36
|
-
elem.contentEditable === 'true'
|
|
34
|
+
((elem.nodeName === 'INPUT' && elem.type === 'text') ||
|
|
35
|
+
elem.nodeName === 'TEXTAREA' || elem.contentEditable === 'true')
|
|
37
36
|
);
|
|
38
37
|
},
|
|
39
38
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @typechecks static-only
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var ReactRootIndex = require("./ReactRootIndex");
|
|
16
16
|
|
|
@@ -115,7 +115,8 @@ function getNextDescendantID(ancestorID, destinationID) {
|
|
|
115
115
|
// Skip over the ancestor and the immediate separator. Traverse until we hit
|
|
116
116
|
// another separator or we reach the end of `destinationID`.
|
|
117
117
|
var start = ancestorID.length + SEPARATOR_LENGTH;
|
|
118
|
-
|
|
118
|
+
var i;
|
|
119
|
+
for (i = start; i < destinationID.length; i++) {
|
|
119
120
|
if (isBoundary(destinationID, i)) {
|
|
120
121
|
break;
|
|
121
122
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-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 ReactInstanceMap
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
16
|
+
* instance (key) and the internal representation (value). This allows public
|
|
17
|
+
* methods to accept the user facing instance as an argument and map them back
|
|
18
|
+
* to internal methods.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// TODO: Replace this with ES6: var ReactInstanceMap = new Map();
|
|
22
|
+
var ReactInstanceMap = {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This API should be called `delete` but we'd have to make sure to always
|
|
26
|
+
* transform these to strings for IE support. When this transform is fully
|
|
27
|
+
* supported we can rename it.
|
|
28
|
+
*/
|
|
29
|
+
remove: function(key) {
|
|
30
|
+
key._reactInternalInstance = undefined;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
get: function(key) {
|
|
34
|
+
return key._reactInternalInstance;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
has: function(key) {
|
|
38
|
+
return key._reactInternalInstance !== undefined;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
set: function(key, value) {
|
|
42
|
+
key._reactInternalInstance = value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = ReactInstanceMap;
|
package/lib/ReactLink.js
CHANGED
package/lib/ReactMount.js
CHANGED
|
@@ -9,28 +9,29 @@
|
|
|
9
9
|
* @providesModule ReactMount
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var DOMProperty = require("./DOMProperty");
|
|
15
15
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
16
16
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
17
17
|
var ReactElement = require("./ReactElement");
|
|
18
|
-
var
|
|
18
|
+
var ReactElementValidator = require("./ReactElementValidator");
|
|
19
|
+
var ReactEmptyComponent = require("./ReactEmptyComponent");
|
|
19
20
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
21
|
+
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
22
|
+
var ReactMarkupChecksum = require("./ReactMarkupChecksum");
|
|
20
23
|
var ReactPerf = require("./ReactPerf");
|
|
24
|
+
var ReactUpdates = require("./ReactUpdates");
|
|
21
25
|
|
|
26
|
+
var emptyObject = require("./emptyObject");
|
|
22
27
|
var containsNode = require("./containsNode");
|
|
23
|
-
var deprecated = require("./deprecated");
|
|
24
28
|
var getReactRootElementInContainer = require("./getReactRootElementInContainer");
|
|
25
29
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
26
30
|
var invariant = require("./invariant");
|
|
31
|
+
var setInnerHTML = require("./setInnerHTML");
|
|
27
32
|
var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
|
|
28
33
|
var warning = require("./warning");
|
|
29
34
|
|
|
30
|
-
var createElement = ReactLegacyElement.wrapCreateElement(
|
|
31
|
-
ReactElement.createElement
|
|
32
|
-
);
|
|
33
|
-
|
|
34
35
|
var SEPARATOR = ReactInstanceHandles.SEPARATOR;
|
|
35
36
|
|
|
36
37
|
var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
|
|
@@ -53,6 +54,22 @@ if ("production" !== process.env.NODE_ENV) {
|
|
|
53
54
|
// Used to store breadth-first search state in findComponentRoot.
|
|
54
55
|
var findComponentRootReusableArray = [];
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Finds the index of the first character
|
|
59
|
+
* that's not common between the two given strings.
|
|
60
|
+
*
|
|
61
|
+
* @return {number} the index of the character where the strings diverge
|
|
62
|
+
*/
|
|
63
|
+
function firstDifferenceIndex(string1, string2) {
|
|
64
|
+
var minLen = Math.min(string1.length, string2.length);
|
|
65
|
+
for (var i = 0; i < minLen; i++) {
|
|
66
|
+
if (string1.charAt(i) !== string2.charAt(i)) {
|
|
67
|
+
return i;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return string1.length === string2.length ? -1 : minLen;
|
|
71
|
+
}
|
|
72
|
+
|
|
56
73
|
/**
|
|
57
74
|
* @param {DOMElement} container DOM element that may contain a React component.
|
|
58
75
|
* @return {?string} A "reactRoot" ID, if a React component is rendered.
|
|
@@ -130,6 +147,24 @@ function getNode(id) {
|
|
|
130
147
|
return nodeCache[id];
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Finds the node with the supplied public React instance.
|
|
152
|
+
*
|
|
153
|
+
* @param {*} instance A public React instance.
|
|
154
|
+
* @return {?DOMElement} DOM node with the suppled `id`.
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
function getNodeFromInstance(instance) {
|
|
158
|
+
var id = ReactInstanceMap.get(instance)._rootNodeID;
|
|
159
|
+
if (ReactEmptyComponent.isNullComponentID(id)) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
if (!nodeCache.hasOwnProperty(id) || !isValid(nodeCache[id], id)) {
|
|
163
|
+
nodeCache[id] = ReactMount.findReactNodeByID(id);
|
|
164
|
+
}
|
|
165
|
+
return nodeCache[id];
|
|
166
|
+
}
|
|
167
|
+
|
|
133
168
|
/**
|
|
134
169
|
* A node is "valid" if it is contained by a currently mounted container.
|
|
135
170
|
*
|
|
@@ -193,6 +228,24 @@ function findDeepestCachedAncestor(targetID) {
|
|
|
193
228
|
return foundNode;
|
|
194
229
|
}
|
|
195
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Mounts this component and inserts it into the DOM.
|
|
233
|
+
*
|
|
234
|
+
* @param {string} rootID DOM ID of the root node.
|
|
235
|
+
* @param {DOMElement} container DOM element to mount into.
|
|
236
|
+
* @param {ReactReconcileTransaction} transaction
|
|
237
|
+
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
238
|
+
*/
|
|
239
|
+
function mountComponentIntoNode(
|
|
240
|
+
rootID,
|
|
241
|
+
container,
|
|
242
|
+
transaction,
|
|
243
|
+
shouldReuseMarkup) {
|
|
244
|
+
var markup = this.mountComponent(rootID, transaction, emptyObject);
|
|
245
|
+
this._isTopLevel = true;
|
|
246
|
+
ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
247
|
+
}
|
|
248
|
+
|
|
196
249
|
/**
|
|
197
250
|
* Mounting is the process of initializing a React component by creatings its
|
|
198
251
|
* representative DOM elements and inserting them into a supplied `container`.
|
|
@@ -230,16 +283,20 @@ var ReactMount = {
|
|
|
230
283
|
/**
|
|
231
284
|
* Take a component that's already mounted into the DOM and replace its props
|
|
232
285
|
* @param {ReactComponent} prevComponent component instance already in the DOM
|
|
233
|
-
* @param {
|
|
286
|
+
* @param {ReactElement} nextElement component instance to render
|
|
234
287
|
* @param {DOMElement} container container to render into
|
|
235
288
|
* @param {?function} callback function triggered on completion
|
|
236
289
|
*/
|
|
237
290
|
_updateRootComponent: function(
|
|
238
291
|
prevComponent,
|
|
239
|
-
|
|
292
|
+
nextElement,
|
|
240
293
|
container,
|
|
241
294
|
callback) {
|
|
242
|
-
|
|
295
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
296
|
+
ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
var nextProps = nextElement.props;
|
|
243
300
|
ReactMount.scrollMonitor(container, function() {
|
|
244
301
|
prevComponent.replaceProps(nextProps, callback);
|
|
245
302
|
});
|
|
@@ -263,13 +320,11 @@ var ReactMount = {
|
|
|
263
320
|
_registerComponent: function(nextComponent, container) {
|
|
264
321
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
265
322
|
container && (
|
|
266
|
-
container.nodeType === ELEMENT_NODE_TYPE ||
|
|
267
|
-
container.nodeType === DOC_NODE_TYPE
|
|
323
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
268
324
|
),
|
|
269
325
|
'_registerComponent(...): Target container is not a DOM element.'
|
|
270
326
|
) : invariant(container && (
|
|
271
|
-
container.nodeType === ELEMENT_NODE_TYPE ||
|
|
272
|
-
container.nodeType === DOC_NODE_TYPE
|
|
327
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
273
328
|
)));
|
|
274
329
|
|
|
275
330
|
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
|
|
@@ -286,44 +341,47 @@ var ReactMount = {
|
|
|
286
341
|
* @param {boolean} shouldReuseMarkup if we should skip the markup insertion
|
|
287
342
|
* @return {ReactComponent} nextComponent
|
|
288
343
|
*/
|
|
289
|
-
_renderNewRootComponent:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
'componentDidUpdate.'
|
|
305
|
-
) : null);
|
|
306
|
-
|
|
307
|
-
var componentInstance = instantiateReactComponent(nextComponent, null);
|
|
308
|
-
var reactRootID = ReactMount._registerComponent(
|
|
309
|
-
componentInstance,
|
|
310
|
-
container
|
|
311
|
-
);
|
|
312
|
-
componentInstance.mountComponentIntoNode(
|
|
313
|
-
reactRootID,
|
|
314
|
-
container,
|
|
315
|
-
shouldReuseMarkup
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
319
|
-
// Record the root element in case it later gets transplanted.
|
|
320
|
-
rootElementsByReactRootID[reactRootID] =
|
|
321
|
-
getReactRootElementInContainer(container);
|
|
322
|
-
}
|
|
344
|
+
_renderNewRootComponent: function(
|
|
345
|
+
nextComponent,
|
|
346
|
+
container,
|
|
347
|
+
shouldReuseMarkup
|
|
348
|
+
) {
|
|
349
|
+
// Various parts of our code (such as ReactCompositeComponent's
|
|
350
|
+
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
351
|
+
// verify that that's the case.
|
|
352
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
353
|
+
ReactCurrentOwner.current == null,
|
|
354
|
+
'_renderNewRootComponent(): Render methods should be a pure function ' +
|
|
355
|
+
'of props and state; triggering nested component updates from ' +
|
|
356
|
+
'render is not allowed. If necessary, trigger nested updates in ' +
|
|
357
|
+
'componentDidUpdate.'
|
|
358
|
+
) : null);
|
|
323
359
|
|
|
324
|
-
|
|
360
|
+
var componentInstance = instantiateReactComponent(nextComponent, null);
|
|
361
|
+
var reactRootID = ReactMount._registerComponent(
|
|
362
|
+
componentInstance,
|
|
363
|
+
container
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
367
|
+
transaction.perform(
|
|
368
|
+
mountComponentIntoNode,
|
|
369
|
+
componentInstance,
|
|
370
|
+
reactRootID,
|
|
371
|
+
container,
|
|
372
|
+
transaction,
|
|
373
|
+
shouldReuseMarkup
|
|
374
|
+
);
|
|
375
|
+
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
376
|
+
|
|
377
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
378
|
+
// Record the root element in case it later gets transplanted.
|
|
379
|
+
rootElementsByReactRootID[reactRootID] =
|
|
380
|
+
getReactRootElementInContainer(container);
|
|
325
381
|
}
|
|
326
|
-
|
|
382
|
+
|
|
383
|
+
return componentInstance;
|
|
384
|
+
},
|
|
327
385
|
|
|
328
386
|
/**
|
|
329
387
|
* Renders a React component into the DOM in the supplied `container`.
|
|
@@ -340,16 +398,16 @@ var ReactMount = {
|
|
|
340
398
|
render: function(nextElement, container, callback) {
|
|
341
399
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
342
400
|
ReactElement.isValidElement(nextElement),
|
|
343
|
-
'
|
|
401
|
+
'React.render(): Invalid component element.%s',
|
|
344
402
|
(
|
|
345
403
|
typeof nextElement === 'string' ?
|
|
346
404
|
' Instead of passing an element string, make sure to instantiate ' +
|
|
347
405
|
'it by passing it to React.createElement.' :
|
|
348
|
-
|
|
406
|
+
typeof nextElement === 'function' ?
|
|
349
407
|
' Instead of passing a component class, make sure to instantiate ' +
|
|
350
408
|
'it by passing it to React.createElement.' :
|
|
351
|
-
// Check if it quacks like
|
|
352
|
-
|
|
409
|
+
// Check if it quacks like an element
|
|
410
|
+
nextElement != null && nextElement.props !== undefined ?
|
|
353
411
|
' This may be caused by unintentionally loading two independent ' +
|
|
354
412
|
'copies of React.' :
|
|
355
413
|
''
|
|
@@ -366,7 +424,7 @@ var ReactMount = {
|
|
|
366
424
|
nextElement,
|
|
367
425
|
container,
|
|
368
426
|
callback
|
|
369
|
-
);
|
|
427
|
+
).getPublicInstance();
|
|
370
428
|
} else {
|
|
371
429
|
ReactMount.unmountComponentAtNode(container);
|
|
372
430
|
}
|
|
@@ -382,8 +440,10 @@ var ReactMount = {
|
|
|
382
440
|
nextElement,
|
|
383
441
|
container,
|
|
384
442
|
shouldReuseMarkup
|
|
385
|
-
);
|
|
386
|
-
|
|
443
|
+
).getPublicInstance();
|
|
444
|
+
if (callback) {
|
|
445
|
+
callback.call(component);
|
|
446
|
+
}
|
|
387
447
|
return component;
|
|
388
448
|
},
|
|
389
449
|
|
|
@@ -397,7 +457,7 @@ var ReactMount = {
|
|
|
397
457
|
* @return {ReactComponent} Component instance rendered in `container`.
|
|
398
458
|
*/
|
|
399
459
|
constructAndRenderComponent: function(constructor, props, container) {
|
|
400
|
-
var element = createElement(constructor, props);
|
|
460
|
+
var element = ReactElement.createElement(constructor, props);
|
|
401
461
|
return ReactMount.render(element, container);
|
|
402
462
|
},
|
|
403
463
|
|
|
@@ -462,6 +522,15 @@ var ReactMount = {
|
|
|
462
522
|
'componentDidUpdate.'
|
|
463
523
|
) : null);
|
|
464
524
|
|
|
525
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
526
|
+
container && (
|
|
527
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
528
|
+
),
|
|
529
|
+
'unmountComponentAtNode(...): Target container is not a DOM element.'
|
|
530
|
+
) : invariant(container && (
|
|
531
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
532
|
+
)));
|
|
533
|
+
|
|
465
534
|
var reactRootID = getReactRootID(container);
|
|
466
535
|
var component = instancesByReactRootID[reactRootID];
|
|
467
536
|
if (!component) {
|
|
@@ -666,6 +735,75 @@ var ReactMount = {
|
|
|
666
735
|
) : invariant(false));
|
|
667
736
|
},
|
|
668
737
|
|
|
738
|
+
_mountImageIntoNode: function(markup, container, shouldReuseMarkup) {
|
|
739
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
740
|
+
container && (
|
|
741
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
742
|
+
),
|
|
743
|
+
'mountComponentIntoNode(...): Target container is not valid.'
|
|
744
|
+
) : invariant(container && (
|
|
745
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
746
|
+
)));
|
|
747
|
+
|
|
748
|
+
if (shouldReuseMarkup) {
|
|
749
|
+
var rootElement = getReactRootElementInContainer(container);
|
|
750
|
+
if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
|
|
751
|
+
return;
|
|
752
|
+
} else {
|
|
753
|
+
var checksum = rootElement.getAttribute(
|
|
754
|
+
ReactMarkupChecksum.CHECKSUM_ATTR_NAME
|
|
755
|
+
);
|
|
756
|
+
rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
757
|
+
|
|
758
|
+
var rootMarkup = rootElement.outerHTML;
|
|
759
|
+
rootElement.setAttribute(
|
|
760
|
+
ReactMarkupChecksum.CHECKSUM_ATTR_NAME,
|
|
761
|
+
checksum
|
|
762
|
+
);
|
|
763
|
+
|
|
764
|
+
var diffIndex = firstDifferenceIndex(markup, rootMarkup);
|
|
765
|
+
var difference = ' (client) ' +
|
|
766
|
+
markup.substring(diffIndex - 20, diffIndex + 20) +
|
|
767
|
+
'\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
|
|
768
|
+
|
|
769
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
770
|
+
container.nodeType !== DOC_NODE_TYPE,
|
|
771
|
+
'You\'re trying to render a component to the document using ' +
|
|
772
|
+
'server rendering but the checksum was invalid. This usually ' +
|
|
773
|
+
'means you rendered a different component type or props on ' +
|
|
774
|
+
'the client from the one on the server, or your render() ' +
|
|
775
|
+
'methods are impure. React cannot handle this case due to ' +
|
|
776
|
+
'cross-browser quirks by rendering at the document root. You ' +
|
|
777
|
+
'should look for environment dependent code in your components ' +
|
|
778
|
+
'and ensure the props are the same client and server side:\n%s',
|
|
779
|
+
difference
|
|
780
|
+
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
781
|
+
|
|
782
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
783
|
+
console.warn(
|
|
784
|
+
'React attempted to reuse markup in a container but the ' +
|
|
785
|
+
'checksum was invalid. This generally means that you are ' +
|
|
786
|
+
'using server rendering and the markup generated on the ' +
|
|
787
|
+
'server was not what the client was expecting. React injected ' +
|
|
788
|
+
'new markup to compensate which works but you have lost many ' +
|
|
789
|
+
'of the benefits of server rendering. Instead, figure out ' +
|
|
790
|
+
'why the markup being generated is different on the client ' +
|
|
791
|
+
'or server:\n' + difference
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
798
|
+
container.nodeType !== DOC_NODE_TYPE,
|
|
799
|
+
'You\'re trying to render a component to the document but ' +
|
|
800
|
+
'you didn\'t use server rendering. We can\'t do this ' +
|
|
801
|
+
'without using server rendering due to cross-browser quirks. ' +
|
|
802
|
+
'See React.renderToString() for server rendering.'
|
|
803
|
+
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
804
|
+
|
|
805
|
+
setInnerHTML(container, markup);
|
|
806
|
+
},
|
|
669
807
|
|
|
670
808
|
/**
|
|
671
809
|
* React ID utilities.
|
|
@@ -679,16 +817,14 @@ var ReactMount = {
|
|
|
679
817
|
|
|
680
818
|
getNode: getNode,
|
|
681
819
|
|
|
820
|
+
getNodeFromInstance: getNodeFromInstance,
|
|
821
|
+
|
|
682
822
|
purgeID: purgeID
|
|
683
823
|
};
|
|
684
824
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
'
|
|
688
|
-
|
|
689
|
-
'render',
|
|
690
|
-
this,
|
|
691
|
-
ReactMount.render
|
|
692
|
-
);
|
|
825
|
+
ReactPerf.measureMethods(ReactMount, 'ReactMount', {
|
|
826
|
+
_renderNewRootComponent: '_renderNewRootComponent',
|
|
827
|
+
_mountImageIntoNode: '_mountImageIntoNode'
|
|
828
|
+
});
|
|
693
829
|
|
|
694
830
|
module.exports = ReactMount;
|