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,449 @@
|
|
|
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
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
14
|
+
|
|
15
|
+
var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
|
16
|
+
var ReactInstanceMap = require('./ReactInstanceMap');
|
|
17
|
+
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
18
|
+
|
|
19
|
+
var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
|
20
|
+
var ReactReconciler = require('./ReactReconciler');
|
|
21
|
+
var ReactChildReconciler = require('./ReactChildReconciler');
|
|
22
|
+
|
|
23
|
+
var emptyFunction = require('fbjs/lib/emptyFunction');
|
|
24
|
+
var flattenChildren = require('./flattenChildren');
|
|
25
|
+
var invariant = require('fbjs/lib/invariant');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Make an update for markup to be rendered and inserted at a supplied index.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} markup Markup that renders into an element.
|
|
31
|
+
* @param {number} toIndex Destination index.
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
function makeInsertMarkup(markup, afterNode, toIndex) {
|
|
35
|
+
// NOTE: Null values reduce hidden classes.
|
|
36
|
+
return {
|
|
37
|
+
type: 'INSERT_MARKUP',
|
|
38
|
+
content: markup,
|
|
39
|
+
fromIndex: null,
|
|
40
|
+
fromNode: null,
|
|
41
|
+
toIndex: toIndex,
|
|
42
|
+
afterNode: afterNode
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Make an update for moving an existing element to another index.
|
|
48
|
+
*
|
|
49
|
+
* @param {number} fromIndex Source index of the existing element.
|
|
50
|
+
* @param {number} toIndex Destination index of the element.
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
function makeMove(child, afterNode, toIndex) {
|
|
54
|
+
// NOTE: Null values reduce hidden classes.
|
|
55
|
+
return {
|
|
56
|
+
type: 'MOVE_EXISTING',
|
|
57
|
+
content: null,
|
|
58
|
+
fromIndex: child._mountIndex,
|
|
59
|
+
fromNode: ReactReconciler.getHostNode(child),
|
|
60
|
+
toIndex: toIndex,
|
|
61
|
+
afterNode: afterNode
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Make an update for removing an element at an index.
|
|
67
|
+
*
|
|
68
|
+
* @param {number} fromIndex Index of the element to remove.
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
function makeRemove(child, node) {
|
|
72
|
+
// NOTE: Null values reduce hidden classes.
|
|
73
|
+
return {
|
|
74
|
+
type: 'REMOVE_NODE',
|
|
75
|
+
content: null,
|
|
76
|
+
fromIndex: child._mountIndex,
|
|
77
|
+
fromNode: node,
|
|
78
|
+
toIndex: null,
|
|
79
|
+
afterNode: null
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Make an update for setting the markup of a node.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} markup Markup that renders into an element.
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
function makeSetMarkup(markup) {
|
|
90
|
+
// NOTE: Null values reduce hidden classes.
|
|
91
|
+
return {
|
|
92
|
+
type: 'SET_MARKUP',
|
|
93
|
+
content: markup,
|
|
94
|
+
fromIndex: null,
|
|
95
|
+
fromNode: null,
|
|
96
|
+
toIndex: null,
|
|
97
|
+
afterNode: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Make an update for setting the text content.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} textContent Text content to set.
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
function makeTextContent(textContent) {
|
|
108
|
+
// NOTE: Null values reduce hidden classes.
|
|
109
|
+
return {
|
|
110
|
+
type: 'TEXT_CONTENT',
|
|
111
|
+
content: textContent,
|
|
112
|
+
fromIndex: null,
|
|
113
|
+
fromNode: null,
|
|
114
|
+
toIndex: null,
|
|
115
|
+
afterNode: null
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Push an update, if any, onto the queue. Creates a new queue if none is
|
|
121
|
+
* passed and always returns the queue. Mutative.
|
|
122
|
+
*/
|
|
123
|
+
function enqueue(queue, update) {
|
|
124
|
+
if (update) {
|
|
125
|
+
queue = queue || [];
|
|
126
|
+
queue.push(update);
|
|
127
|
+
}
|
|
128
|
+
return queue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Processes any enqueued updates.
|
|
133
|
+
*
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
function processQueue(inst, updateQueue) {
|
|
137
|
+
ReactComponentEnvironment.processChildrenUpdates(inst, updateQueue);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var setChildrenForInstrumentation = emptyFunction;
|
|
141
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
142
|
+
var getDebugID = function (inst) {
|
|
143
|
+
if (!inst._debugID) {
|
|
144
|
+
// Check for ART-like instances. TODO: This is silly/gross.
|
|
145
|
+
var internal;
|
|
146
|
+
if (internal = ReactInstanceMap.get(inst)) {
|
|
147
|
+
inst = internal;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return inst._debugID;
|
|
151
|
+
};
|
|
152
|
+
setChildrenForInstrumentation = function (children) {
|
|
153
|
+
var debugID = getDebugID(this);
|
|
154
|
+
// TODO: React Native empty components are also multichild.
|
|
155
|
+
// This means they still get into this method but don't have _debugID.
|
|
156
|
+
if (debugID !== 0) {
|
|
157
|
+
ReactInstrumentation.debugTool.onSetChildren(debugID, children ? Object.keys(children).map(function (key) {
|
|
158
|
+
return children[key]._debugID;
|
|
159
|
+
}) : []);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* ReactMultiChild are capable of reconciling multiple children.
|
|
166
|
+
*
|
|
167
|
+
* @class ReactMultiChild
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
var ReactMultiChild = {
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Provides common functionality for components that must reconcile multiple
|
|
174
|
+
* children. This is used by `ReactDOMComponent` to mount, update, and
|
|
175
|
+
* unmount child components.
|
|
176
|
+
*
|
|
177
|
+
* @lends {ReactMultiChild.prototype}
|
|
178
|
+
*/
|
|
179
|
+
Mixin: {
|
|
180
|
+
|
|
181
|
+
_reconcilerInstantiateChildren: function (nestedChildren, transaction, context) {
|
|
182
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
183
|
+
var selfDebugID = getDebugID(this);
|
|
184
|
+
if (this._currentElement) {
|
|
185
|
+
try {
|
|
186
|
+
ReactCurrentOwner.current = this._currentElement._owner;
|
|
187
|
+
return ReactChildReconciler.instantiateChildren(nestedChildren, transaction, context, selfDebugID);
|
|
188
|
+
} finally {
|
|
189
|
+
ReactCurrentOwner.current = null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return ReactChildReconciler.instantiateChildren(nestedChildren, transaction, context);
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
_reconcilerUpdateChildren: function (prevChildren, nextNestedChildrenElements, mountImages, removedNodes, transaction, context) {
|
|
197
|
+
var nextChildren;
|
|
198
|
+
var selfDebugID = 0;
|
|
199
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
200
|
+
selfDebugID = getDebugID(this);
|
|
201
|
+
if (this._currentElement) {
|
|
202
|
+
try {
|
|
203
|
+
ReactCurrentOwner.current = this._currentElement._owner;
|
|
204
|
+
nextChildren = flattenChildren(nextNestedChildrenElements, selfDebugID);
|
|
205
|
+
} finally {
|
|
206
|
+
ReactCurrentOwner.current = null;
|
|
207
|
+
}
|
|
208
|
+
ReactChildReconciler.updateChildren(prevChildren, nextChildren, mountImages, removedNodes, transaction, this, this._hostContainerInfo, context, selfDebugID);
|
|
209
|
+
return nextChildren;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
nextChildren = flattenChildren(nextNestedChildrenElements, selfDebugID);
|
|
213
|
+
ReactChildReconciler.updateChildren(prevChildren, nextChildren, mountImages, removedNodes, transaction, this, this._hostContainerInfo, context, selfDebugID);
|
|
214
|
+
return nextChildren;
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Generates a "mount image" for each of the supplied children. In the case
|
|
219
|
+
* of `ReactDOMComponent`, a mount image is a string of markup.
|
|
220
|
+
*
|
|
221
|
+
* @param {?object} nestedChildren Nested child maps.
|
|
222
|
+
* @return {array} An array of mounted representations.
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
mountChildren: function (nestedChildren, transaction, context) {
|
|
226
|
+
var children = this._reconcilerInstantiateChildren(nestedChildren, transaction, context);
|
|
227
|
+
this._renderedChildren = children;
|
|
228
|
+
|
|
229
|
+
var mountImages = [];
|
|
230
|
+
var index = 0;
|
|
231
|
+
for (var name in children) {
|
|
232
|
+
if (children.hasOwnProperty(name)) {
|
|
233
|
+
var child = children[name];
|
|
234
|
+
var selfDebugID = 0;
|
|
235
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
236
|
+
selfDebugID = getDebugID(this);
|
|
237
|
+
}
|
|
238
|
+
var mountImage = ReactReconciler.mountComponent(child, transaction, this, this._hostContainerInfo, context, selfDebugID);
|
|
239
|
+
child._mountIndex = index++;
|
|
240
|
+
mountImages.push(mountImage);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
245
|
+
setChildrenForInstrumentation.call(this, children);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return mountImages;
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Replaces any rendered children with a text content string.
|
|
253
|
+
*
|
|
254
|
+
* @param {string} nextContent String of content.
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
updateTextContent: function (nextContent) {
|
|
258
|
+
var prevChildren = this._renderedChildren;
|
|
259
|
+
// Remove any rendered children.
|
|
260
|
+
ReactChildReconciler.unmountChildren(prevChildren, false);
|
|
261
|
+
for (var name in prevChildren) {
|
|
262
|
+
if (prevChildren.hasOwnProperty(name)) {
|
|
263
|
+
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'updateTextContent called on non-empty component.') : _prodInvariant('118') : void 0;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Set new text content.
|
|
267
|
+
var updates = [makeTextContent(nextContent)];
|
|
268
|
+
processQueue(this, updates);
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Replaces any rendered children with a markup string.
|
|
273
|
+
*
|
|
274
|
+
* @param {string} nextMarkup String of markup.
|
|
275
|
+
* @internal
|
|
276
|
+
*/
|
|
277
|
+
updateMarkup: function (nextMarkup) {
|
|
278
|
+
var prevChildren = this._renderedChildren;
|
|
279
|
+
// Remove any rendered children.
|
|
280
|
+
ReactChildReconciler.unmountChildren(prevChildren, false);
|
|
281
|
+
for (var name in prevChildren) {
|
|
282
|
+
if (prevChildren.hasOwnProperty(name)) {
|
|
283
|
+
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'updateTextContent called on non-empty component.') : _prodInvariant('118') : void 0;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
var updates = [makeSetMarkup(nextMarkup)];
|
|
287
|
+
processQueue(this, updates);
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Updates the rendered children with new children.
|
|
292
|
+
*
|
|
293
|
+
* @param {?object} nextNestedChildrenElements Nested child element maps.
|
|
294
|
+
* @param {ReactReconcileTransaction} transaction
|
|
295
|
+
* @internal
|
|
296
|
+
*/
|
|
297
|
+
updateChildren: function (nextNestedChildrenElements, transaction, context) {
|
|
298
|
+
// Hook used by React ART
|
|
299
|
+
this._updateChildren(nextNestedChildrenElements, transaction, context);
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* @param {?object} nextNestedChildrenElements Nested child element maps.
|
|
304
|
+
* @param {ReactReconcileTransaction} transaction
|
|
305
|
+
* @final
|
|
306
|
+
* @protected
|
|
307
|
+
*/
|
|
308
|
+
_updateChildren: function (nextNestedChildrenElements, transaction, context) {
|
|
309
|
+
var prevChildren = this._renderedChildren;
|
|
310
|
+
var removedNodes = {};
|
|
311
|
+
var mountImages = [];
|
|
312
|
+
var nextChildren = this._reconcilerUpdateChildren(prevChildren, nextNestedChildrenElements, mountImages, removedNodes, transaction, context);
|
|
313
|
+
if (!nextChildren && !prevChildren) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
var updates = null;
|
|
317
|
+
var name;
|
|
318
|
+
// `nextIndex` will increment for each child in `nextChildren`, but
|
|
319
|
+
// `lastIndex` will be the last index visited in `prevChildren`.
|
|
320
|
+
var nextIndex = 0;
|
|
321
|
+
var lastIndex = 0;
|
|
322
|
+
// `nextMountIndex` will increment for each newly mounted child.
|
|
323
|
+
var nextMountIndex = 0;
|
|
324
|
+
var lastPlacedNode = null;
|
|
325
|
+
for (name in nextChildren) {
|
|
326
|
+
if (!nextChildren.hasOwnProperty(name)) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
var prevChild = prevChildren && prevChildren[name];
|
|
330
|
+
var nextChild = nextChildren[name];
|
|
331
|
+
if (prevChild === nextChild) {
|
|
332
|
+
updates = enqueue(updates, this.moveChild(prevChild, lastPlacedNode, nextIndex, lastIndex));
|
|
333
|
+
lastIndex = Math.max(prevChild._mountIndex, lastIndex);
|
|
334
|
+
prevChild._mountIndex = nextIndex;
|
|
335
|
+
} else {
|
|
336
|
+
if (prevChild) {
|
|
337
|
+
// Update `lastIndex` before `_mountIndex` gets unset by unmounting.
|
|
338
|
+
lastIndex = Math.max(prevChild._mountIndex, lastIndex);
|
|
339
|
+
// The `removedNodes` loop below will actually remove the child.
|
|
340
|
+
}
|
|
341
|
+
// The child must be instantiated before it's mounted.
|
|
342
|
+
updates = enqueue(updates, this._mountChildAtIndex(nextChild, mountImages[nextMountIndex], lastPlacedNode, nextIndex, transaction, context));
|
|
343
|
+
nextMountIndex++;
|
|
344
|
+
}
|
|
345
|
+
nextIndex++;
|
|
346
|
+
lastPlacedNode = ReactReconciler.getHostNode(nextChild);
|
|
347
|
+
}
|
|
348
|
+
// Remove children that are no longer present.
|
|
349
|
+
for (name in removedNodes) {
|
|
350
|
+
if (removedNodes.hasOwnProperty(name)) {
|
|
351
|
+
updates = enqueue(updates, this._unmountChild(prevChildren[name], removedNodes[name]));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (updates) {
|
|
355
|
+
processQueue(this, updates);
|
|
356
|
+
}
|
|
357
|
+
this._renderedChildren = nextChildren;
|
|
358
|
+
|
|
359
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
360
|
+
setChildrenForInstrumentation.call(this, nextChildren);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Unmounts all rendered children. This should be used to clean up children
|
|
366
|
+
* when this component is unmounted. It does not actually perform any
|
|
367
|
+
* backend operations.
|
|
368
|
+
*
|
|
369
|
+
* @internal
|
|
370
|
+
*/
|
|
371
|
+
unmountChildren: function (safely) {
|
|
372
|
+
var renderedChildren = this._renderedChildren;
|
|
373
|
+
ReactChildReconciler.unmountChildren(renderedChildren, safely);
|
|
374
|
+
this._renderedChildren = null;
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Moves a child component to the supplied index.
|
|
379
|
+
*
|
|
380
|
+
* @param {ReactComponent} child Component to move.
|
|
381
|
+
* @param {number} toIndex Destination index of the element.
|
|
382
|
+
* @param {number} lastIndex Last index visited of the siblings of `child`.
|
|
383
|
+
* @protected
|
|
384
|
+
*/
|
|
385
|
+
moveChild: function (child, afterNode, toIndex, lastIndex) {
|
|
386
|
+
// If the index of `child` is less than `lastIndex`, then it needs to
|
|
387
|
+
// be moved. Otherwise, we do not need to move it because a child will be
|
|
388
|
+
// inserted or moved before `child`.
|
|
389
|
+
if (child._mountIndex < lastIndex) {
|
|
390
|
+
return makeMove(child, afterNode, toIndex);
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Creates a child component.
|
|
396
|
+
*
|
|
397
|
+
* @param {ReactComponent} child Component to create.
|
|
398
|
+
* @param {string} mountImage Markup to insert.
|
|
399
|
+
* @protected
|
|
400
|
+
*/
|
|
401
|
+
createChild: function (child, afterNode, mountImage) {
|
|
402
|
+
return makeInsertMarkup(mountImage, afterNode, child._mountIndex);
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Removes a child component.
|
|
407
|
+
*
|
|
408
|
+
* @param {ReactComponent} child Child to remove.
|
|
409
|
+
* @protected
|
|
410
|
+
*/
|
|
411
|
+
removeChild: function (child, node) {
|
|
412
|
+
return makeRemove(child, node);
|
|
413
|
+
},
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Mounts a child with the supplied name.
|
|
417
|
+
*
|
|
418
|
+
* NOTE: This is part of `updateChildren` and is here for readability.
|
|
419
|
+
*
|
|
420
|
+
* @param {ReactComponent} child Component to mount.
|
|
421
|
+
* @param {string} name Name of the child.
|
|
422
|
+
* @param {number} index Index at which to insert the child.
|
|
423
|
+
* @param {ReactReconcileTransaction} transaction
|
|
424
|
+
* @private
|
|
425
|
+
*/
|
|
426
|
+
_mountChildAtIndex: function (child, mountImage, afterNode, index, transaction, context) {
|
|
427
|
+
child._mountIndex = index;
|
|
428
|
+
return this.createChild(child, afterNode, mountImage);
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Unmounts a rendered child.
|
|
433
|
+
*
|
|
434
|
+
* NOTE: This is part of `updateChildren` and is here for readability.
|
|
435
|
+
*
|
|
436
|
+
* @param {ReactComponent} child Component to unmount.
|
|
437
|
+
* @private
|
|
438
|
+
*/
|
|
439
|
+
_unmountChild: function (child, node) {
|
|
440
|
+
var update = this.removeChild(child, node);
|
|
441
|
+
child._mountIndex = null;
|
|
442
|
+
return update;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
module.exports = ReactMultiChild;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* When a component's children are updated, a series of update configuration
|
|
15
|
+
* objects are created in order to batch and serialize the required changes.
|
|
16
|
+
*
|
|
17
|
+
* Enumerates all the possible types of update configurations.
|
|
18
|
+
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
16
|
+
var React = require('react/lib/React');
|
|
17
|
+
|
|
18
|
+
var invariant = require('fbjs/lib/invariant');
|
|
19
|
+
|
|
20
|
+
var ReactNodeTypes = {
|
|
21
|
+
HOST: 0,
|
|
22
|
+
COMPOSITE: 1,
|
|
23
|
+
EMPTY: 2,
|
|
24
|
+
|
|
25
|
+
getType: function (node) {
|
|
26
|
+
if (node === null || node === false) {
|
|
27
|
+
return ReactNodeTypes.EMPTY;
|
|
28
|
+
} else if (React.isValidElement(node)) {
|
|
29
|
+
if (typeof node.type === 'function') {
|
|
30
|
+
return ReactNodeTypes.COMPOSITE;
|
|
31
|
+
} else {
|
|
32
|
+
return ReactNodeTypes.HOST;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unexpected node: %s', node) : _prodInvariant('26', node) : void 0;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
module.exports = ReactNodeTypes;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
|
|
16
|
+
var invariant = require('fbjs/lib/invariant');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {?object} object
|
|
20
|
+
* @return {boolean} True if `object` is a valid owner.
|
|
21
|
+
* @final
|
|
22
|
+
*/
|
|
23
|
+
function isValidOwner(object) {
|
|
24
|
+
return !!(object && typeof object.attachRef === 'function' && typeof object.detachRef === 'function');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* ReactOwners are capable of storing references to owned components.
|
|
29
|
+
*
|
|
30
|
+
* All components are capable of //being// referenced by owner components, but
|
|
31
|
+
* only ReactOwner components are capable of //referencing// owned components.
|
|
32
|
+
* The named reference is known as a "ref".
|
|
33
|
+
*
|
|
34
|
+
* Refs are available when mounted and updated during reconciliation.
|
|
35
|
+
*
|
|
36
|
+
* var MyComponent = React.createClass({
|
|
37
|
+
* render: function() {
|
|
38
|
+
* return (
|
|
39
|
+
* <div onClick={this.handleClick}>
|
|
40
|
+
* <CustomComponent ref="custom" />
|
|
41
|
+
* </div>
|
|
42
|
+
* );
|
|
43
|
+
* },
|
|
44
|
+
* handleClick: function() {
|
|
45
|
+
* this.refs.custom.handleClick();
|
|
46
|
+
* },
|
|
47
|
+
* componentDidMount: function() {
|
|
48
|
+
* this.refs.custom.initialize();
|
|
49
|
+
* }
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* Refs should rarely be used. When refs are used, they should only be done to
|
|
53
|
+
* control data that is not handled by React's data flow.
|
|
54
|
+
*
|
|
55
|
+
* @class ReactOwner
|
|
56
|
+
*/
|
|
57
|
+
var ReactOwner = {
|
|
58
|
+
/**
|
|
59
|
+
* Adds a component by ref to an owner component.
|
|
60
|
+
*
|
|
61
|
+
* @param {ReactComponent} component Component to reference.
|
|
62
|
+
* @param {string} ref Name by which to refer to the component.
|
|
63
|
+
* @param {ReactOwner} owner Component on which to record the ref.
|
|
64
|
+
* @final
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
addComponentAsRefTo: function (component, ref, owner) {
|
|
68
|
+
!isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component\'s `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).') : _prodInvariant('119') : void 0;
|
|
69
|
+
owner.attachRef(ref, component);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Removes a component by ref from an owner component.
|
|
74
|
+
*
|
|
75
|
+
* @param {ReactComponent} component Component to dereference.
|
|
76
|
+
* @param {string} ref Name of the ref to remove.
|
|
77
|
+
* @param {ReactOwner} owner Component on which the ref is recorded.
|
|
78
|
+
* @final
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
removeComponentAsRefFrom: function (component, ref, owner) {
|
|
82
|
+
!isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs. You might be removing a ref to a component that was not created inside a component\'s `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).') : _prodInvariant('120') : void 0;
|
|
83
|
+
var ownerPublicInstance = owner.getPublicInstance();
|
|
84
|
+
// Check that `component`'s owner is still alive and that `component` is still the current ref
|
|
85
|
+
// because we do not want to detach the ref if another component stole it.
|
|
86
|
+
if (ownerPublicInstance && ownerPublicInstance.refs[ref] === component.getPublicInstance()) {
|
|
87
|
+
owner.detachRef(ref);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
module.exports = ReactOwner;
|