react 0.12.2 → 0.13.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/JSXTransformer.js +986 -511
- package/dist/react-with-addons.js +6076 -4560
- package/dist/react-with-addons.min.js +6 -7
- package/dist/react.js +5386 -4170
- package/dist/react.min.js +6 -7
- package/lib/AutoFocusMixin.js +2 -2
- package/lib/BeforeInputEventPlugin.js +388 -115
- package/lib/CSSCore.js +1 -1
- package/lib/CSSProperty.js +2 -2
- package/lib/CSSPropertyOperations.js +58 -11
- package/lib/CallbackQueue.js +3 -3
- package/lib/ChangeEventPlugin.js +4 -4
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +10 -47
- package/lib/DOMProperty.js +2 -2
- package/lib/DOMPropertyOperations.js +11 -16
- package/lib/Danger.js +8 -7
- package/lib/DefaultEventPluginOrder.js +3 -4
- package/lib/EnterLeaveEventPlugin.js +2 -2
- package/lib/EventConstants.js +2 -2
- package/lib/EventListener.js +1 -1
- package/lib/EventPluginHub.js +10 -8
- package/lib/EventPluginRegistry.js +2 -2
- package/lib/EventPluginUtils.js +4 -4
- package/lib/EventPropagators.js +2 -2
- package/lib/ExecutionEnvironment.js +3 -4
- package/lib/FallbackCompositionState.js +89 -0
- package/lib/HTMLDOMPropertyConfig.js +23 -10
- package/lib/LinkedStateMixin.js +2 -2
- package/lib/LinkedValueUtils.js +4 -4
- package/lib/LocalEventTrapMixin.js +10 -3
- package/lib/MobileSafariClickEventPlugin.js +2 -2
- package/lib/Object.assign.js +4 -2
- package/lib/PooledClass.js +2 -2
- package/lib/React.js +19 -58
- package/lib/ReactBrowserComponentMixin.js +4 -14
- package/lib/ReactBrowserEventEmitter.js +6 -8
- package/lib/ReactCSSTransitionGroup.js +5 -2
- package/lib/ReactCSSTransitionGroupChild.js +20 -7
- package/lib/ReactChildReconciler.js +125 -0
- package/lib/ReactChildren.js +13 -10
- package/lib/ReactClass.js +918 -0
- package/lib/ReactComponent.js +98 -406
- package/lib/ReactComponentBrowserEnvironment.js +11 -84
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +2 -2
- package/lib/ReactCompositeComponent.js +574 -1140
- package/lib/ReactContext.js +17 -3
- package/lib/ReactCurrentOwner.js +2 -2
- package/lib/ReactDOM.js +4 -9
- package/lib/ReactDOMButton.js +6 -7
- package/lib/ReactDOMComponent.js +123 -105
- package/lib/ReactDOMForm.js +6 -7
- package/lib/ReactDOMIDOperations.js +59 -77
- package/lib/ReactDOMIframe.js +43 -0
- package/lib/ReactDOMImg.js +5 -7
- package/lib/ReactDOMInput.js +6 -7
- package/lib/ReactDOMOption.js +6 -7
- package/lib/ReactDOMSelect.js +58 -66
- package/lib/ReactDOMSelection.js +7 -3
- package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -37
- package/lib/ReactDOMTextarea.js +6 -7
- package/lib/ReactDefaultBatchingStrategy.js +5 -5
- package/lib/ReactDefaultInjection.js +39 -9
- package/lib/ReactDefaultPerf.js +17 -8
- package/lib/ReactDefaultPerfAnalysis.js +2 -2
- package/lib/ReactElement.js +23 -15
- package/lib/ReactElementValidator.js +206 -89
- package/lib/ReactEmptyComponent.js +33 -15
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +2 -2
- package/lib/ReactEventListener.js +4 -5
- package/lib/ReactFragment.js +172 -0
- package/lib/ReactInjection.js +8 -6
- package/lib/ReactInputSelection.js +4 -5
- package/lib/ReactInstanceHandles.js +4 -3
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +2 -2
- package/lib/ReactMarkupChecksum.js +2 -2
- package/lib/ReactMount.js +264 -71
- package/lib/ReactMultiChild.js +50 -48
- package/lib/ReactMultiChildUpdateTypes.js +2 -2
- package/lib/ReactNativeComponent.js +59 -25
- package/lib/ReactOwner.js +5 -49
- package/lib/ReactPerf.js +22 -2
- package/lib/ReactPropTransferer.js +3 -58
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +2 -2
- package/lib/ReactPropTypes.js +17 -25
- package/lib/ReactPutListenerQueue.js +2 -2
- package/lib/ReactReconcileTransaction.js +2 -2
- package/lib/ReactReconciler.js +121 -0
- package/lib/ReactRef.js +69 -0
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +6 -4
- package/lib/ReactServerRenderingTransaction.js +2 -2
- package/lib/ReactStateSetters.js +2 -2
- package/lib/ReactTestUtils.js +113 -27
- package/lib/ReactTransitionChildMapping.js +8 -4
- package/lib/ReactTransitionEvents.js +2 -2
- package/lib/ReactTransitionGroup.js +53 -12
- package/lib/ReactUpdateQueue.js +295 -0
- package/lib/ReactUpdates.js +54 -62
- package/lib/ReactWithAddons.js +4 -2
- package/lib/SVGDOMPropertyConfig.js +2 -2
- package/lib/SelectEventPlugin.js +4 -4
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +4 -4
- package/lib/SyntheticClipboardEvent.js +2 -3
- package/lib/SyntheticCompositionEvent.js +2 -3
- package/lib/SyntheticDragEvent.js +2 -2
- package/lib/SyntheticEvent.js +12 -4
- package/lib/SyntheticFocusEvent.js +2 -2
- package/lib/SyntheticInputEvent.js +2 -3
- package/lib/SyntheticKeyboardEvent.js +2 -2
- package/lib/SyntheticMouseEvent.js +3 -5
- package/lib/SyntheticTouchEvent.js +2 -2
- package/lib/SyntheticUIEvent.js +2 -2
- package/lib/SyntheticWheelEvent.js +2 -2
- package/lib/Transaction.js +4 -4
- package/lib/ViewportMetrics.js +3 -6
- package/lib/accumulateInto.js +2 -2
- package/lib/adler32.js +2 -2
- package/lib/camelize.js +1 -1
- package/lib/camelizeStyleName.js +1 -1
- package/lib/cloneWithProps.js +4 -4
- package/lib/containsNode.js +1 -1
- package/lib/{createArrayFrom.js → createArrayFromMixed.js} +6 -6
- package/lib/createFullPageComponent.js +4 -4
- package/lib/createNodesFromMarkup.js +4 -4
- package/lib/cx.js +1 -1
- package/lib/dangerousStyleValue.js +2 -2
- package/lib/emptyFunction.js +1 -1
- package/lib/emptyObject.js +1 -1
- package/lib/{escapeTextForBrowser.js → escapeTextContentForBrowser.js} +10 -11
- package/lib/findDOMNode.js +51 -0
- package/lib/flattenChildren.js +12 -23
- package/lib/focusNode.js +1 -1
- package/lib/forEachAccumulated.js +2 -2
- package/lib/getActiveElement.js +1 -1
- package/lib/getEventCharCode.js +2 -2
- package/lib/getEventKey.js +2 -2
- package/lib/getEventModifierState.js +2 -2
- package/lib/getEventTarget.js +2 -2
- package/lib/getIteratorFn.js +42 -0
- package/lib/getMarkupWrap.js +1 -1
- package/lib/getNodeForCharacterOffset.js +3 -3
- package/lib/getReactRootElementInContainer.js +2 -2
- package/lib/getTextContentAccessor.js +2 -2
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +1 -1
- package/lib/hyphenateStyleName.js +1 -1
- package/lib/instantiateReactComponent.js +90 -68
- package/lib/invariant.js +1 -1
- package/lib/isEventSupported.js +2 -2
- package/lib/isNode.js +4 -5
- package/lib/isTextInputElement.js +3 -4
- package/lib/isTextNode.js +1 -1
- package/lib/joinClasses.js +2 -2
- package/lib/keyMirror.js +2 -2
- package/lib/keyOf.js +1 -1
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +5 -6
- package/lib/onlyChild.js +2 -2
- package/lib/performance.js +1 -1
- package/lib/performanceNow.js +1 -1
- package/lib/quoteAttributeValueForBrowser.js +26 -0
- package/lib/setInnerHTML.js +13 -2
- package/lib/setTextContent.js +40 -0
- package/lib/shallowEqual.js +2 -2
- package/lib/shouldUpdateReactComponent.js +71 -7
- package/lib/toArray.js +2 -2
- package/lib/traverseAllChildren.js +114 -56
- package/lib/update.js +2 -2
- package/lib/warning.js +20 -2
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/copyProperties.js +0 -54
- package/lib/deprecated.js +0 -47
- package/lib/merge.js +0 -34
- package/lib/mergeInto.js +0 -24
- package/lib/monitorCodeUse.js +0 -30
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -9,15 +9,11 @@
|
|
|
9
9
|
* @providesModule ReactPropTransferer
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var assign = require("./Object.assign");
|
|
15
15
|
var emptyFunction = require("./emptyFunction");
|
|
16
|
-
var invariant = require("./invariant");
|
|
17
16
|
var joinClasses = require("./joinClasses");
|
|
18
|
-
var warning = require("./warning");
|
|
19
|
-
|
|
20
|
-
var didWarn = false;
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* Creates a transfer strategy that will merge prop values using the supplied
|
|
@@ -96,8 +92,6 @@ function transferInto(props, newProps) {
|
|
|
96
92
|
*/
|
|
97
93
|
var ReactPropTransferer = {
|
|
98
94
|
|
|
99
|
-
TransferStrategies: TransferStrategies,
|
|
100
|
-
|
|
101
95
|
/**
|
|
102
96
|
* Merge two props objects using TransferStrategies.
|
|
103
97
|
*
|
|
@@ -107,57 +101,8 @@ var ReactPropTransferer = {
|
|
|
107
101
|
*/
|
|
108
102
|
mergeProps: function(oldProps, newProps) {
|
|
109
103
|
return transferInto(assign({}, oldProps), newProps);
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @lends {ReactPropTransferer.prototype}
|
|
114
|
-
*/
|
|
115
|
-
Mixin: {
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Transfer props from this component to a target component.
|
|
119
|
-
*
|
|
120
|
-
* Props that do not have an explicit transfer strategy will be transferred
|
|
121
|
-
* only if the target component does not already have the prop set.
|
|
122
|
-
*
|
|
123
|
-
* This is usually used to pass down props to a returned root component.
|
|
124
|
-
*
|
|
125
|
-
* @param {ReactElement} element Component receiving the properties.
|
|
126
|
-
* @return {ReactElement} The supplied `component`.
|
|
127
|
-
* @final
|
|
128
|
-
* @protected
|
|
129
|
-
*/
|
|
130
|
-
transferPropsTo: function(element) {
|
|
131
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
132
|
-
element._owner === this,
|
|
133
|
-
'%s: You can\'t call transferPropsTo() on a component that you ' +
|
|
134
|
-
'don\'t own, %s. This usually means you are calling ' +
|
|
135
|
-
'transferPropsTo() on a component passed in as props or children.',
|
|
136
|
-
this.constructor.displayName,
|
|
137
|
-
typeof element.type === 'string' ?
|
|
138
|
-
element.type :
|
|
139
|
-
element.type.displayName
|
|
140
|
-
) : invariant(element._owner === this));
|
|
141
|
-
|
|
142
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
143
|
-
if (!didWarn) {
|
|
144
|
-
didWarn = true;
|
|
145
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
146
|
-
false,
|
|
147
|
-
'transferPropsTo is deprecated. ' +
|
|
148
|
-
'See http://fb.me/react-transferpropsto for more information.'
|
|
149
|
-
) : null);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Because elements are immutable we have to merge into the existing
|
|
154
|
-
// props object rather than clone it.
|
|
155
|
-
transferInto(element.props, this.props);
|
|
156
|
-
|
|
157
|
-
return element;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
104
|
}
|
|
105
|
+
|
|
161
106
|
};
|
|
162
107
|
|
|
163
108
|
module.exports = ReactPropTransferer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactPropTypeLocationNames
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactPropTypeLocationNames = {};
|
|
15
15
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactPropTypeLocations
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var keyMirror = require("./keyMirror");
|
|
15
15
|
|
package/lib/ReactPropTypes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
* @providesModule ReactPropTypes
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
15
|
var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
|
|
16
16
|
|
|
17
|
-
var deprecated = require("./deprecated");
|
|
18
17
|
var emptyFunction = require("./emptyFunction");
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -85,22 +84,7 @@ var ReactPropTypes = {
|
|
|
85
84
|
objectOf: createObjectOfTypeChecker,
|
|
86
85
|
oneOf: createEnumTypeChecker,
|
|
87
86
|
oneOfType: createUnionTypeChecker,
|
|
88
|
-
shape: createShapeTypeChecker
|
|
89
|
-
|
|
90
|
-
component: deprecated(
|
|
91
|
-
'React.PropTypes',
|
|
92
|
-
'component',
|
|
93
|
-
'element',
|
|
94
|
-
this,
|
|
95
|
-
elementTypeChecker
|
|
96
|
-
),
|
|
97
|
-
renderable: deprecated(
|
|
98
|
-
'React.PropTypes',
|
|
99
|
-
'renderable',
|
|
100
|
-
'node',
|
|
101
|
-
this,
|
|
102
|
-
nodeTypeChecker
|
|
103
|
-
)
|
|
87
|
+
shape: createShapeTypeChecker
|
|
104
88
|
};
|
|
105
89
|
|
|
106
90
|
function createChainableTypeChecker(validate) {
|
|
@@ -110,10 +94,11 @@ function createChainableTypeChecker(validate) {
|
|
|
110
94
|
var locationName = ReactPropTypeLocationNames[location];
|
|
111
95
|
if (isRequired) {
|
|
112
96
|
return new Error(
|
|
113
|
-
("Required " + locationName + " `" + propName + "` was not specified in ")+
|
|
97
|
+
("Required " + locationName + " `" + propName + "` was not specified in ") +
|
|
114
98
|
("`" + componentName + "`.")
|
|
115
99
|
);
|
|
116
100
|
}
|
|
101
|
+
return null;
|
|
117
102
|
} else {
|
|
118
103
|
return validate(props, propName, componentName, location);
|
|
119
104
|
}
|
|
@@ -141,12 +126,13 @@ function createPrimitiveTypeChecker(expectedType) {
|
|
|
141
126
|
("supplied to `" + componentName + "`, expected `" + expectedType + "`.")
|
|
142
127
|
);
|
|
143
128
|
}
|
|
129
|
+
return null;
|
|
144
130
|
}
|
|
145
131
|
return createChainableTypeChecker(validate);
|
|
146
132
|
}
|
|
147
133
|
|
|
148
134
|
function createAnyTypeChecker() {
|
|
149
|
-
return createChainableTypeChecker(emptyFunction.thatReturns());
|
|
135
|
+
return createChainableTypeChecker(emptyFunction.thatReturns(null));
|
|
150
136
|
}
|
|
151
137
|
|
|
152
138
|
function createArrayOfTypeChecker(typeChecker) {
|
|
@@ -166,6 +152,7 @@ function createArrayOfTypeChecker(typeChecker) {
|
|
|
166
152
|
return error;
|
|
167
153
|
}
|
|
168
154
|
}
|
|
155
|
+
return null;
|
|
169
156
|
}
|
|
170
157
|
return createChainableTypeChecker(validate);
|
|
171
158
|
}
|
|
@@ -179,6 +166,7 @@ function createElementTypeChecker() {
|
|
|
179
166
|
("`" + componentName + "`, expected a ReactElement.")
|
|
180
167
|
);
|
|
181
168
|
}
|
|
169
|
+
return null;
|
|
182
170
|
}
|
|
183
171
|
return createChainableTypeChecker(validate);
|
|
184
172
|
}
|
|
@@ -193,6 +181,7 @@ function createInstanceTypeChecker(expectedClass) {
|
|
|
193
181
|
("`" + componentName + "`, expected instance of `" + expectedClassName + "`.")
|
|
194
182
|
);
|
|
195
183
|
}
|
|
184
|
+
return null;
|
|
196
185
|
}
|
|
197
186
|
return createChainableTypeChecker(validate);
|
|
198
187
|
}
|
|
@@ -202,7 +191,7 @@ function createEnumTypeChecker(expectedValues) {
|
|
|
202
191
|
var propValue = props[propName];
|
|
203
192
|
for (var i = 0; i < expectedValues.length; i++) {
|
|
204
193
|
if (propValue === expectedValues[i]) {
|
|
205
|
-
return;
|
|
194
|
+
return null;
|
|
206
195
|
}
|
|
207
196
|
}
|
|
208
197
|
|
|
@@ -235,6 +224,7 @@ function createObjectOfTypeChecker(typeChecker) {
|
|
|
235
224
|
}
|
|
236
225
|
}
|
|
237
226
|
}
|
|
227
|
+
return null;
|
|
238
228
|
}
|
|
239
229
|
return createChainableTypeChecker(validate);
|
|
240
230
|
}
|
|
@@ -244,7 +234,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
|
244
234
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
245
235
|
var checker = arrayOfTypeCheckers[i];
|
|
246
236
|
if (checker(props, propName, componentName, location) == null) {
|
|
247
|
-
return;
|
|
237
|
+
return null;
|
|
248
238
|
}
|
|
249
239
|
}
|
|
250
240
|
|
|
@@ -266,6 +256,7 @@ function createNodeChecker() {
|
|
|
266
256
|
("`" + componentName + "`, expected a ReactNode.")
|
|
267
257
|
);
|
|
268
258
|
}
|
|
259
|
+
return null;
|
|
269
260
|
}
|
|
270
261
|
return createChainableTypeChecker(validate);
|
|
271
262
|
}
|
|
@@ -291,12 +282,13 @@ function createShapeTypeChecker(shapeTypes) {
|
|
|
291
282
|
return error;
|
|
292
283
|
}
|
|
293
284
|
}
|
|
285
|
+
return null;
|
|
294
286
|
}
|
|
295
|
-
return createChainableTypeChecker(validate
|
|
287
|
+
return createChainableTypeChecker(validate);
|
|
296
288
|
}
|
|
297
289
|
|
|
298
290
|
function isNode(propValue) {
|
|
299
|
-
switch(typeof propValue) {
|
|
291
|
+
switch (typeof propValue) {
|
|
300
292
|
case 'number':
|
|
301
293
|
case 'string':
|
|
302
294
|
return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactPutListenerQueue
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var PooledClass = require("./PooledClass");
|
|
15
15
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013-
|
|
2
|
+
* Copyright 2013-2015, Facebook, Inc.
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the BSD-style license found in the
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @typechecks static-only
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var CallbackQueue = require("./CallbackQueue");
|
|
16
16
|
var PooledClass = require("./PooledClass");
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-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 ReactReconciler
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactRef = require("./ReactRef");
|
|
15
|
+
var ReactElementValidator = require("./ReactElementValidator");
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Helper to call ReactRef.attachRefs with this composite component, split out
|
|
19
|
+
* to avoid allocations in the transaction mount-ready queue.
|
|
20
|
+
*/
|
|
21
|
+
function attachRefs() {
|
|
22
|
+
ReactRef.attachRefs(this, this._currentElement);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var ReactReconciler = {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initializes the component, renders markup, and registers event listeners.
|
|
29
|
+
*
|
|
30
|
+
* @param {ReactComponent} internalInstance
|
|
31
|
+
* @param {string} rootID DOM ID of the root node.
|
|
32
|
+
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
|
33
|
+
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
34
|
+
* @final
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
mountComponent: function(internalInstance, rootID, transaction, context) {
|
|
38
|
+
var markup = internalInstance.mountComponent(rootID, transaction, context);
|
|
39
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
40
|
+
ReactElementValidator.checkAndWarnForMutatedProps(
|
|
41
|
+
internalInstance._currentElement
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
|
45
|
+
return markup;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Releases any resources allocated by `mountComponent`.
|
|
50
|
+
*
|
|
51
|
+
* @final
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
unmountComponent: function(internalInstance) {
|
|
55
|
+
ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
|
|
56
|
+
internalInstance.unmountComponent();
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Update a component using a new element.
|
|
61
|
+
*
|
|
62
|
+
* @param {ReactComponent} internalInstance
|
|
63
|
+
* @param {ReactElement} nextElement
|
|
64
|
+
* @param {ReactReconcileTransaction} transaction
|
|
65
|
+
* @param {object} context
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
receiveComponent: function(
|
|
69
|
+
internalInstance, nextElement, transaction, context
|
|
70
|
+
) {
|
|
71
|
+
var prevElement = internalInstance._currentElement;
|
|
72
|
+
|
|
73
|
+
if (nextElement === prevElement && nextElement._owner != null) {
|
|
74
|
+
// Since elements are immutable after the owner is rendered,
|
|
75
|
+
// we can do a cheap identity compare here to determine if this is a
|
|
76
|
+
// superfluous reconcile. It's possible for state to be mutable but such
|
|
77
|
+
// change should trigger an update of the owner which would recreate
|
|
78
|
+
// the element. We explicitly check for the existence of an owner since
|
|
79
|
+
// it's possible for an element created outside a composite to be
|
|
80
|
+
// deeply mutated and reused.
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
85
|
+
ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var refsChanged = ReactRef.shouldUpdateRefs(
|
|
89
|
+
this,
|
|
90
|
+
prevElement,
|
|
91
|
+
nextElement
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (refsChanged) {
|
|
95
|
+
ReactRef.detachRefs(internalInstance, prevElement);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
internalInstance.receiveComponent(nextElement, transaction, context);
|
|
99
|
+
|
|
100
|
+
if (refsChanged) {
|
|
101
|
+
transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Flush any dirty changes in a component.
|
|
107
|
+
*
|
|
108
|
+
* @param {ReactComponent} internalInstance
|
|
109
|
+
* @param {ReactReconcileTransaction} transaction
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
performUpdateIfNecessary: function(
|
|
113
|
+
internalInstance,
|
|
114
|
+
transaction
|
|
115
|
+
) {
|
|
116
|
+
internalInstance.performUpdateIfNecessary(transaction);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
module.exports = ReactReconciler;
|
package/lib/ReactRef.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-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 ReactRef
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactOwner = require("./ReactOwner");
|
|
15
|
+
|
|
16
|
+
var ReactRef = {};
|
|
17
|
+
|
|
18
|
+
function attachRef(ref, component, owner) {
|
|
19
|
+
if (typeof ref === 'function') {
|
|
20
|
+
ref(component.getPublicInstance());
|
|
21
|
+
} else {
|
|
22
|
+
// Legacy ref
|
|
23
|
+
ReactOwner.addComponentAsRefTo(component, ref, owner);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function detachRef(ref, component, owner) {
|
|
28
|
+
if (typeof ref === 'function') {
|
|
29
|
+
ref(null);
|
|
30
|
+
} else {
|
|
31
|
+
// Legacy ref
|
|
32
|
+
ReactOwner.removeComponentAsRefFrom(component, ref, owner);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ReactRef.attachRefs = function(instance, element) {
|
|
37
|
+
var ref = element.ref;
|
|
38
|
+
if (ref != null) {
|
|
39
|
+
attachRef(ref, instance, element._owner);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
ReactRef.shouldUpdateRefs = function(instance, prevElement, nextElement) {
|
|
44
|
+
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
45
|
+
// has stored a reference to `this`, and the previous owner (if different)
|
|
46
|
+
// has forgotten the reference to `this`. We use the element instead
|
|
47
|
+
// of the public this.props because the post processing cannot determine
|
|
48
|
+
// a ref. The ref conceptually lives on the element.
|
|
49
|
+
|
|
50
|
+
// TODO: Should this even be possible? The owner cannot change because
|
|
51
|
+
// it's forbidden by shouldUpdateReactComponent. The ref can change
|
|
52
|
+
// if you swap the keys of but not the refs. Reconsider where this check
|
|
53
|
+
// is made. It probably belongs where the key checking and
|
|
54
|
+
// instantiateReactComponent is done.
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
nextElement._owner !== prevElement._owner ||
|
|
58
|
+
nextElement.ref !== prevElement.ref
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
ReactRef.detachRefs = function(instance, element) {
|
|
63
|
+
var ref = element.ref;
|
|
64
|
+
if (ref != null) {
|
|
65
|
+
detachRef(ref, instance, element._owner);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports = ReactRef;
|