react-test-renderer 15.5.0 → 15.5.4
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/lib/ReactShallowRenderer.js +6 -0
- package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
- package/lib/shallow/AutoFocusUtils.js +23 -0
- package/lib/shallow/BeforeInputEventPlugin.js +384 -0
- package/lib/shallow/CSSProperty.js +147 -0
- package/lib/shallow/CSSPropertyOperations.js +208 -0
- package/lib/shallow/CallbackQueue.js +118 -0
- package/lib/shallow/ChangeEventPlugin.js +345 -0
- package/lib/shallow/DOMChildrenOperations.js +224 -0
- package/lib/shallow/DOMLazyTree.js +117 -0
- package/lib/shallow/DOMNamespaces.js +19 -0
- package/lib/shallow/DOMProperty.js +209 -0
- package/lib/shallow/DOMPropertyOperations.js +236 -0
- package/lib/shallow/Danger.js +47 -0
- package/lib/shallow/DefaultEventPluginOrder.js +25 -0
- package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
- package/lib/shallow/EventConstants.js +91 -0
- package/lib/shallow/EventPluginHub.js +277 -0
- package/lib/shallow/EventPluginRegistry.js +254 -0
- package/lib/shallow/EventPluginUtils.js +225 -0
- package/lib/shallow/EventPropagators.js +133 -0
- package/lib/shallow/FallbackCompositionState.js +94 -0
- package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
- package/lib/shallow/KeyEscapeUtils.js +58 -0
- package/lib/shallow/LinkedValueUtils.js +137 -0
- package/lib/shallow/PluginModuleType.js +12 -0
- package/lib/shallow/PooledClass.js +111 -0
- package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
- package/lib/shallow/ReactChildFiber.js +243 -0
- package/lib/shallow/ReactChildReconciler.js +153 -0
- package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
- package/lib/shallow/ReactComponentEnvironment.js +45 -0
- package/lib/shallow/ReactCompositeComponent.js +901 -0
- package/lib/shallow/ReactCoroutine.js +80 -0
- package/lib/shallow/ReactDOM.js +110 -0
- package/lib/shallow/ReactDOMComponent.js +1000 -0
- package/lib/shallow/ReactDOMComponentFlags.js +17 -0
- package/lib/shallow/ReactDOMComponentTree.js +194 -0
- package/lib/shallow/ReactDOMContainerInfo.js +32 -0
- package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
- package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
- package/lib/shallow/ReactDOMFiber.js +97 -0
- package/lib/shallow/ReactDOMIDOperations.js +33 -0
- package/lib/shallow/ReactDOMInput.js +284 -0
- package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
- package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
- package/lib/shallow/ReactDOMOption.js +122 -0
- package/lib/shallow/ReactDOMSelect.js +199 -0
- package/lib/shallow/ReactDOMSelection.js +211 -0
- package/lib/shallow/ReactDOMServer.js +25 -0
- package/lib/shallow/ReactDOMTextComponent.js +163 -0
- package/lib/shallow/ReactDOMTextarea.js +159 -0
- package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
- package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
- package/lib/shallow/ReactDebugTool.js +358 -0
- package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
- package/lib/shallow/ReactDefaultInjection.js +85 -0
- package/lib/shallow/ReactElementSymbol.js +19 -0
- package/lib/shallow/ReactEmptyComponent.js +29 -0
- package/lib/shallow/ReactErrorUtils.js +75 -0
- package/lib/shallow/ReactEventEmitterMixin.js +32 -0
- package/lib/shallow/ReactEventListener.js +154 -0
- package/lib/shallow/ReactFeatureFlags.js +21 -0
- package/lib/shallow/ReactFiber.js +190 -0
- package/lib/shallow/ReactFiberBeginWork.js +380 -0
- package/lib/shallow/ReactFiberCommitWork.js +78 -0
- package/lib/shallow/ReactFiberCompleteWork.js +208 -0
- package/lib/shallow/ReactFiberReconciler.js +64 -0
- package/lib/shallow/ReactFiberRoot.js +29 -0
- package/lib/shallow/ReactFiberScheduler.js +331 -0
- package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
- package/lib/shallow/ReactHostComponent.js +67 -0
- package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
- package/lib/shallow/ReactInjection.js +33 -0
- package/lib/shallow/ReactInputSelection.js +123 -0
- package/lib/shallow/ReactInstanceMap.js +47 -0
- package/lib/shallow/ReactInstanceType.js +12 -0
- package/lib/shallow/ReactInstrumentation.js +23 -0
- package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
- package/lib/shallow/ReactMarkupChecksum.js +49 -0
- package/lib/shallow/ReactMount.js +537 -0
- package/lib/shallow/ReactMultiChild.js +449 -0
- package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
- package/lib/shallow/ReactNodeTypes.js +39 -0
- package/lib/shallow/ReactOwner.js +93 -0
- package/lib/shallow/ReactPerf.js +500 -0
- package/lib/shallow/ReactPriorityLevel.js +20 -0
- package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
- package/lib/shallow/ReactPropTypeLocations.js +12 -0
- package/lib/shallow/ReactPropTypesSecret.js +16 -0
- package/lib/shallow/ReactReconcileTransaction.js +177 -0
- package/lib/shallow/ReactReconciler.js +167 -0
- package/lib/shallow/ReactRef.js +88 -0
- package/lib/shallow/ReactReifiedYield.js +30 -0
- package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
- package/lib/shallow/ReactServerRendering.js +89 -0
- package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
- package/lib/shallow/ReactServerUpdateQueue.js +138 -0
- package/lib/shallow/ReactShallowRenderer.js +150 -0
- package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
- package/lib/shallow/ReactSyntheticEventType.js +14 -0
- package/lib/shallow/ReactTestEmptyComponent.js +36 -0
- package/lib/shallow/ReactTestMount.js +131 -0
- package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
- package/lib/shallow/ReactTestRenderer.js +139 -0
- package/lib/shallow/ReactTestTextComponent.js +40 -0
- package/lib/shallow/ReactTypeOfWork.js +23 -0
- package/lib/shallow/ReactTypes.js +12 -0
- package/lib/shallow/ReactUpdateQueue.js +235 -0
- package/lib/shallow/ReactUpdates.js +250 -0
- package/lib/shallow/ReactVersion.js +13 -0
- package/lib/shallow/ResponderEventPlugin.js +507 -0
- package/lib/shallow/ResponderSyntheticEvent.js +38 -0
- package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
- package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
- package/lib/shallow/SelectEventPlugin.js +190 -0
- package/lib/shallow/SimpleEventPlugin.js +227 -0
- package/lib/shallow/SyntheticAnimationEvent.js +38 -0
- package/lib/shallow/SyntheticClipboardEvent.js +37 -0
- package/lib/shallow/SyntheticCompositionEvent.js +35 -0
- package/lib/shallow/SyntheticDragEvent.js +35 -0
- package/lib/shallow/SyntheticEvent.js +267 -0
- package/lib/shallow/SyntheticFocusEvent.js +35 -0
- package/lib/shallow/SyntheticInputEvent.js +36 -0
- package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
- package/lib/shallow/SyntheticMouseEvent.js +71 -0
- package/lib/shallow/SyntheticTouchEvent.js +44 -0
- package/lib/shallow/SyntheticTransitionEvent.js +38 -0
- package/lib/shallow/SyntheticUIEvent.js +58 -0
- package/lib/shallow/SyntheticWheelEvent.js +53 -0
- package/lib/shallow/TapEventPlugin.js +115 -0
- package/lib/shallow/TouchHistoryMath.js +98 -0
- package/lib/shallow/Transaction.js +224 -0
- package/lib/shallow/ViewportMetrics.js +26 -0
- package/lib/shallow/accumulate.js +45 -0
- package/lib/shallow/accumulateInto.js +57 -0
- package/lib/shallow/adler32.js +43 -0
- package/lib/shallow/canDefineProperty.js +25 -0
- package/lib/shallow/checkReactTypeSpec.js +86 -0
- package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
- package/lib/shallow/dangerousStyleValue.js +78 -0
- package/lib/shallow/deprecated.js +56 -0
- package/lib/shallow/escapeTextContentForBrowser.js +122 -0
- package/lib/shallow/findDOMNode.js +59 -0
- package/lib/shallow/flattenChildren.js +75 -0
- package/lib/shallow/forEachAccumulated.js +30 -0
- package/lib/shallow/getEventCharCode.js +49 -0
- package/lib/shallow/getEventKey.js +101 -0
- package/lib/shallow/getEventModifierState.js +42 -0
- package/lib/shallow/getEventTarget.js +34 -0
- package/lib/shallow/getHostComponentFromComposite.js +29 -0
- package/lib/shallow/getIteratorFn.js +40 -0
- package/lib/shallow/getNodeForCharacterOffset.js +73 -0
- package/lib/shallow/getTextContentAccessor.js +32 -0
- package/lib/shallow/getVendorPrefixedEventName.js +100 -0
- package/lib/shallow/instantiateReactComponent.js +128 -0
- package/lib/shallow/isEventSupported.js +59 -0
- package/lib/shallow/isTextInputElement.js +50 -0
- package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
- package/lib/shallow/reactProdInvariant.js +38 -0
- package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
- package/lib/shallow/setInnerHTML.js +97 -0
- package/lib/shallow/setTextContent.js +51 -0
- package/lib/shallow/shouldUpdateReactComponent.js +41 -0
- package/lib/shallow/traverseAllChildren.js +175 -0
- package/lib/shallow/validateDOMNesting.js +376 -0
- package/package.json +1 -1
- package/shallow.js +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-present, 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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var _prodInvariant = require('./reactProdInvariant'),
|
|
15
|
+
_assign = require('object-assign');
|
|
16
|
+
|
|
17
|
+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
18
|
+
|
|
19
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
+
|
|
21
|
+
var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
|
22
|
+
var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
|
|
23
|
+
var ReactEmptyComponent = require('./ReactEmptyComponent');
|
|
24
|
+
var ReactMultiChild = require('./ReactMultiChild');
|
|
25
|
+
var ReactHostComponent = require('./ReactHostComponent');
|
|
26
|
+
var ReactTestMount = require('./ReactTestMount');
|
|
27
|
+
var ReactTestReconcileTransaction = require('./ReactTestReconcileTransaction');
|
|
28
|
+
var ReactUpdates = require('./ReactUpdates');
|
|
29
|
+
var ReactTestTextComponent = require('./ReactTestTextComponent');
|
|
30
|
+
var ReactTestEmptyComponent = require('./ReactTestEmptyComponent');
|
|
31
|
+
var invariant = require('fbjs/lib/invariant');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Drill down (through composites and empty components) until we get a native or
|
|
35
|
+
* native text component.
|
|
36
|
+
*
|
|
37
|
+
* This is pretty polymorphic but unavoidable with the current structure we have
|
|
38
|
+
* for `_renderedChildren`.
|
|
39
|
+
*/
|
|
40
|
+
function getRenderedHostOrTextFromComponent(component) {
|
|
41
|
+
var rendered;
|
|
42
|
+
while (rendered = component._renderedComponent) {
|
|
43
|
+
component = rendered;
|
|
44
|
+
}
|
|
45
|
+
return component;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var ReactTestComponent = function () {
|
|
49
|
+
function ReactTestComponent(element) {
|
|
50
|
+
_classCallCheck(this, ReactTestComponent);
|
|
51
|
+
|
|
52
|
+
this._currentElement = element;
|
|
53
|
+
this._renderedChildren = null;
|
|
54
|
+
this._topLevelWrapper = null;
|
|
55
|
+
this._hostContainerInfo = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ReactTestComponent.prototype.mountComponent = function mountComponent(transaction, nativeParent, hostContainerInfo, context) {
|
|
59
|
+
var element = this._currentElement;
|
|
60
|
+
this._hostContainerInfo = hostContainerInfo;
|
|
61
|
+
// $FlowFixMe https://github.com/facebook/flow/issues/1805
|
|
62
|
+
this.mountChildren(element.props.children, transaction, context);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
ReactTestComponent.prototype.receiveComponent = function receiveComponent(nextElement, transaction, context) {
|
|
66
|
+
this._currentElement = nextElement;
|
|
67
|
+
// $FlowFixMe https://github.com/facebook/flow/issues/1805
|
|
68
|
+
this.updateChildren(nextElement.props.children, transaction, context);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
ReactTestComponent.prototype.getPublicInstance = function getPublicInstance() {
|
|
72
|
+
var element = this._currentElement;
|
|
73
|
+
var hostContainerInfo = this._hostContainerInfo;
|
|
74
|
+
!hostContainerInfo ? process.env.NODE_ENV !== 'production' ? invariant(false, 'hostContainerInfo should be populated before getPublicInstance is called.') : _prodInvariant('145') : void 0;
|
|
75
|
+
return hostContainerInfo.createNodeMock(element);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
ReactTestComponent.prototype.toJSON = function toJSON() {
|
|
79
|
+
// not using `children`, but I don't want to rewrite without destructuring
|
|
80
|
+
// eslint-disable-next-line no-unused-vars
|
|
81
|
+
var _currentElement$props = this._currentElement.props,
|
|
82
|
+
children = _currentElement$props.children,
|
|
83
|
+
props = _objectWithoutProperties(_currentElement$props, ['children']);
|
|
84
|
+
|
|
85
|
+
var childrenJSON = [];
|
|
86
|
+
for (var key in this._renderedChildren) {
|
|
87
|
+
var inst = this._renderedChildren[key];
|
|
88
|
+
inst = getRenderedHostOrTextFromComponent(inst);
|
|
89
|
+
var json = inst.toJSON();
|
|
90
|
+
if (json !== undefined) {
|
|
91
|
+
childrenJSON.push(json);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var object = {
|
|
95
|
+
type: this._currentElement.type,
|
|
96
|
+
props: props,
|
|
97
|
+
children: childrenJSON.length ? childrenJSON : null
|
|
98
|
+
};
|
|
99
|
+
Object.defineProperty(object, '$$typeof', {
|
|
100
|
+
value: Symbol['for']('react.test.json')
|
|
101
|
+
});
|
|
102
|
+
return object;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
ReactTestComponent.prototype.getHostNode = function getHostNode() {};
|
|
106
|
+
|
|
107
|
+
ReactTestComponent.prototype.unmountComponent = function unmountComponent(safely, skipLifecycle) {
|
|
108
|
+
// $FlowFixMe https://github.com/facebook/flow/issues/1805
|
|
109
|
+
this.unmountChildren(safely, skipLifecycle);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return ReactTestComponent;
|
|
113
|
+
}();
|
|
114
|
+
|
|
115
|
+
_assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
|
|
116
|
+
|
|
117
|
+
// =============================================================================
|
|
118
|
+
|
|
119
|
+
ReactUpdates.injection.injectReconcileTransaction(ReactTestReconcileTransaction);
|
|
120
|
+
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
|
|
121
|
+
|
|
122
|
+
ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
|
|
123
|
+
ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
|
|
124
|
+
ReactEmptyComponent.injection.injectEmptyComponentFactory(function () {
|
|
125
|
+
return new ReactTestEmptyComponent();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
ReactComponentEnvironment.injection.injectEnvironment({
|
|
129
|
+
processChildrenUpdates: function () {},
|
|
130
|
+
replaceNodeWithMarkup: function () {}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
var ReactTestRenderer = {
|
|
134
|
+
create: ReactTestMount.render,
|
|
135
|
+
/* eslint-disable camelcase */
|
|
136
|
+
unstable_batchedUpdates: ReactUpdates.batchedUpdates
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
module.exports = ReactTestRenderer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-present, 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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
|
|
16
|
+
var ReactTestTextComponent = function () {
|
|
17
|
+
function ReactTestTextComponent(element) {
|
|
18
|
+
_classCallCheck(this, ReactTestTextComponent);
|
|
19
|
+
|
|
20
|
+
this._currentElement = element;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
ReactTestTextComponent.prototype.receiveComponent = function receiveComponent(nextElement) {
|
|
24
|
+
this._currentElement = nextElement;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
ReactTestTextComponent.prototype.toJSON = function toJSON() {
|
|
28
|
+
return this._currentElement;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
ReactTestTextComponent.prototype.mountComponent = function mountComponent() {};
|
|
32
|
+
|
|
33
|
+
ReactTestTextComponent.prototype.getHostNode = function getHostNode() {};
|
|
34
|
+
|
|
35
|
+
ReactTestTextComponent.prototype.unmountComponent = function unmountComponent() {};
|
|
36
|
+
|
|
37
|
+
return ReactTestTextComponent;
|
|
38
|
+
}();
|
|
39
|
+
|
|
40
|
+
module.exports = ReactTestTextComponent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-present, 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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
IndeterminateComponent: 0, // Before we know whether it is functional or class
|
|
16
|
+
FunctionalComponent: 1,
|
|
17
|
+
ClassComponent: 2,
|
|
18
|
+
HostContainer: 3, // Root of a host tree. Could be nested inside another node.
|
|
19
|
+
HostComponent: 4,
|
|
20
|
+
CoroutineComponent: 5,
|
|
21
|
+
CoroutineHandlerPhase: 6,
|
|
22
|
+
YieldComponent: 7
|
|
23
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014-present, 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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2015-present, 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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
14
|
+
|
|
15
|
+
var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
|
16
|
+
var ReactInstanceMap = require('./ReactInstanceMap');
|
|
17
|
+
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
18
|
+
var ReactUpdates = require('./ReactUpdates');
|
|
19
|
+
|
|
20
|
+
var invariant = require('fbjs/lib/invariant');
|
|
21
|
+
var warning = require('fbjs/lib/warning');
|
|
22
|
+
|
|
23
|
+
function enqueueUpdate(internalInstance) {
|
|
24
|
+
ReactUpdates.enqueueUpdate(internalInstance);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function formatUnexpectedArgument(arg) {
|
|
28
|
+
var type = typeof arg;
|
|
29
|
+
if (type !== 'object') {
|
|
30
|
+
return type;
|
|
31
|
+
}
|
|
32
|
+
var displayName = arg.constructor && arg.constructor.name || type;
|
|
33
|
+
var keys = Object.keys(arg);
|
|
34
|
+
if (keys.length > 0 && keys.length < 20) {
|
|
35
|
+
return displayName + ' (keys: ' + keys.join(', ') + ')';
|
|
36
|
+
}
|
|
37
|
+
return displayName;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
|
41
|
+
var internalInstance = ReactInstanceMap.get(publicInstance);
|
|
42
|
+
if (!internalInstance) {
|
|
43
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
+
var ctor = publicInstance.constructor;
|
|
45
|
+
// Only warn when we have a callerName. Otherwise we should be silent.
|
|
46
|
+
// We're probably calling from enqueueCallback. We don't want to warn
|
|
47
|
+
// there because we already warned for the corresponding lifecycle method.
|
|
48
|
+
process.env.NODE_ENV !== 'production' ? warning(!callerName, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, ctor && (ctor.displayName || ctor.name) || 'ReactClass') : void 0;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
54
|
+
process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, '%s(...): Cannot update during an existing state transition (such as ' + 'within `render` or another component\'s constructor). Render methods ' + 'should be a pure function of props and state; constructor ' + 'side-effects are an anti-pattern, but can be moved to ' + '`componentWillMount`.', callerName) : void 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return internalInstance;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* ReactUpdateQueue allows for state updates to be scheduled into a later
|
|
62
|
+
* reconciliation step.
|
|
63
|
+
*/
|
|
64
|
+
var ReactUpdateQueue = {
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Checks whether or not this composite component is mounted.
|
|
68
|
+
* @param {ReactClass} publicInstance The instance we want to test.
|
|
69
|
+
* @return {boolean} True if mounted, false otherwise.
|
|
70
|
+
* @protected
|
|
71
|
+
* @final
|
|
72
|
+
*/
|
|
73
|
+
isMounted: function (publicInstance) {
|
|
74
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
75
|
+
var owner = ReactCurrentOwner.current;
|
|
76
|
+
if (owner !== null) {
|
|
77
|
+
process.env.NODE_ENV !== 'production' ? warning(owner._warnedAboutRefsInRender, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : void 0;
|
|
78
|
+
owner._warnedAboutRefsInRender = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
var internalInstance = ReactInstanceMap.get(publicInstance);
|
|
82
|
+
if (internalInstance) {
|
|
83
|
+
// During componentWillMount and render this will still be null but after
|
|
84
|
+
// that will always render to something. At least for now. So we can use
|
|
85
|
+
// this hack.
|
|
86
|
+
return !!internalInstance._renderedComponent;
|
|
87
|
+
} else {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Enqueue a callback that will be executed after all the pending updates
|
|
94
|
+
* have processed.
|
|
95
|
+
*
|
|
96
|
+
* @param {ReactClass} publicInstance The instance to use as `this` context.
|
|
97
|
+
* @param {?function} callback Called after state is updated.
|
|
98
|
+
* @param {string} callerName Name of the calling function in the public API.
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
enqueueCallback: function (publicInstance, callback, callerName) {
|
|
102
|
+
ReactUpdateQueue.validateCallback(callback, callerName);
|
|
103
|
+
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
|
|
104
|
+
|
|
105
|
+
// Previously we would throw an error if we didn't have an internal
|
|
106
|
+
// instance. Since we want to make it a no-op instead, we mirror the same
|
|
107
|
+
// behavior we have in other enqueue* methods.
|
|
108
|
+
// We also need to ignore callbacks in componentWillMount. See
|
|
109
|
+
// enqueueUpdates.
|
|
110
|
+
if (!internalInstance) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (internalInstance._pendingCallbacks) {
|
|
115
|
+
internalInstance._pendingCallbacks.push(callback);
|
|
116
|
+
} else {
|
|
117
|
+
internalInstance._pendingCallbacks = [callback];
|
|
118
|
+
}
|
|
119
|
+
// TODO: The callback here is ignored when setState is called from
|
|
120
|
+
// componentWillMount. Either fix it or disallow doing so completely in
|
|
121
|
+
// favor of getInitialState. Alternatively, we can disallow
|
|
122
|
+
// componentWillMount during server-side rendering.
|
|
123
|
+
enqueueUpdate(internalInstance);
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
enqueueCallbackInternal: function (internalInstance, callback) {
|
|
127
|
+
if (internalInstance._pendingCallbacks) {
|
|
128
|
+
internalInstance._pendingCallbacks.push(callback);
|
|
129
|
+
} else {
|
|
130
|
+
internalInstance._pendingCallbacks = [callback];
|
|
131
|
+
}
|
|
132
|
+
enqueueUpdate(internalInstance);
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Forces an update. This should only be invoked when it is known with
|
|
137
|
+
* certainty that we are **not** in a DOM transaction.
|
|
138
|
+
*
|
|
139
|
+
* You may want to call this when you know that some deeper aspect of the
|
|
140
|
+
* component's state has changed but `setState` was not called.
|
|
141
|
+
*
|
|
142
|
+
* This will not invoke `shouldComponentUpdate`, but it will invoke
|
|
143
|
+
* `componentWillUpdate` and `componentDidUpdate`.
|
|
144
|
+
*
|
|
145
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
enqueueForceUpdate: function (publicInstance) {
|
|
149
|
+
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'forceUpdate');
|
|
150
|
+
|
|
151
|
+
if (!internalInstance) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
internalInstance._pendingForceUpdate = true;
|
|
156
|
+
|
|
157
|
+
enqueueUpdate(internalInstance);
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Replaces all of the state. Always use this or `setState` to mutate state.
|
|
162
|
+
* You should treat `this.state` as immutable.
|
|
163
|
+
*
|
|
164
|
+
* There is no guarantee that `this.state` will be immediately updated, so
|
|
165
|
+
* accessing `this.state` after calling this method may return the old value.
|
|
166
|
+
*
|
|
167
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
168
|
+
* @param {object} completeState Next state.
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
enqueueReplaceState: function (publicInstance, completeState, callback) {
|
|
172
|
+
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'replaceState');
|
|
173
|
+
|
|
174
|
+
if (!internalInstance) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
internalInstance._pendingStateQueue = [completeState];
|
|
179
|
+
internalInstance._pendingReplaceState = true;
|
|
180
|
+
|
|
181
|
+
// Future-proof 15.5
|
|
182
|
+
if (callback !== undefined && callback !== null) {
|
|
183
|
+
ReactUpdateQueue.validateCallback(callback, 'replaceState');
|
|
184
|
+
if (internalInstance._pendingCallbacks) {
|
|
185
|
+
internalInstance._pendingCallbacks.push(callback);
|
|
186
|
+
} else {
|
|
187
|
+
internalInstance._pendingCallbacks = [callback];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
enqueueUpdate(internalInstance);
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Sets a subset of the state. This only exists because _pendingState is
|
|
196
|
+
* internal. This provides a merging strategy that is not available to deep
|
|
197
|
+
* properties which is confusing. TODO: Expose pendingState or don't use it
|
|
198
|
+
* during the merge.
|
|
199
|
+
*
|
|
200
|
+
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
201
|
+
* @param {object} partialState Next partial state to be merged with state.
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
enqueueSetState: function (publicInstance, partialState) {
|
|
205
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
206
|
+
ReactInstrumentation.debugTool.onSetState();
|
|
207
|
+
process.env.NODE_ENV !== 'production' ? warning(partialState != null, 'setState(...): You passed an undefined or null state object; ' + 'instead, use forceUpdate().') : void 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'setState');
|
|
211
|
+
|
|
212
|
+
if (!internalInstance) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var queue = internalInstance._pendingStateQueue || (internalInstance._pendingStateQueue = []);
|
|
217
|
+
queue.push(partialState);
|
|
218
|
+
|
|
219
|
+
enqueueUpdate(internalInstance);
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
enqueueElementInternal: function (internalInstance, nextElement, nextContext) {
|
|
223
|
+
internalInstance._pendingElement = nextElement;
|
|
224
|
+
// TODO: introduce _pendingContext instead of setting it directly.
|
|
225
|
+
internalInstance._context = nextContext;
|
|
226
|
+
enqueueUpdate(internalInstance);
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
validateCallback: function (callback, callerName) {
|
|
230
|
+
!(!callback || typeof callback === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s(...): Expected the last optional `callback` argument to be a function. Instead received: %s.', callerName, formatUnexpectedArgument(callback)) : _prodInvariant('122', callerName, formatUnexpectedArgument(callback)) : void 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
module.exports = ReactUpdateQueue;
|