react 0.13.0-alpha.1 → 0.13.0-rc1
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 +1376 -596
- package/dist/react-with-addons.js +3256 -2363
- package/dist/react-with-addons.min.js +7 -7
- package/dist/react.js +3092 -2266
- package/dist/react.min.js +6 -7
- package/lib/AutoFocusMixin.js +2 -2
- package/lib/BeforeInputEventPlugin.js +5 -9
- package/lib/CSSCore.js +1 -1
- package/lib/CSSProperty.js +4 -2
- package/lib/CSSPropertyOperations.js +44 -17
- package/lib/CallbackQueue.js +3 -3
- package/lib/ChangeEventPlugin.js +2 -2
- 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 +7 -6
- package/lib/DefaultEventPluginOrder.js +3 -3
- 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 +1 -1
- package/lib/FallbackCompositionState.js +7 -5
- package/lib/HTMLDOMPropertyConfig.js +22 -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 +2 -2
- package/lib/PooledClass.js +2 -2
- package/lib/React.js +9 -13
- package/lib/ReactBrowserComponentMixin.js +2 -2
- package/lib/ReactBrowserEventEmitter.js +4 -4
- package/lib/ReactCSSTransitionGroup.js +2 -2
- package/lib/ReactCSSTransitionGroupChild.js +12 -7
- package/lib/ReactChildReconciler.js +11 -7
- package/lib/ReactChildren.js +13 -10
- package/lib/ReactClass.js +161 -135
- package/lib/ReactComponent.js +100 -158
- package/lib/ReactComponentBrowserEnvironment.js +2 -2
- package/lib/ReactComponentEnvironment.js +3 -3
- package/lib/ReactComponentWithPureRenderMixin.js +2 -2
- package/lib/ReactCompositeComponent.js +336 -484
- package/lib/ReactContext.js +14 -4
- package/lib/ReactCurrentOwner.js +2 -2
- package/lib/ReactDOM.js +2 -2
- package/lib/ReactDOMButton.js +2 -2
- package/lib/ReactDOMComponent.js +42 -52
- package/lib/ReactDOMForm.js +2 -2
- package/lib/ReactDOMIDOperations.js +4 -4
- package/lib/ReactDOMIframe.js +43 -0
- package/lib/ReactDOMImg.js +2 -2
- package/lib/ReactDOMInput.js +2 -2
- package/lib/ReactDOMOption.js +2 -2
- package/lib/ReactDOMSelect.js +3 -3
- package/lib/ReactDOMSelection.js +2 -2
- package/lib/ReactDOMTextComponent.js +4 -13
- package/lib/ReactDOMTextarea.js +2 -2
- package/lib/ReactDefaultBatchingStrategy.js +5 -5
- package/lib/ReactDefaultInjection.js +26 -2
- package/lib/ReactDefaultPerf.js +12 -4
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +7 -5
- package/lib/ReactElementValidator.js +185 -65
- package/lib/ReactEmptyComponent.js +17 -6
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +2 -2
- package/lib/ReactEventListener.js +4 -5
- package/lib/ReactFragment.js +180 -0
- package/lib/ReactInjection.js +2 -2
- package/lib/ReactInputSelection.js +2 -2
- package/lib/ReactInstanceHandles.js +4 -3
- package/lib/ReactInstanceMap.js +2 -2
- package/lib/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +2 -2
- package/lib/ReactMarkupChecksum.js +2 -2
- package/lib/ReactMount.js +87 -23
- package/lib/ReactMultiChild.js +19 -7
- package/lib/ReactMultiChildUpdateTypes.js +2 -2
- package/lib/ReactNativeComponent.js +34 -37
- package/lib/ReactOwner.js +2 -2
- package/lib/ReactPerf.js +2 -2
- package/lib/ReactPropTransferer.js +3 -3
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +2 -2
- package/lib/ReactPropTypes.js +16 -8
- package/lib/ReactPutListenerQueue.js +2 -2
- package/lib/ReactReconcileTransaction.js +2 -2
- package/lib/ReactReconciler.js +121 -0
- package/lib/ReactRef.js +41 -68
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +4 -3
- package/lib/ReactServerRenderingTransaction.js +2 -2
- package/lib/ReactStateSetters.js +2 -2
- package/lib/ReactTestUtils.js +49 -8
- package/lib/ReactTransitionChildMapping.js +8 -4
- package/lib/ReactTransitionEvents.js +2 -2
- package/lib/ReactTransitionGroup.js +6 -6
- package/lib/ReactUpdateQueue.js +295 -0
- package/lib/ReactUpdates.js +13 -22
- 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 +2 -2
- package/lib/SyntheticTouchEvent.js +2 -2
- package/lib/SyntheticUIEvent.js +2 -2
- package/lib/SyntheticWheelEvent.js +2 -2
- package/lib/Transaction.js +5 -5
- package/lib/ViewportMetrics.js +2 -2
- 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 +2 -2
- package/lib/createNodesFromMarkup.js +4 -4
- package/lib/cx.js +16 -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 +26 -9
- package/lib/flattenChildren.js +11 -9
- 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 +2 -2
- 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 +21 -21
- package/lib/invariant.js +1 -1
- package/lib/isEventSupported.js +2 -2
- package/lib/isNode.js +1 -1
- package/lib/isTextInputElement.js +2 -2
- 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 +64 -8
- package/lib/toArray.js +2 -2
- package/lib/traverseAllChildren.js +19 -5
- package/lib/update.js +2 -2
- package/lib/warning.js +20 -2
- package/package.json +1 -1
- package/lib/accumulate.js +0 -47
- package/lib/copyProperties.js +0 -56
- package/lib/merge.js +0 -34
- package/lib/mergeInto.js +0 -24
- package/lib/monitorCodeUse.js +0 -30
package/lib/ReactRootIndex.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
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @typechecks
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var ReactRootIndexInjection = {
|
|
16
16
|
/**
|
|
@@ -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
|
* @typechecks static-only
|
|
10
10
|
* @providesModule ReactServerRendering
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
15
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
@@ -38,7 +38,8 @@ function renderToString(element) {
|
|
|
38
38
|
|
|
39
39
|
return transaction.perform(function() {
|
|
40
40
|
var componentInstance = instantiateReactComponent(element, null);
|
|
41
|
-
var markup =
|
|
41
|
+
var markup =
|
|
42
|
+
componentInstance.mountComponent(id, transaction, emptyObject);
|
|
42
43
|
return ReactMarkupChecksum.addChecksumToMarkup(markup);
|
|
43
44
|
}, null);
|
|
44
45
|
} finally {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2014, Facebook, Inc.
|
|
2
|
+
* Copyright 2014-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
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var PooledClass = require("./PooledClass");
|
|
16
16
|
var CallbackQueue = require("./CallbackQueue");
|
package/lib/ReactStateSetters.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,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactStateSetters
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactStateSetters = {
|
|
15
15
|
/**
|
package/lib/ReactTestUtils.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,13 +9,14 @@
|
|
|
9
9
|
* @providesModule ReactTestUtils
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var EventConstants = require("./EventConstants");
|
|
15
15
|
var EventPluginHub = require("./EventPluginHub");
|
|
16
16
|
var EventPropagators = require("./EventPropagators");
|
|
17
17
|
var React = require("./React");
|
|
18
18
|
var ReactElement = require("./ReactElement");
|
|
19
|
+
var ReactEmptyComponent = require("./ReactEmptyComponent");
|
|
19
20
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
20
21
|
var ReactCompositeComponent = require("./ReactCompositeComponent");
|
|
21
22
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
@@ -169,7 +170,7 @@ var ReactTestUtils = {
|
|
|
169
170
|
var all =
|
|
170
171
|
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
171
172
|
if (all.length !== 1) {
|
|
172
|
-
throw new Error('Did not find exactly one match '+
|
|
173
|
+
throw new Error('Did not find exactly one match ' +
|
|
173
174
|
'(found: ' + all.length + ') for class:' + className
|
|
174
175
|
);
|
|
175
176
|
}
|
|
@@ -320,15 +321,49 @@ var ReactShallowRenderer = function() {
|
|
|
320
321
|
};
|
|
321
322
|
|
|
322
323
|
ReactShallowRenderer.prototype.getRenderOutput = function() {
|
|
323
|
-
return (
|
|
324
|
+
return (
|
|
325
|
+
(this._instance && this._instance._renderedComponent &&
|
|
326
|
+
this._instance._renderedComponent._renderedOutput)
|
|
327
|
+
|| null
|
|
328
|
+
);
|
|
324
329
|
};
|
|
325
330
|
|
|
326
|
-
var
|
|
327
|
-
this.
|
|
331
|
+
var NoopInternalComponent = function(element) {
|
|
332
|
+
this._renderedOutput = element;
|
|
333
|
+
this._currentElement = element === null || element === false ?
|
|
334
|
+
ReactEmptyComponent.emptyElement :
|
|
335
|
+
element;
|
|
328
336
|
};
|
|
337
|
+
|
|
338
|
+
NoopInternalComponent.prototype = {
|
|
339
|
+
|
|
340
|
+
mountComponent: function() {
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
receiveComponent: function(element) {
|
|
344
|
+
this._renderedOutput = element;
|
|
345
|
+
this._currentElement = element === null || element === false ?
|
|
346
|
+
ReactEmptyComponent.emptyElement :
|
|
347
|
+
element;
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
unmountComponent: function() {
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
var ShallowComponentWrapper = function() { };
|
|
329
356
|
assign(
|
|
330
357
|
ShallowComponentWrapper.prototype,
|
|
331
|
-
ReactCompositeComponent.
|
|
358
|
+
ReactCompositeComponent.Mixin, {
|
|
359
|
+
_instantiateReactComponent: function(element) {
|
|
360
|
+
return new NoopInternalComponent(element);
|
|
361
|
+
},
|
|
362
|
+
_replaceNodeWithMarkupByID: function() {},
|
|
363
|
+
_renderValidatedComponent:
|
|
364
|
+
ReactCompositeComponent.Mixin.
|
|
365
|
+
_renderValidatedComponentWithoutOwnerOrContext
|
|
366
|
+
}
|
|
332
367
|
);
|
|
333
368
|
|
|
334
369
|
ReactShallowRenderer.prototype.render = function(element, context) {
|
|
@@ -337,10 +372,16 @@ ReactShallowRenderer.prototype.render = function(element, context) {
|
|
|
337
372
|
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
338
373
|
};
|
|
339
374
|
|
|
375
|
+
ReactShallowRenderer.prototype.unmount = function() {
|
|
376
|
+
if (this._instance) {
|
|
377
|
+
this._instance.unmountComponent();
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
340
381
|
ReactShallowRenderer.prototype._render = function(element, transaction, context) {
|
|
341
382
|
if (!this._instance) {
|
|
342
383
|
var rootID = ReactInstanceHandles.createReactRootID();
|
|
343
|
-
var instance = new ShallowComponentWrapper(
|
|
384
|
+
var instance = new ShallowComponentWrapper(element.type);
|
|
344
385
|
instance.construct(element);
|
|
345
386
|
|
|
346
387
|
instance.mountComponent(rootID, transaction, context);
|
|
@@ -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,9 +10,10 @@
|
|
|
10
10
|
* @providesModule ReactTransitionChildMapping
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
'use strict';
|
|
14
14
|
|
|
15
15
|
var ReactChildren = require("./ReactChildren");
|
|
16
|
+
var ReactFragment = require("./ReactFragment");
|
|
16
17
|
|
|
17
18
|
var ReactTransitionChildMapping = {
|
|
18
19
|
/**
|
|
@@ -23,9 +24,12 @@ var ReactTransitionChildMapping = {
|
|
|
23
24
|
* @return {object} Mapping of key to child
|
|
24
25
|
*/
|
|
25
26
|
getChildMapping: function(children) {
|
|
26
|
-
|
|
27
|
+
if (!children) {
|
|
28
|
+
return children;
|
|
29
|
+
}
|
|
30
|
+
return ReactFragment.extract(ReactChildren.map(children, function(child) {
|
|
27
31
|
return child;
|
|
28
|
-
});
|
|
32
|
+
}));
|
|
29
33
|
},
|
|
30
34
|
|
|
31
35
|
/**
|
|
@@ -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 ReactTransitionEvents
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
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 ReactTransitionGroup
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var React = require("./React");
|
|
15
15
|
var ReactTransitionChildMapping = require("./ReactTransitionChildMapping");
|
|
@@ -202,7 +202,7 @@ var ReactTransitionGroup = React.createClass({
|
|
|
202
202
|
render: function() {
|
|
203
203
|
// TODO: we could get rid of the need for the wrapper node
|
|
204
204
|
// by cloning a single child
|
|
205
|
-
var childrenToRender =
|
|
205
|
+
var childrenToRender = [];
|
|
206
206
|
for (var key in this.state.children) {
|
|
207
207
|
var child = this.state.children[key];
|
|
208
208
|
if (child) {
|
|
@@ -211,10 +211,10 @@ var ReactTransitionGroup = React.createClass({
|
|
|
211
211
|
// already been removed. In case you need this behavior you can provide
|
|
212
212
|
// a childFactory function to wrap every child, even the ones that are
|
|
213
213
|
// leaving.
|
|
214
|
-
childrenToRender
|
|
214
|
+
childrenToRender.push(cloneWithProps(
|
|
215
215
|
this.props.childFactory(child),
|
|
216
|
-
{ref: key}
|
|
217
|
-
);
|
|
216
|
+
{ref: key, key: key}
|
|
217
|
+
));
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
return React.createElement(
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 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 ReactUpdateQueue
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactLifeCycle = require("./ReactLifeCycle");
|
|
15
|
+
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
16
|
+
var ReactElement = require("./ReactElement");
|
|
17
|
+
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
18
|
+
var ReactUpdates = require("./ReactUpdates");
|
|
19
|
+
|
|
20
|
+
var assign = require("./Object.assign");
|
|
21
|
+
var invariant = require("./invariant");
|
|
22
|
+
var warning = require("./warning");
|
|
23
|
+
|
|
24
|
+
function enqueueUpdate(internalInstance) {
|
|
25
|
+
if (internalInstance !== ReactLifeCycle.currentlyMountingInstance) {
|
|
26
|
+
// If we're in a componentWillMount handler, don't enqueue a rerender
|
|
27
|
+
// because ReactUpdates assumes we're in a browser context (which is
|
|
28
|
+
// wrong for server rendering) and we're about to do a render anyway.
|
|
29
|
+
// See bug in #1740.
|
|
30
|
+
ReactUpdates.enqueueUpdate(internalInstance);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
|
35
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
36
|
+
ReactCurrentOwner.current == null,
|
|
37
|
+
'%s(...): Cannot update during an existing state transition ' +
|
|
38
|
+
'(such as within `render`). Render methods should be a pure function ' +
|
|
39
|
+
'of props and state.',
|
|
40
|
+
callerName
|
|
41
|
+
) : invariant(ReactCurrentOwner.current == null));
|
|
42
|
+
|
|
43
|
+
var internalInstance = ReactInstanceMap.get(publicInstance);
|
|
44
|
+
if (!internalInstance) {
|
|
45
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
46
|
+
// Only warn when we have a callerName. Otherwise we should be silent.
|
|
47
|
+
// We're probably calling from enqueueCallback. We don't want to warn
|
|
48
|
+
// there because we already warned for the corresponding lifecycle method.
|
|
49
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
50
|
+
!callerName,
|
|
51
|
+
'%s(...): Can only update a mounted or mounting component. ' +
|
|
52
|
+
'This usually means you called %s() on an unmounted ' +
|
|
53
|
+
'component. This is a no-op.',
|
|
54
|
+
callerName,
|
|
55
|
+
callerName
|
|
56
|
+
) : null);
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (internalInstance === ReactLifeCycle.currentlyUnmountingInstance) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return internalInstance;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* ReactUpdateQueue allows for state updates to be scheduled into a later
|
|
70
|
+
* reconciliation step.
|
|
71
|
+
*/
|
|
72
|
+
var ReactUpdateQueue = {
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Enqueue a callback that will be executed after all the pending updates
|
|
76
|
+
* have processed.
|
|
77
|
+
*
|
|
78
|
+
* @param {ReactClass} publicInstance The instance to use as `this` context.
|
|
79
|
+
* @param {?function} callback Called after state is updated.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
enqueueCallback: function(publicInstance, callback) {
|
|
83
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
84
|
+
typeof callback === 'function',
|
|
85
|
+
'enqueueCallback(...): You called `setProps`, `replaceProps`, ' +
|
|
86
|
+
'`setState`, `replaceState`, or `forceUpdate` with a callback that ' +
|
|
87
|
+
'isn\'t callable.'
|
|
88
|
+
) : invariant(typeof callback === 'function'));
|
|
89
|
+
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
|
|
90
|
+
|
|
91
|
+
// Previously we would throw an error if we didn't have an internal
|
|
92
|
+
// instance. Since we want to make it a no-op instead, we mirror the same
|
|
93
|
+
// behavior we have in other enqueue* methods.
|
|
94
|
+
// We also need to ignore callbacks in componentWillMount. See
|
|
95
|
+
// enqueueUpdates.
|
|
96
|
+
if (!internalInstance ||
|
|
97
|
+
internalInstance === ReactLifeCycle.currentlyMountingInstance) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (internalInstance._pendingCallbacks) {
|
|
102
|
+
internalInstance._pendingCallbacks.push(callback);
|
|
103
|
+
} else {
|
|
104
|
+
internalInstance._pendingCallbacks = [callback];
|
|
105
|
+
}
|
|
106
|
+
// TODO: The callback here is ignored when setState is called from
|
|
107
|
+
// componentWillMount. Either fix it or disallow doing so completely in
|
|
108
|
+
// favor of getInitialState. Alternatively, we can disallow
|
|
109
|
+
// componentWillMount during server-side rendering.
|
|
110
|
+
enqueueUpdate(internalInstance);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
enqueueCallbackInternal: function(internalInstance, callback) {
|
|
114
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
115
|
+
typeof callback === 'function',
|
|
116
|
+
'enqueueCallback(...): You called `setProps`, `replaceProps`, ' +
|
|
117
|
+
'`setState`, `replaceState`, or `forceUpdate` with a callback that ' +
|
|
118
|
+
'isn\'t callable.'
|
|
119
|
+
) : invariant(typeof callback === 'function'));
|
|
120
|
+
if (internalInstance._pendingCallbacks) {
|
|
121
|
+
internalInstance._pendingCallbacks.push(callback);
|
|
122
|
+
} else {
|
|
123
|
+
internalInstance._pendingCallbacks = [callback];
|
|
124
|
+
}
|
|
125
|
+
enqueueUpdate(internalInstance);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Forces an update. This should only be invoked when it is known with
|
|
130
|
+
* certainty that we are **not** in a DOM transaction.
|
|
131
|
+
*
|
|
132
|
+
* You may want to call this when you know that some deeper aspect of the
|
|
133
|
+
* component's state has changed but `setState` was not called.
|
|
134
|
+
*
|
|
135
|
+
* This will not invoke `shouldUpdateComponent`, but it will invoke
|
|
136
|
+
* `componentWillUpdate` and `componentDidUpdate`.
|
|
137
|
+
*
|
|
138
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
enqueueForceUpdate: function(publicInstance) {
|
|
142
|
+
var internalInstance = getInternalInstanceReadyForUpdate(
|
|
143
|
+
publicInstance,
|
|
144
|
+
'forceUpdate'
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (!internalInstance) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
internalInstance._pendingForceUpdate = true;
|
|
152
|
+
|
|
153
|
+
enqueueUpdate(internalInstance);
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Replaces all of the state. Always use this or `setState` to mutate state.
|
|
158
|
+
* You should treat `this.state` as immutable.
|
|
159
|
+
*
|
|
160
|
+
* There is no guarantee that `this.state` will be immediately updated, so
|
|
161
|
+
* accessing `this.state` after calling this method may return the old value.
|
|
162
|
+
*
|
|
163
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
164
|
+
* @param {object} completeState Next state.
|
|
165
|
+
* @internal
|
|
166
|
+
*/
|
|
167
|
+
enqueueReplaceState: function(publicInstance, completeState) {
|
|
168
|
+
var internalInstance = getInternalInstanceReadyForUpdate(
|
|
169
|
+
publicInstance,
|
|
170
|
+
'replaceState'
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
if (!internalInstance) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
internalInstance._pendingStateQueue = [completeState];
|
|
178
|
+
internalInstance._pendingReplaceState = true;
|
|
179
|
+
|
|
180
|
+
enqueueUpdate(internalInstance);
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Sets a subset of the state. This only exists because _pendingState is
|
|
185
|
+
* internal. This provides a merging strategy that is not available to deep
|
|
186
|
+
* properties which is confusing. TODO: Expose pendingState or don't use it
|
|
187
|
+
* during the merge.
|
|
188
|
+
*
|
|
189
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
190
|
+
* @param {object} partialState Next partial state to be merged with state.
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
enqueueSetState: function(publicInstance, partialState) {
|
|
194
|
+
var internalInstance = getInternalInstanceReadyForUpdate(
|
|
195
|
+
publicInstance,
|
|
196
|
+
'setState'
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
if (!internalInstance) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var queue =
|
|
204
|
+
internalInstance._pendingStateQueue ||
|
|
205
|
+
(internalInstance._pendingStateQueue = []);
|
|
206
|
+
queue.push(partialState);
|
|
207
|
+
|
|
208
|
+
enqueueUpdate(internalInstance);
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Sets a subset of the props.
|
|
213
|
+
*
|
|
214
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
215
|
+
* @param {object} partialProps Subset of the next props.
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
enqueueSetProps: function(publicInstance, partialProps) {
|
|
219
|
+
var internalInstance = getInternalInstanceReadyForUpdate(
|
|
220
|
+
publicInstance,
|
|
221
|
+
'setProps'
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
if (!internalInstance) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
229
|
+
internalInstance._isTopLevel,
|
|
230
|
+
'setProps(...): You called `setProps` on a ' +
|
|
231
|
+
'component with a parent. This is an anti-pattern since props will ' +
|
|
232
|
+
'get reactively updated when rendered. Instead, change the owner\'s ' +
|
|
233
|
+
'`render` method to pass the correct value as props to the component ' +
|
|
234
|
+
'where it is created.'
|
|
235
|
+
) : invariant(internalInstance._isTopLevel));
|
|
236
|
+
|
|
237
|
+
// Merge with the pending element if it exists, otherwise with existing
|
|
238
|
+
// element props.
|
|
239
|
+
var element = internalInstance._pendingElement ||
|
|
240
|
+
internalInstance._currentElement;
|
|
241
|
+
var props = assign({}, element.props, partialProps);
|
|
242
|
+
internalInstance._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
243
|
+
element,
|
|
244
|
+
props
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
enqueueUpdate(internalInstance);
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Replaces all of the props.
|
|
252
|
+
*
|
|
253
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
254
|
+
* @param {object} props New props.
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
enqueueReplaceProps: function(publicInstance, props) {
|
|
258
|
+
var internalInstance = getInternalInstanceReadyForUpdate(
|
|
259
|
+
publicInstance,
|
|
260
|
+
'replaceProps'
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
if (!internalInstance) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
268
|
+
internalInstance._isTopLevel,
|
|
269
|
+
'replaceProps(...): You called `replaceProps` on a ' +
|
|
270
|
+
'component with a parent. This is an anti-pattern since props will ' +
|
|
271
|
+
'get reactively updated when rendered. Instead, change the owner\'s ' +
|
|
272
|
+
'`render` method to pass the correct value as props to the component ' +
|
|
273
|
+
'where it is created.'
|
|
274
|
+
) : invariant(internalInstance._isTopLevel));
|
|
275
|
+
|
|
276
|
+
// Merge with the pending element if it exists, otherwise with existing
|
|
277
|
+
// element props.
|
|
278
|
+
var element = internalInstance._pendingElement ||
|
|
279
|
+
internalInstance._currentElement;
|
|
280
|
+
internalInstance._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
281
|
+
element,
|
|
282
|
+
props
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
enqueueUpdate(internalInstance);
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
enqueueElementInternal: function(internalInstance, newElement) {
|
|
289
|
+
internalInstance._pendingElement = newElement;
|
|
290
|
+
enqueueUpdate(internalInstance);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
module.exports = ReactUpdateQueue;
|