react-dom 16.10.2 → 16.13.1
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/build-info.json +5 -5
- package/cjs/react-dom-server.browser.development.js +411 -729
- package/cjs/react-dom-server.browser.production.min.js +41 -41
- package/cjs/react-dom-server.node.development.js +406 -720
- package/cjs/react-dom-server.node.production.min.js +40 -40
- package/cjs/react-dom-test-utils.development.js +200 -393
- package/cjs/react-dom-test-utils.production.min.js +22 -22
- package/cjs/react-dom-unstable-fizz.browser.development.js +11 -25
- package/cjs/react-dom-unstable-fizz.browser.production.min.js +3 -3
- package/cjs/react-dom-unstable-fizz.node.development.js +24 -27
- package/cjs/react-dom-unstable-fizz.node.production.min.js +4 -3
- package/cjs/react-dom-unstable-native-dependencies.development.js +203 -338
- package/cjs/react-dom-unstable-native-dependencies.production.min.js +23 -27
- package/cjs/react-dom.development.js +10451 -13365
- package/cjs/react-dom.production.min.js +280 -281
- package/cjs/react-dom.profiling.min.js +285 -285
- package/package.json +3 -3
- package/umd/react-dom-server.browser.development.js +3310 -3639
- package/umd/react-dom-server.browser.production.min.js +38 -38
- package/umd/react-dom-test-utils.development.js +1181 -1374
- package/umd/react-dom-test-utils.production.min.js +23 -23
- package/umd/react-dom-unstable-fizz.browser.development.js +105 -119
- package/umd/react-dom-unstable-fizz.browser.production.min.js +3 -3
- package/umd/react-dom-unstable-native-dependencies.development.js +1326 -1462
- package/umd/react-dom-unstable-native-dependencies.production.min.js +21 -22
- package/umd/react-dom.development.js +19905 -22830
- package/umd/react-dom.production.min.js +229 -234
- package/umd/react-dom.profiling.min.js +237 -241
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.
|
|
1
|
+
/** @license React v16.13.1
|
|
2
2
|
* react-dom-test-utils.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
@@ -10,1683 +10,1490 @@
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
(function (global, factory) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}(this, (function (React,ReactDOM) { 'use strict';
|
|
17
|
-
|
|
18
|
-
var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
19
|
-
var _assign = ReactInternals.assign;
|
|
20
|
-
|
|
21
|
-
// Do not require this module directly! Use normal `invariant` calls with
|
|
22
|
-
// template literal strings. The messages will be converted to ReactError during
|
|
23
|
-
// build, and in production they will be minified.
|
|
24
|
-
|
|
25
|
-
// Do not require this module directly! Use normal `invariant` calls with
|
|
26
|
-
// template literal strings. The messages will be converted to ReactError during
|
|
27
|
-
// build, and in production they will be minified.
|
|
28
|
-
function ReactError(error) {
|
|
29
|
-
error.name = 'Invariant Violation';
|
|
30
|
-
return error;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Use invariant() to assert state which your program assumes to be true.
|
|
35
|
-
*
|
|
36
|
-
* Provide sprintf-style format (only %s is supported) and arguments
|
|
37
|
-
* to provide information about what broke and what you were
|
|
38
|
-
* expecting.
|
|
39
|
-
*
|
|
40
|
-
* The invariant message will be stripped in production, but the invariant
|
|
41
|
-
* will remain to ensure logic does not differ in production.
|
|
42
|
-
*/
|
|
13
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('react-dom')) :
|
|
14
|
+
typeof define === 'function' && define.amd ? define(['react', 'react-dom'], factory) :
|
|
15
|
+
(global = global || self, global.ReactTestUtils = factory(global.React, global.ReactDOM));
|
|
16
|
+
}(this, (function (React, ReactDOM) { 'use strict';
|
|
43
17
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* This can be used to log issues in development environments in critical
|
|
47
|
-
* paths. Removing the logging code for production environments will keep the
|
|
48
|
-
* same logic and follow the same code paths.
|
|
49
|
-
*/
|
|
50
|
-
var warningWithoutStack = function () {};
|
|
18
|
+
var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
19
|
+
var _assign = ReactInternals.assign;
|
|
51
20
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
args[_key - 2] = arguments[_key];
|
|
56
|
-
}
|
|
21
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
|
|
22
|
+
// Current owner and dispatcher used to share the same ref,
|
|
23
|
+
// but PR #14548 split them out to better support the react-debug-tools package.
|
|
57
24
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
25
|
+
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
|
|
26
|
+
ReactSharedInternals.ReactCurrentDispatcher = {
|
|
27
|
+
current: null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
61
30
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
31
|
+
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
|
|
32
|
+
ReactSharedInternals.ReactCurrentBatchConfig = {
|
|
33
|
+
suspense: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
66
36
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
// by calls to these methods by a Babel plugin.
|
|
38
|
+
//
|
|
39
|
+
// In PROD (or in packages without access to React internals),
|
|
40
|
+
// they are left as they are instead.
|
|
70
41
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
42
|
+
function warn(format) {
|
|
43
|
+
{
|
|
44
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
45
|
+
args[_key - 1] = arguments[_key];
|
|
46
|
+
}
|
|
77
47
|
|
|
78
|
-
|
|
48
|
+
printWarning('warn', format, args);
|
|
79
49
|
}
|
|
50
|
+
}
|
|
51
|
+
function error(format) {
|
|
52
|
+
{
|
|
53
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
54
|
+
args[_key2 - 1] = arguments[_key2];
|
|
55
|
+
}
|
|
80
56
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// to find the callsite that caused this warning to fire.
|
|
85
|
-
var argIndex = 0;
|
|
86
|
-
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
87
|
-
return args[argIndex++];
|
|
88
|
-
});
|
|
89
|
-
throw new Error(message);
|
|
90
|
-
} catch (x) {}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
var warningWithoutStack$1 = warningWithoutStack;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
98
|
-
* instance (key) and the internal representation (value). This allows public
|
|
99
|
-
* methods to accept the user facing instance as an argument and map them back
|
|
100
|
-
* to internal methods.
|
|
101
|
-
*
|
|
102
|
-
* Note that this module is currently shared and assumed to be stateless.
|
|
103
|
-
* If this becomes an actual Map, that will break.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* This API should be called `delete` but we'd have to make sure to always
|
|
108
|
-
* transform these to strings for IE support. When this transform is fully
|
|
109
|
-
* supported we can rename it.
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
function get(key) {
|
|
113
|
-
return key._reactInternalFiber;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
|
|
117
|
-
// Current owner and dispatcher used to share the same ref,
|
|
118
|
-
// but PR #14548 split them out to better support the react-debug-tools package.
|
|
119
|
-
|
|
120
|
-
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
|
|
121
|
-
ReactSharedInternals.ReactCurrentDispatcher = {
|
|
122
|
-
current: null
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!ReactSharedInternals.hasOwnProperty('ReactCurrentBatchConfig')) {
|
|
127
|
-
ReactSharedInternals.ReactCurrentBatchConfig = {
|
|
128
|
-
suspense: null
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
133
|
-
// nor polyfill, then a plain number is used for performance.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
|
|
141
|
-
// (unstable) APIs that have been removed. Can we remove the symbols?
|
|
142
|
-
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
var FunctionComponent = 0;
|
|
148
|
-
var ClassComponent = 1;
|
|
149
|
-
// Before we know whether it is function or class
|
|
150
|
-
|
|
151
|
-
var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
|
|
152
|
-
|
|
153
|
-
// A subtree. Could be an entry point to a different renderer.
|
|
154
|
-
|
|
155
|
-
var HostComponent = 5;
|
|
156
|
-
var HostText = 6;
|
|
157
|
-
|
|
158
|
-
// Don't change these two values. They're used by React Dev Tools.
|
|
159
|
-
var NoEffect =
|
|
160
|
-
/* */
|
|
161
|
-
0;
|
|
162
|
-
// You can change the rest (and add more).
|
|
163
|
-
|
|
164
|
-
var Placement =
|
|
165
|
-
/* */
|
|
166
|
-
2;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var Hydrating =
|
|
177
|
-
/* */
|
|
178
|
-
1024;
|
|
179
|
-
// Passive & Update & Callback & Ref & Snapshot
|
|
180
|
-
|
|
181
|
-
// Union of all host effects
|
|
182
|
-
|
|
183
|
-
// Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
|
|
184
|
-
|
|
185
|
-
// In some cases, StrictMode should also double-render lifecycles.
|
|
186
|
-
// This can be confusing for tests though,
|
|
187
|
-
// And it can be bad for performance in production.
|
|
188
|
-
// This feature flag can be used to control the behavior:
|
|
189
|
-
|
|
190
|
-
// To preserve the "Pause on caught exceptions" behavior of the debugger, we
|
|
191
|
-
// replay the begin phase of a failed component inside invokeGuardedCallback.
|
|
192
|
-
|
|
193
|
-
// Warn about deprecated, async-unsafe lifecycles; relates to RFC #6:
|
|
194
|
-
|
|
195
|
-
// Gather advanced timing metrics for Profiler subtrees.
|
|
196
|
-
|
|
197
|
-
// Trace which interactions trigger each commit.
|
|
198
|
-
|
|
199
|
-
// Only used in www builds.
|
|
200
|
-
|
|
201
|
-
// TODO: true? Here it might just be false.
|
|
202
|
-
|
|
203
|
-
// Only used in www builds.
|
|
204
|
-
|
|
205
|
-
// Only used in www builds.
|
|
57
|
+
printWarning('error', format, args);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
206
60
|
|
|
207
|
-
|
|
61
|
+
function printWarning(level, format, args) {
|
|
62
|
+
// When changing this logic, you might want to also
|
|
63
|
+
// update consoleWithStackDev.www.js as well.
|
|
64
|
+
{
|
|
65
|
+
var hasExistingStack = args.length > 0 && typeof args[args.length - 1] === 'string' && args[args.length - 1].indexOf('\n in') === 0;
|
|
208
66
|
|
|
209
|
-
|
|
210
|
-
|
|
67
|
+
if (!hasExistingStack) {
|
|
68
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
69
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
211
70
|
|
|
212
|
-
|
|
213
|
-
|
|
71
|
+
if (stack !== '') {
|
|
72
|
+
format += '%s';
|
|
73
|
+
args = args.concat([stack]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
214
76
|
|
|
77
|
+
var argsWithFormat = args.map(function (item) {
|
|
78
|
+
return '' + item;
|
|
79
|
+
}); // Careful: RN currently depends on this prefix
|
|
215
80
|
|
|
216
|
-
//
|
|
217
|
-
//
|
|
81
|
+
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
82
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
83
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
|
218
84
|
|
|
219
|
-
|
|
85
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
220
86
|
|
|
221
|
-
|
|
87
|
+
try {
|
|
88
|
+
// --- Welcome to debugging React ---
|
|
89
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
90
|
+
// to find the callsite that caused this warning to fire.
|
|
91
|
+
var argIndex = 0;
|
|
92
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
93
|
+
return args[argIndex++];
|
|
94
|
+
});
|
|
95
|
+
throw new Error(message);
|
|
96
|
+
} catch (x) {}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
222
99
|
|
|
223
|
-
|
|
100
|
+
/**
|
|
101
|
+
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
102
|
+
* instance (key) and the internal representation (value). This allows public
|
|
103
|
+
* methods to accept the user facing instance as an argument and map them back
|
|
104
|
+
* to internal methods.
|
|
105
|
+
*
|
|
106
|
+
* Note that this module is currently shared and assumed to be stateless.
|
|
107
|
+
* If this becomes an actual Map, that will break.
|
|
108
|
+
*/
|
|
109
|
+
function get(key) {
|
|
110
|
+
return key._reactInternalFiber;
|
|
111
|
+
}
|
|
224
112
|
|
|
225
|
-
|
|
113
|
+
var FunctionComponent = 0;
|
|
114
|
+
var ClassComponent = 1;
|
|
226
115
|
|
|
227
|
-
//
|
|
228
|
-
// Till then, we warn about the missing mock, but still fallback to a sync mode compatible version
|
|
116
|
+
var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
|
|
229
117
|
|
|
230
|
-
|
|
231
|
-
|
|
118
|
+
var HostComponent = 5;
|
|
119
|
+
var HostText = 6;
|
|
232
120
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
121
|
+
// Don't change these two values. They're used by React Dev Tools.
|
|
122
|
+
var NoEffect =
|
|
123
|
+
/* */
|
|
124
|
+
0;
|
|
236
125
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
126
|
+
var Placement =
|
|
127
|
+
/* */
|
|
128
|
+
2;
|
|
129
|
+
var Hydrating =
|
|
130
|
+
/* */
|
|
131
|
+
1024;
|
|
242
132
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
133
|
+
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
|
134
|
+
function getNearestMountedFiber(fiber) {
|
|
135
|
+
var node = fiber;
|
|
136
|
+
var nearestMounted = fiber;
|
|
246
137
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
138
|
+
if (!fiber.alternate) {
|
|
139
|
+
// If there is no alternate, this might be a new tree that isn't inserted
|
|
140
|
+
// yet. If it is, then it will have a pending insertion effect on it.
|
|
141
|
+
var nextNode = node;
|
|
251
142
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
// yet. If it is, then it will have a pending insertion effect on it.
|
|
255
|
-
var nextNode = node;
|
|
143
|
+
do {
|
|
144
|
+
node = nextNode;
|
|
256
145
|
|
|
257
|
-
|
|
258
|
-
|
|
146
|
+
if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
|
|
147
|
+
// This is an insertion or in-progress hydration. The nearest possible
|
|
148
|
+
// mounted fiber is the parent but we need to continue to figure out
|
|
149
|
+
// if that one is still mounted.
|
|
150
|
+
nearestMounted = node.return;
|
|
151
|
+
}
|
|
259
152
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
153
|
+
nextNode = node.return;
|
|
154
|
+
} while (nextNode);
|
|
155
|
+
} else {
|
|
156
|
+
while (node.return) {
|
|
157
|
+
node = node.return;
|
|
265
158
|
}
|
|
266
|
-
|
|
267
|
-
nextNode = node.return;
|
|
268
|
-
} while (nextNode);
|
|
269
|
-
} else {
|
|
270
|
-
while (node.return) {
|
|
271
|
-
node = node.return;
|
|
272
159
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (node.tag === HostRoot) {
|
|
276
|
-
// TODO: Check if this was a nested HostRoot when used with
|
|
277
|
-
// renderContainerIntoSubtree.
|
|
278
|
-
return nearestMounted;
|
|
279
|
-
} // If we didn't hit the root, that means that we're in an disconnected tree
|
|
280
|
-
// that has been unmounted.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
160
|
|
|
161
|
+
if (node.tag === HostRoot) {
|
|
162
|
+
// TODO: Check if this was a nested HostRoot when used with
|
|
163
|
+
// renderContainerIntoSubtree.
|
|
164
|
+
return nearestMounted;
|
|
165
|
+
} // If we didn't hit the root, that means that we're in an disconnected tree
|
|
166
|
+
// that has been unmounted.
|
|
287
167
|
|
|
288
168
|
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
289
171
|
|
|
290
|
-
function assertIsMounted(fiber) {
|
|
291
|
-
(function () {
|
|
172
|
+
function assertIsMounted(fiber) {
|
|
292
173
|
if (!(getNearestMountedFiber(fiber) === fiber)) {
|
|
293
174
|
{
|
|
294
|
-
throw
|
|
175
|
+
throw Error( "Unable to find node on an unmounted component." );
|
|
295
176
|
}
|
|
296
177
|
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
178
|
+
}
|
|
299
179
|
|
|
300
|
-
function findCurrentFiberUsingSlowPath(fiber) {
|
|
301
|
-
|
|
180
|
+
function findCurrentFiberUsingSlowPath(fiber) {
|
|
181
|
+
var alternate = fiber.alternate;
|
|
302
182
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
183
|
+
if (!alternate) {
|
|
184
|
+
// If there is no alternate, then we only need to check if it is mounted.
|
|
185
|
+
var nearestMounted = getNearestMountedFiber(fiber);
|
|
306
186
|
|
|
307
|
-
(function () {
|
|
308
187
|
if (!(nearestMounted !== null)) {
|
|
309
188
|
{
|
|
310
|
-
throw
|
|
189
|
+
throw Error( "Unable to find node on an unmounted component." );
|
|
311
190
|
}
|
|
312
191
|
}
|
|
313
|
-
})();
|
|
314
192
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
193
|
+
if (nearestMounted !== fiber) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
318
196
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
197
|
+
return fiber;
|
|
198
|
+
} // If we have two possible branches, we'll walk backwards up to the root
|
|
199
|
+
// to see what path the root points to. On the way we may hit one of the
|
|
200
|
+
// special cases and we'll deal with them.
|
|
323
201
|
|
|
324
202
|
|
|
325
|
-
|
|
326
|
-
|
|
203
|
+
var a = fiber;
|
|
204
|
+
var b = alternate;
|
|
327
205
|
|
|
328
|
-
|
|
329
|
-
|
|
206
|
+
while (true) {
|
|
207
|
+
var parentA = a.return;
|
|
330
208
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
209
|
+
if (parentA === null) {
|
|
210
|
+
// We're at the root.
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
335
213
|
|
|
336
|
-
|
|
214
|
+
var parentB = parentA.alternate;
|
|
337
215
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
216
|
+
if (parentB === null) {
|
|
217
|
+
// There is no alternate. This is an unusual case. Currently, it only
|
|
218
|
+
// happens when a Suspense component is hidden. An extra fragment fiber
|
|
219
|
+
// is inserted in between the Suspense fiber and its children. Skip
|
|
220
|
+
// over this extra fragment fiber and proceed to the next parent.
|
|
221
|
+
var nextParent = parentA.return;
|
|
344
222
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
223
|
+
if (nextParent !== null) {
|
|
224
|
+
a = b = nextParent;
|
|
225
|
+
continue;
|
|
226
|
+
} // If there's no parent, we're at the root.
|
|
349
227
|
|
|
350
228
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
229
|
+
break;
|
|
230
|
+
} // If both copies of the parent fiber point to the same child, we can
|
|
231
|
+
// assume that the child is current. This happens when we bailout on low
|
|
232
|
+
// priority: the bailed out fiber's child reuses the current child.
|
|
355
233
|
|
|
356
234
|
|
|
357
|
-
|
|
358
|
-
|
|
235
|
+
if (parentA.child === parentB.child) {
|
|
236
|
+
var child = parentA.child;
|
|
359
237
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
238
|
+
while (child) {
|
|
239
|
+
if (child === a) {
|
|
240
|
+
// We've determined that A is the current branch.
|
|
241
|
+
assertIsMounted(parentA);
|
|
242
|
+
return fiber;
|
|
243
|
+
}
|
|
366
244
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
245
|
+
if (child === b) {
|
|
246
|
+
// We've determined that B is the current branch.
|
|
247
|
+
assertIsMounted(parentA);
|
|
248
|
+
return alternate;
|
|
249
|
+
}
|
|
372
250
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
251
|
+
child = child.sibling;
|
|
252
|
+
} // We should never have an alternate for any mounting node. So the only
|
|
253
|
+
// way this could possibly happen is if this was unmounted, if at all.
|
|
376
254
|
|
|
377
255
|
|
|
378
|
-
(function () {
|
|
379
256
|
{
|
|
380
257
|
{
|
|
381
|
-
throw
|
|
258
|
+
throw Error( "Unable to find node on an unmounted component." );
|
|
382
259
|
}
|
|
383
260
|
}
|
|
384
|
-
})();
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (a.return !== b.return) {
|
|
388
|
-
// The return pointer of A and the return pointer of B point to different
|
|
389
|
-
// fibers. We assume that return pointers never criss-cross, so A must
|
|
390
|
-
// belong to the child set of A.return, and B must belong to the child
|
|
391
|
-
// set of B.return.
|
|
392
|
-
a = parentA;
|
|
393
|
-
b = parentB;
|
|
394
|
-
} else {
|
|
395
|
-
// The return pointers point to the same fiber. We'll have to use the
|
|
396
|
-
// default, slow path: scan the child sets of each parent alternate to see
|
|
397
|
-
// which child belongs to which set.
|
|
398
|
-
//
|
|
399
|
-
// Search parent A's child set
|
|
400
|
-
var didFindChild = false;
|
|
401
|
-
var _child = parentA.child;
|
|
402
|
-
|
|
403
|
-
while (_child) {
|
|
404
|
-
if (_child === a) {
|
|
405
|
-
didFindChild = true;
|
|
406
|
-
a = parentA;
|
|
407
|
-
b = parentB;
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (_child === b) {
|
|
412
|
-
didFindChild = true;
|
|
413
|
-
b = parentA;
|
|
414
|
-
a = parentB;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
_child = _child.sibling;
|
|
419
261
|
}
|
|
420
262
|
|
|
421
|
-
if (
|
|
422
|
-
//
|
|
423
|
-
|
|
263
|
+
if (a.return !== b.return) {
|
|
264
|
+
// The return pointer of A and the return pointer of B point to different
|
|
265
|
+
// fibers. We assume that return pointers never criss-cross, so A must
|
|
266
|
+
// belong to the child set of A.return, and B must belong to the child
|
|
267
|
+
// set of B.return.
|
|
268
|
+
a = parentA;
|
|
269
|
+
b = parentB;
|
|
270
|
+
} else {
|
|
271
|
+
// The return pointers point to the same fiber. We'll have to use the
|
|
272
|
+
// default, slow path: scan the child sets of each parent alternate to see
|
|
273
|
+
// which child belongs to which set.
|
|
274
|
+
//
|
|
275
|
+
// Search parent A's child set
|
|
276
|
+
var didFindChild = false;
|
|
277
|
+
var _child = parentA.child;
|
|
424
278
|
|
|
425
279
|
while (_child) {
|
|
426
280
|
if (_child === a) {
|
|
427
281
|
didFindChild = true;
|
|
428
|
-
a =
|
|
429
|
-
b =
|
|
282
|
+
a = parentA;
|
|
283
|
+
b = parentB;
|
|
430
284
|
break;
|
|
431
285
|
}
|
|
432
286
|
|
|
433
287
|
if (_child === b) {
|
|
434
288
|
didFindChild = true;
|
|
435
|
-
b =
|
|
436
|
-
a =
|
|
289
|
+
b = parentA;
|
|
290
|
+
a = parentB;
|
|
437
291
|
break;
|
|
438
292
|
}
|
|
439
293
|
|
|
440
294
|
_child = _child.sibling;
|
|
441
295
|
}
|
|
442
296
|
|
|
443
|
-
|
|
297
|
+
if (!didFindChild) {
|
|
298
|
+
// Search parent B's child set
|
|
299
|
+
_child = parentB.child;
|
|
300
|
+
|
|
301
|
+
while (_child) {
|
|
302
|
+
if (_child === a) {
|
|
303
|
+
didFindChild = true;
|
|
304
|
+
a = parentB;
|
|
305
|
+
b = parentA;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (_child === b) {
|
|
310
|
+
didFindChild = true;
|
|
311
|
+
b = parentB;
|
|
312
|
+
a = parentA;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_child = _child.sibling;
|
|
317
|
+
}
|
|
318
|
+
|
|
444
319
|
if (!didFindChild) {
|
|
445
320
|
{
|
|
446
|
-
throw
|
|
321
|
+
throw Error( "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." );
|
|
447
322
|
}
|
|
448
323
|
}
|
|
449
|
-
}
|
|
324
|
+
}
|
|
450
325
|
}
|
|
451
|
-
}
|
|
452
326
|
|
|
453
|
-
(function () {
|
|
454
327
|
if (!(a.alternate === b)) {
|
|
455
328
|
{
|
|
456
|
-
throw
|
|
329
|
+
throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
|
|
457
330
|
}
|
|
458
331
|
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// unmounted.
|
|
332
|
+
} // If the root is not a host container, we're in a disconnected tree. I.e.
|
|
333
|
+
// unmounted.
|
|
462
334
|
|
|
463
335
|
|
|
464
|
-
(function () {
|
|
465
336
|
if (!(a.tag === HostRoot)) {
|
|
466
337
|
{
|
|
467
|
-
throw
|
|
338
|
+
throw Error( "Unable to find node on an unmounted component." );
|
|
468
339
|
}
|
|
469
340
|
}
|
|
470
|
-
})();
|
|
471
|
-
|
|
472
|
-
if (a.stateNode.current === a) {
|
|
473
|
-
// We've determined that A is the current branch.
|
|
474
|
-
return fiber;
|
|
475
|
-
} // Otherwise B has to be current branch.
|
|
476
341
|
|
|
342
|
+
if (a.stateNode.current === a) {
|
|
343
|
+
// We've determined that A is the current branch.
|
|
344
|
+
return fiber;
|
|
345
|
+
} // Otherwise B has to be current branch.
|
|
477
346
|
|
|
478
|
-
return alternate;
|
|
479
|
-
}
|
|
480
347
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* @interface Event
|
|
485
|
-
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
|
486
|
-
*/
|
|
348
|
+
return alternate;
|
|
349
|
+
}
|
|
487
350
|
|
|
488
|
-
var
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return null;
|
|
494
|
-
},
|
|
495
|
-
eventPhase: null,
|
|
496
|
-
bubbles: null,
|
|
497
|
-
cancelable: null,
|
|
498
|
-
timeStamp: function (event) {
|
|
499
|
-
return event.timeStamp || Date.now();
|
|
500
|
-
},
|
|
501
|
-
defaultPrevented: null,
|
|
502
|
-
isTrusted: null
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
function functionThatReturnsTrue() {
|
|
506
|
-
return true;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
function functionThatReturnsFalse() {
|
|
510
|
-
return false;
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Synthetic events are dispatched by event plugins, typically in response to a
|
|
514
|
-
* top-level event delegation handler.
|
|
515
|
-
*
|
|
516
|
-
* These systems should generally use pooling to reduce the frequency of garbage
|
|
517
|
-
* collection. The system should check `isPersistent` to determine whether the
|
|
518
|
-
* event should be released into the pool after being dispatched. Users that
|
|
519
|
-
* need a persisted event should invoke `persist`.
|
|
520
|
-
*
|
|
521
|
-
* Synthetic events (and subclasses) implement the DOM Level 3 Events API by
|
|
522
|
-
* normalizing browser quirks. Subclasses do not necessarily have to implement a
|
|
523
|
-
* DOM interface; custom application-specific events can also subclass this.
|
|
524
|
-
*
|
|
525
|
-
* @param {object} dispatchConfig Configuration used to dispatch this event.
|
|
526
|
-
* @param {*} targetInst Marker identifying the event target.
|
|
527
|
-
* @param {object} nativeEvent Native browser event.
|
|
528
|
-
* @param {DOMEventTarget} nativeEventTarget Target node.
|
|
529
|
-
*/
|
|
351
|
+
var EVENT_POOL_SIZE = 10;
|
|
352
|
+
/**
|
|
353
|
+
* @interface Event
|
|
354
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
|
355
|
+
*/
|
|
530
356
|
|
|
357
|
+
var EventInterface = {
|
|
358
|
+
type: null,
|
|
359
|
+
target: null,
|
|
360
|
+
// currentTarget is set when dispatching; no use in copying it here
|
|
361
|
+
currentTarget: function () {
|
|
362
|
+
return null;
|
|
363
|
+
},
|
|
364
|
+
eventPhase: null,
|
|
365
|
+
bubbles: null,
|
|
366
|
+
cancelable: null,
|
|
367
|
+
timeStamp: function (event) {
|
|
368
|
+
return event.timeStamp || Date.now();
|
|
369
|
+
},
|
|
370
|
+
defaultPrevented: null,
|
|
371
|
+
isTrusted: null
|
|
372
|
+
};
|
|
531
373
|
|
|
532
|
-
function
|
|
533
|
-
|
|
534
|
-
// these have a getter/setter for warnings
|
|
535
|
-
delete this.nativeEvent;
|
|
536
|
-
delete this.preventDefault;
|
|
537
|
-
delete this.stopPropagation;
|
|
538
|
-
delete this.isDefaultPrevented;
|
|
539
|
-
delete this.isPropagationStopped;
|
|
374
|
+
function functionThatReturnsTrue() {
|
|
375
|
+
return true;
|
|
540
376
|
}
|
|
541
377
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
378
|
+
function functionThatReturnsFalse() {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Synthetic events are dispatched by event plugins, typically in response to a
|
|
383
|
+
* top-level event delegation handler.
|
|
384
|
+
*
|
|
385
|
+
* These systems should generally use pooling to reduce the frequency of garbage
|
|
386
|
+
* collection. The system should check `isPersistent` to determine whether the
|
|
387
|
+
* event should be released into the pool after being dispatched. Users that
|
|
388
|
+
* need a persisted event should invoke `persist`.
|
|
389
|
+
*
|
|
390
|
+
* Synthetic events (and subclasses) implement the DOM Level 3 Events API by
|
|
391
|
+
* normalizing browser quirks. Subclasses do not necessarily have to implement a
|
|
392
|
+
* DOM interface; custom application-specific events can also subclass this.
|
|
393
|
+
*
|
|
394
|
+
* @param {object} dispatchConfig Configuration used to dispatch this event.
|
|
395
|
+
* @param {*} targetInst Marker identifying the event target.
|
|
396
|
+
* @param {object} nativeEvent Native browser event.
|
|
397
|
+
* @param {DOMEventTarget} nativeEventTarget Target node.
|
|
398
|
+
*/
|
|
546
399
|
|
|
547
|
-
for (var propName in Interface) {
|
|
548
|
-
if (!Interface.hasOwnProperty(propName)) {
|
|
549
|
-
continue;
|
|
550
|
-
}
|
|
551
400
|
|
|
401
|
+
function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarget) {
|
|
552
402
|
{
|
|
553
|
-
|
|
403
|
+
// these have a getter/setter for warnings
|
|
404
|
+
delete this.nativeEvent;
|
|
405
|
+
delete this.preventDefault;
|
|
406
|
+
delete this.stopPropagation;
|
|
407
|
+
delete this.isDefaultPrevented;
|
|
408
|
+
delete this.isPropagationStopped;
|
|
554
409
|
}
|
|
555
410
|
|
|
556
|
-
|
|
411
|
+
this.dispatchConfig = dispatchConfig;
|
|
412
|
+
this._targetInst = targetInst;
|
|
413
|
+
this.nativeEvent = nativeEvent;
|
|
414
|
+
var Interface = this.constructor.Interface;
|
|
557
415
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
416
|
+
for (var propName in Interface) {
|
|
417
|
+
if (!Interface.hasOwnProperty(propName)) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
{
|
|
422
|
+
delete this[propName]; // this has a getter/setter for warnings
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
var normalize = Interface[propName];
|
|
426
|
+
|
|
427
|
+
if (normalize) {
|
|
428
|
+
this[propName] = normalize(nativeEvent);
|
|
563
429
|
} else {
|
|
564
|
-
|
|
430
|
+
if (propName === 'target') {
|
|
431
|
+
this.target = nativeEventTarget;
|
|
432
|
+
} else {
|
|
433
|
+
this[propName] = nativeEvent[propName];
|
|
434
|
+
}
|
|
565
435
|
}
|
|
566
436
|
}
|
|
567
|
-
}
|
|
568
437
|
|
|
569
|
-
|
|
438
|
+
var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
|
439
|
+
|
|
440
|
+
if (defaultPrevented) {
|
|
441
|
+
this.isDefaultPrevented = functionThatReturnsTrue;
|
|
442
|
+
} else {
|
|
443
|
+
this.isDefaultPrevented = functionThatReturnsFalse;
|
|
444
|
+
}
|
|
570
445
|
|
|
571
|
-
|
|
572
|
-
this
|
|
573
|
-
} else {
|
|
574
|
-
this.isDefaultPrevented = functionThatReturnsFalse;
|
|
446
|
+
this.isPropagationStopped = functionThatReturnsFalse;
|
|
447
|
+
return this;
|
|
575
448
|
}
|
|
576
449
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
450
|
+
_assign(SyntheticEvent.prototype, {
|
|
451
|
+
preventDefault: function () {
|
|
452
|
+
this.defaultPrevented = true;
|
|
453
|
+
var event = this.nativeEvent;
|
|
580
454
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
var event = this.nativeEvent;
|
|
455
|
+
if (!event) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
585
458
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
459
|
+
if (event.preventDefault) {
|
|
460
|
+
event.preventDefault();
|
|
461
|
+
} else if (typeof event.returnValue !== 'unknown') {
|
|
462
|
+
event.returnValue = false;
|
|
463
|
+
}
|
|
589
464
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
event
|
|
594
|
-
}
|
|
465
|
+
this.isDefaultPrevented = functionThatReturnsTrue;
|
|
466
|
+
},
|
|
467
|
+
stopPropagation: function () {
|
|
468
|
+
var event = this.nativeEvent;
|
|
595
469
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
var event = this.nativeEvent;
|
|
470
|
+
if (!event) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
600
473
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
474
|
+
if (event.stopPropagation) {
|
|
475
|
+
event.stopPropagation();
|
|
476
|
+
} else if (typeof event.cancelBubble !== 'unknown') {
|
|
477
|
+
// The ChangeEventPlugin registers a "propertychange" event for
|
|
478
|
+
// IE. This event does not support bubbling or cancelling, and
|
|
479
|
+
// any references to cancelBubble throw "Member not found". A
|
|
480
|
+
// typeof check of "unknown" circumvents this issue (and is also
|
|
481
|
+
// IE specific).
|
|
482
|
+
event.cancelBubble = true;
|
|
483
|
+
}
|
|
604
484
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
} else if (typeof event.cancelBubble !== 'unknown') {
|
|
608
|
-
// The ChangeEventPlugin registers a "propertychange" event for
|
|
609
|
-
// IE. This event does not support bubbling or cancelling, and
|
|
610
|
-
// any references to cancelBubble throw "Member not found". A
|
|
611
|
-
// typeof check of "unknown" circumvents this issue (and is also
|
|
612
|
-
// IE specific).
|
|
613
|
-
event.cancelBubble = true;
|
|
614
|
-
}
|
|
485
|
+
this.isPropagationStopped = functionThatReturnsTrue;
|
|
486
|
+
},
|
|
615
487
|
|
|
616
|
-
|
|
617
|
-
|
|
488
|
+
/**
|
|
489
|
+
* We release all dispatched `SyntheticEvent`s after each event loop, adding
|
|
490
|
+
* them back into the pool. This allows a way to hold onto a reference that
|
|
491
|
+
* won't be added back into the pool.
|
|
492
|
+
*/
|
|
493
|
+
persist: function () {
|
|
494
|
+
this.isPersistent = functionThatReturnsTrue;
|
|
495
|
+
},
|
|
618
496
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
this.isPersistent = functionThatReturnsTrue;
|
|
626
|
-
},
|
|
497
|
+
/**
|
|
498
|
+
* Checks if this event should be released back into the pool.
|
|
499
|
+
*
|
|
500
|
+
* @return {boolean} True if this should not be released, false otherwise.
|
|
501
|
+
*/
|
|
502
|
+
isPersistent: functionThatReturnsFalse,
|
|
627
503
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
isPersistent: functionThatReturnsFalse,
|
|
504
|
+
/**
|
|
505
|
+
* `PooledClass` looks for `destructor` on each instance it releases.
|
|
506
|
+
*/
|
|
507
|
+
destructor: function () {
|
|
508
|
+
var Interface = this.constructor.Interface;
|
|
634
509
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
510
|
+
for (var propName in Interface) {
|
|
511
|
+
{
|
|
512
|
+
Object.defineProperty(this, propName, getPooledWarningPropertyDefinition(propName, Interface[propName]));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
this.dispatchConfig = null;
|
|
517
|
+
this._targetInst = null;
|
|
518
|
+
this.nativeEvent = null;
|
|
519
|
+
this.isDefaultPrevented = functionThatReturnsFalse;
|
|
520
|
+
this.isPropagationStopped = functionThatReturnsFalse;
|
|
521
|
+
this._dispatchListeners = null;
|
|
522
|
+
this._dispatchInstances = null;
|
|
640
523
|
|
|
641
|
-
for (var propName in Interface) {
|
|
642
524
|
{
|
|
643
|
-
Object.defineProperty(this,
|
|
525
|
+
Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
|
|
526
|
+
Object.defineProperty(this, 'isDefaultPrevented', getPooledWarningPropertyDefinition('isDefaultPrevented', functionThatReturnsFalse));
|
|
527
|
+
Object.defineProperty(this, 'isPropagationStopped', getPooledWarningPropertyDefinition('isPropagationStopped', functionThatReturnsFalse));
|
|
528
|
+
Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', function () {}));
|
|
529
|
+
Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', function () {}));
|
|
644
530
|
}
|
|
645
531
|
}
|
|
532
|
+
});
|
|
646
533
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
this.isPropagationStopped = functionThatReturnsFalse;
|
|
652
|
-
this._dispatchListeners = null;
|
|
653
|
-
this._dispatchInstances = null;
|
|
654
|
-
|
|
655
|
-
{
|
|
656
|
-
Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
|
|
657
|
-
Object.defineProperty(this, 'isDefaultPrevented', getPooledWarningPropertyDefinition('isDefaultPrevented', functionThatReturnsFalse));
|
|
658
|
-
Object.defineProperty(this, 'isPropagationStopped', getPooledWarningPropertyDefinition('isPropagationStopped', functionThatReturnsFalse));
|
|
659
|
-
Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', function () {}));
|
|
660
|
-
Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', function () {}));
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
});
|
|
534
|
+
SyntheticEvent.Interface = EventInterface;
|
|
535
|
+
/**
|
|
536
|
+
* Helper to reduce boilerplate when creating subclasses.
|
|
537
|
+
*/
|
|
664
538
|
|
|
665
|
-
SyntheticEvent.
|
|
666
|
-
|
|
667
|
-
* Helper to reduce boilerplate when creating subclasses.
|
|
668
|
-
*/
|
|
539
|
+
SyntheticEvent.extend = function (Interface) {
|
|
540
|
+
var Super = this;
|
|
669
541
|
|
|
670
|
-
|
|
671
|
-
var Super = this;
|
|
542
|
+
var E = function () {};
|
|
672
543
|
|
|
673
|
-
|
|
544
|
+
E.prototype = Super.prototype;
|
|
545
|
+
var prototype = new E();
|
|
674
546
|
|
|
675
|
-
|
|
676
|
-
|
|
547
|
+
function Class() {
|
|
548
|
+
return Super.apply(this, arguments);
|
|
549
|
+
}
|
|
677
550
|
|
|
678
|
-
|
|
679
|
-
return Super.apply(this, arguments);
|
|
680
|
-
}
|
|
551
|
+
_assign(prototype, Class.prototype);
|
|
681
552
|
|
|
682
|
-
|
|
553
|
+
Class.prototype = prototype;
|
|
554
|
+
Class.prototype.constructor = Class;
|
|
555
|
+
Class.Interface = _assign({}, Super.Interface, Interface);
|
|
556
|
+
Class.extend = Super.extend;
|
|
557
|
+
addEventPoolingTo(Class);
|
|
558
|
+
return Class;
|
|
559
|
+
};
|
|
683
560
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
561
|
+
addEventPoolingTo(SyntheticEvent);
|
|
562
|
+
/**
|
|
563
|
+
* Helper to nullify syntheticEvent instance properties when destructing
|
|
564
|
+
*
|
|
565
|
+
* @param {String} propName
|
|
566
|
+
* @param {?object} getVal
|
|
567
|
+
* @return {object} defineProperty object
|
|
568
|
+
*/
|
|
691
569
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
*/
|
|
570
|
+
function getPooledWarningPropertyDefinition(propName, getVal) {
|
|
571
|
+
var isFunction = typeof getVal === 'function';
|
|
572
|
+
return {
|
|
573
|
+
configurable: true,
|
|
574
|
+
set: set,
|
|
575
|
+
get: get
|
|
576
|
+
};
|
|
700
577
|
|
|
701
|
-
function
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
get: get
|
|
707
|
-
};
|
|
578
|
+
function set(val) {
|
|
579
|
+
var action = isFunction ? 'setting the method' : 'setting the property';
|
|
580
|
+
warn(action, 'This is effectively a no-op');
|
|
581
|
+
return val;
|
|
582
|
+
}
|
|
708
583
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
584
|
+
function get() {
|
|
585
|
+
var action = isFunction ? 'accessing the method' : 'accessing the property';
|
|
586
|
+
var result = isFunction ? 'This is a no-op function' : 'This is set to null';
|
|
587
|
+
warn(action, result);
|
|
588
|
+
return getVal;
|
|
589
|
+
}
|
|
714
590
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
591
|
+
function warn(action, result) {
|
|
592
|
+
{
|
|
593
|
+
error("This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
720
596
|
}
|
|
721
597
|
|
|
722
|
-
function
|
|
723
|
-
var
|
|
724
|
-
!warningCondition ? warningWithoutStack$1(false, "This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result) : void 0;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
598
|
+
function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
|
|
599
|
+
var EventConstructor = this;
|
|
727
600
|
|
|
728
|
-
|
|
729
|
-
|
|
601
|
+
if (EventConstructor.eventPool.length) {
|
|
602
|
+
var instance = EventConstructor.eventPool.pop();
|
|
603
|
+
EventConstructor.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst);
|
|
604
|
+
return instance;
|
|
605
|
+
}
|
|
730
606
|
|
|
731
|
-
|
|
732
|
-
var instance = EventConstructor.eventPool.pop();
|
|
733
|
-
EventConstructor.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst);
|
|
734
|
-
return instance;
|
|
607
|
+
return new EventConstructor(dispatchConfig, targetInst, nativeEvent, nativeInst);
|
|
735
608
|
}
|
|
736
609
|
|
|
737
|
-
|
|
738
|
-
|
|
610
|
+
function releasePooledEvent(event) {
|
|
611
|
+
var EventConstructor = this;
|
|
739
612
|
|
|
740
|
-
function releasePooledEvent(event) {
|
|
741
|
-
var EventConstructor = this;
|
|
742
|
-
|
|
743
|
-
(function () {
|
|
744
613
|
if (!(event instanceof EventConstructor)) {
|
|
745
614
|
{
|
|
746
|
-
throw
|
|
615
|
+
throw Error( "Trying to release an event instance into a pool of a different type." );
|
|
747
616
|
}
|
|
748
617
|
}
|
|
749
|
-
})();
|
|
750
618
|
|
|
751
|
-
|
|
619
|
+
event.destructor();
|
|
752
620
|
|
|
753
|
-
|
|
754
|
-
|
|
621
|
+
if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
|
|
622
|
+
EventConstructor.eventPool.push(event);
|
|
623
|
+
}
|
|
755
624
|
}
|
|
756
|
-
}
|
|
757
625
|
|
|
758
|
-
function addEventPoolingTo(EventConstructor) {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
/**
|
|
765
|
-
* Forked from fbjs/warning:
|
|
766
|
-
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
|
767
|
-
*
|
|
768
|
-
* Only change is we use console.warn instead of console.error,
|
|
769
|
-
* and do nothing when 'console' is not supported.
|
|
770
|
-
* This really simplifies the code.
|
|
771
|
-
* ---
|
|
772
|
-
* Similar to invariant but only logs a warning if the condition is not met.
|
|
773
|
-
* This can be used to log issues in development environments in critical
|
|
774
|
-
* paths. Removing the logging code for production environments will keep the
|
|
775
|
-
* same logic and follow the same code paths.
|
|
776
|
-
*/
|
|
777
|
-
var lowPriorityWarningWithoutStack = function () {};
|
|
626
|
+
function addEventPoolingTo(EventConstructor) {
|
|
627
|
+
EventConstructor.eventPool = [];
|
|
628
|
+
EventConstructor.getPooled = getPooledEvent;
|
|
629
|
+
EventConstructor.release = releasePooledEvent;
|
|
630
|
+
}
|
|
778
631
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
}
|
|
632
|
+
/**
|
|
633
|
+
* HTML nodeType values that represent the type of the node
|
|
634
|
+
*/
|
|
635
|
+
var ELEMENT_NODE = 1;
|
|
784
636
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
637
|
+
// Do not use the below two methods directly!
|
|
638
|
+
// Instead use constants exported from DOMTopLevelEventTypes in ReactDOM.
|
|
639
|
+
// (It is the only module that is allowed to access these methods.)
|
|
640
|
+
function unsafeCastStringToDOMTopLevelType(topLevelType) {
|
|
641
|
+
return topLevelType;
|
|
642
|
+
}
|
|
789
643
|
|
|
790
|
-
|
|
791
|
-
console.warn(message);
|
|
792
|
-
}
|
|
644
|
+
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
793
645
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
646
|
+
/**
|
|
647
|
+
* Generate a mapping of standard vendor prefixes using the defined style property and event name.
|
|
648
|
+
*
|
|
649
|
+
* @param {string} styleProp
|
|
650
|
+
* @param {string} eventName
|
|
651
|
+
* @returns {object}
|
|
652
|
+
*/
|
|
801
653
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
654
|
+
function makePrefixMap(styleProp, eventName) {
|
|
655
|
+
var prefixes = {};
|
|
656
|
+
prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
|
|
657
|
+
prefixes['Webkit' + styleProp] = 'webkit' + eventName;
|
|
658
|
+
prefixes['Moz' + styleProp] = 'moz' + eventName;
|
|
659
|
+
return prefixes;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* A list of event names to a configurable list of vendor prefixes.
|
|
663
|
+
*/
|
|
806
664
|
|
|
807
|
-
if (!condition) {
|
|
808
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
809
|
-
args[_key2 - 2] = arguments[_key2];
|
|
810
|
-
}
|
|
811
665
|
|
|
812
|
-
|
|
813
|
-
|
|
666
|
+
var vendorPrefixes = {
|
|
667
|
+
animationend: makePrefixMap('Animation', 'AnimationEnd'),
|
|
668
|
+
animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
|
|
669
|
+
animationstart: makePrefixMap('Animation', 'AnimationStart'),
|
|
670
|
+
transitionend: makePrefixMap('Transition', 'TransitionEnd')
|
|
814
671
|
};
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
/**
|
|
820
|
-
* HTML nodeType values that represent the type of the node
|
|
821
|
-
*/
|
|
822
|
-
var ELEMENT_NODE = 1;
|
|
823
|
-
|
|
824
|
-
// Do not use the below two methods directly!
|
|
825
|
-
// Instead use constants exported from DOMTopLevelEventTypes in ReactDOM.
|
|
826
|
-
// (It is the only module that is allowed to access these methods.)
|
|
827
|
-
function unsafeCastStringToDOMTopLevelType(topLevelType) {
|
|
828
|
-
return topLevelType;
|
|
829
|
-
}
|
|
672
|
+
/**
|
|
673
|
+
* Event names that have already been detected and prefixed (if applicable).
|
|
674
|
+
*/
|
|
830
675
|
|
|
831
|
-
var
|
|
676
|
+
var prefixedEventNames = {};
|
|
677
|
+
/**
|
|
678
|
+
* Element to check for prefixes on.
|
|
679
|
+
*/
|
|
832
680
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
* @param {string} eventName
|
|
838
|
-
* @returns {object}
|
|
839
|
-
*/
|
|
681
|
+
var style = {};
|
|
682
|
+
/**
|
|
683
|
+
* Bootstrap if a DOM exists.
|
|
684
|
+
*/
|
|
840
685
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
return prefixes;
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
* A list of event names to a configurable list of vendor prefixes.
|
|
850
|
-
*/
|
|
686
|
+
if (canUseDOM) {
|
|
687
|
+
style = document.createElement('div').style; // On some platforms, in particular some releases of Android 4.x,
|
|
688
|
+
// the un-prefixed "animation" and "transition" properties are defined on the
|
|
689
|
+
// style object but the events that fire will still be prefixed, so we need
|
|
690
|
+
// to check if the un-prefixed events are usable, and if not remove them from the map.
|
|
851
691
|
|
|
692
|
+
if (!('AnimationEvent' in window)) {
|
|
693
|
+
delete vendorPrefixes.animationend.animation;
|
|
694
|
+
delete vendorPrefixes.animationiteration.animation;
|
|
695
|
+
delete vendorPrefixes.animationstart.animation;
|
|
696
|
+
} // Same as above
|
|
852
697
|
|
|
853
|
-
var vendorPrefixes = {
|
|
854
|
-
animationend: makePrefixMap('Animation', 'AnimationEnd'),
|
|
855
|
-
animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
|
|
856
|
-
animationstart: makePrefixMap('Animation', 'AnimationStart'),
|
|
857
|
-
transitionend: makePrefixMap('Transition', 'TransitionEnd')
|
|
858
|
-
};
|
|
859
|
-
/**
|
|
860
|
-
* Event names that have already been detected and prefixed (if applicable).
|
|
861
|
-
*/
|
|
862
698
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
699
|
+
if (!('TransitionEvent' in window)) {
|
|
700
|
+
delete vendorPrefixes.transitionend.transition;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Attempts to determine the correct vendor prefixed event name.
|
|
705
|
+
*
|
|
706
|
+
* @param {string} eventName
|
|
707
|
+
* @returns {string}
|
|
708
|
+
*/
|
|
867
709
|
|
|
868
|
-
var style = {};
|
|
869
|
-
/**
|
|
870
|
-
* Bootstrap if a DOM exists.
|
|
871
|
-
*/
|
|
872
710
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
711
|
+
function getVendorPrefixedEventName(eventName) {
|
|
712
|
+
if (prefixedEventNames[eventName]) {
|
|
713
|
+
return prefixedEventNames[eventName];
|
|
714
|
+
} else if (!vendorPrefixes[eventName]) {
|
|
715
|
+
return eventName;
|
|
716
|
+
}
|
|
878
717
|
|
|
879
|
-
|
|
880
|
-
delete vendorPrefixes.animationend.animation;
|
|
881
|
-
delete vendorPrefixes.animationiteration.animation;
|
|
882
|
-
delete vendorPrefixes.animationstart.animation;
|
|
883
|
-
} // Same as above
|
|
718
|
+
var prefixMap = vendorPrefixes[eventName];
|
|
884
719
|
|
|
720
|
+
for (var styleProp in prefixMap) {
|
|
721
|
+
if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
|
|
722
|
+
return prefixedEventNames[eventName] = prefixMap[styleProp];
|
|
723
|
+
}
|
|
724
|
+
}
|
|
885
725
|
|
|
886
|
-
|
|
887
|
-
delete vendorPrefixes.transitionend.transition;
|
|
726
|
+
return eventName;
|
|
888
727
|
}
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Attempts to determine the correct vendor prefixed event name.
|
|
892
|
-
*
|
|
893
|
-
* @param {string} eventName
|
|
894
|
-
* @returns {string}
|
|
895
|
-
*/
|
|
896
728
|
|
|
729
|
+
/**
|
|
730
|
+
* To identify top level events in ReactDOM, we use constants defined by this
|
|
731
|
+
* module. This is the only module that uses the unsafe* methods to express
|
|
732
|
+
* that the constants actually correspond to the browser event names. This lets
|
|
733
|
+
* us save some bundle size by avoiding a top level type -> event name map.
|
|
734
|
+
* The rest of ReactDOM code should import top level types from this file.
|
|
735
|
+
*/
|
|
897
736
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
737
|
+
var TOP_ABORT = unsafeCastStringToDOMTopLevelType('abort');
|
|
738
|
+
var TOP_ANIMATION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationend'));
|
|
739
|
+
var TOP_ANIMATION_ITERATION = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationiteration'));
|
|
740
|
+
var TOP_ANIMATION_START = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('animationstart'));
|
|
741
|
+
var TOP_BLUR = unsafeCastStringToDOMTopLevelType('blur');
|
|
742
|
+
var TOP_CAN_PLAY = unsafeCastStringToDOMTopLevelType('canplay');
|
|
743
|
+
var TOP_CAN_PLAY_THROUGH = unsafeCastStringToDOMTopLevelType('canplaythrough');
|
|
744
|
+
var TOP_CANCEL = unsafeCastStringToDOMTopLevelType('cancel');
|
|
745
|
+
var TOP_CHANGE = unsafeCastStringToDOMTopLevelType('change');
|
|
746
|
+
var TOP_CLICK = unsafeCastStringToDOMTopLevelType('click');
|
|
747
|
+
var TOP_CLOSE = unsafeCastStringToDOMTopLevelType('close');
|
|
748
|
+
var TOP_COMPOSITION_END = unsafeCastStringToDOMTopLevelType('compositionend');
|
|
749
|
+
var TOP_COMPOSITION_START = unsafeCastStringToDOMTopLevelType('compositionstart');
|
|
750
|
+
var TOP_COMPOSITION_UPDATE = unsafeCastStringToDOMTopLevelType('compositionupdate');
|
|
751
|
+
var TOP_CONTEXT_MENU = unsafeCastStringToDOMTopLevelType('contextmenu');
|
|
752
|
+
var TOP_COPY = unsafeCastStringToDOMTopLevelType('copy');
|
|
753
|
+
var TOP_CUT = unsafeCastStringToDOMTopLevelType('cut');
|
|
754
|
+
var TOP_DOUBLE_CLICK = unsafeCastStringToDOMTopLevelType('dblclick');
|
|
755
|
+
var TOP_DRAG = unsafeCastStringToDOMTopLevelType('drag');
|
|
756
|
+
var TOP_DRAG_END = unsafeCastStringToDOMTopLevelType('dragend');
|
|
757
|
+
var TOP_DRAG_ENTER = unsafeCastStringToDOMTopLevelType('dragenter');
|
|
758
|
+
var TOP_DRAG_EXIT = unsafeCastStringToDOMTopLevelType('dragexit');
|
|
759
|
+
var TOP_DRAG_LEAVE = unsafeCastStringToDOMTopLevelType('dragleave');
|
|
760
|
+
var TOP_DRAG_OVER = unsafeCastStringToDOMTopLevelType('dragover');
|
|
761
|
+
var TOP_DRAG_START = unsafeCastStringToDOMTopLevelType('dragstart');
|
|
762
|
+
var TOP_DROP = unsafeCastStringToDOMTopLevelType('drop');
|
|
763
|
+
var TOP_DURATION_CHANGE = unsafeCastStringToDOMTopLevelType('durationchange');
|
|
764
|
+
var TOP_EMPTIED = unsafeCastStringToDOMTopLevelType('emptied');
|
|
765
|
+
var TOP_ENCRYPTED = unsafeCastStringToDOMTopLevelType('encrypted');
|
|
766
|
+
var TOP_ENDED = unsafeCastStringToDOMTopLevelType('ended');
|
|
767
|
+
var TOP_ERROR = unsafeCastStringToDOMTopLevelType('error');
|
|
768
|
+
var TOP_FOCUS = unsafeCastStringToDOMTopLevelType('focus');
|
|
769
|
+
var TOP_INPUT = unsafeCastStringToDOMTopLevelType('input');
|
|
770
|
+
var TOP_KEY_DOWN = unsafeCastStringToDOMTopLevelType('keydown');
|
|
771
|
+
var TOP_KEY_PRESS = unsafeCastStringToDOMTopLevelType('keypress');
|
|
772
|
+
var TOP_KEY_UP = unsafeCastStringToDOMTopLevelType('keyup');
|
|
773
|
+
var TOP_LOAD = unsafeCastStringToDOMTopLevelType('load');
|
|
774
|
+
var TOP_LOAD_START = unsafeCastStringToDOMTopLevelType('loadstart');
|
|
775
|
+
var TOP_LOADED_DATA = unsafeCastStringToDOMTopLevelType('loadeddata');
|
|
776
|
+
var TOP_LOADED_METADATA = unsafeCastStringToDOMTopLevelType('loadedmetadata');
|
|
777
|
+
var TOP_MOUSE_DOWN = unsafeCastStringToDOMTopLevelType('mousedown');
|
|
778
|
+
var TOP_MOUSE_MOVE = unsafeCastStringToDOMTopLevelType('mousemove');
|
|
779
|
+
var TOP_MOUSE_OUT = unsafeCastStringToDOMTopLevelType('mouseout');
|
|
780
|
+
var TOP_MOUSE_OVER = unsafeCastStringToDOMTopLevelType('mouseover');
|
|
781
|
+
var TOP_MOUSE_UP = unsafeCastStringToDOMTopLevelType('mouseup');
|
|
782
|
+
var TOP_PASTE = unsafeCastStringToDOMTopLevelType('paste');
|
|
783
|
+
var TOP_PAUSE = unsafeCastStringToDOMTopLevelType('pause');
|
|
784
|
+
var TOP_PLAY = unsafeCastStringToDOMTopLevelType('play');
|
|
785
|
+
var TOP_PLAYING = unsafeCastStringToDOMTopLevelType('playing');
|
|
786
|
+
var TOP_PROGRESS = unsafeCastStringToDOMTopLevelType('progress');
|
|
787
|
+
var TOP_RATE_CHANGE = unsafeCastStringToDOMTopLevelType('ratechange');
|
|
788
|
+
var TOP_SCROLL = unsafeCastStringToDOMTopLevelType('scroll');
|
|
789
|
+
var TOP_SEEKED = unsafeCastStringToDOMTopLevelType('seeked');
|
|
790
|
+
var TOP_SEEKING = unsafeCastStringToDOMTopLevelType('seeking');
|
|
791
|
+
var TOP_SELECTION_CHANGE = unsafeCastStringToDOMTopLevelType('selectionchange');
|
|
792
|
+
var TOP_STALLED = unsafeCastStringToDOMTopLevelType('stalled');
|
|
793
|
+
var TOP_SUSPEND = unsafeCastStringToDOMTopLevelType('suspend');
|
|
794
|
+
var TOP_TEXT_INPUT = unsafeCastStringToDOMTopLevelType('textInput');
|
|
795
|
+
var TOP_TIME_UPDATE = unsafeCastStringToDOMTopLevelType('timeupdate');
|
|
796
|
+
var TOP_TOGGLE = unsafeCastStringToDOMTopLevelType('toggle');
|
|
797
|
+
var TOP_TOUCH_CANCEL = unsafeCastStringToDOMTopLevelType('touchcancel');
|
|
798
|
+
var TOP_TOUCH_END = unsafeCastStringToDOMTopLevelType('touchend');
|
|
799
|
+
var TOP_TOUCH_MOVE = unsafeCastStringToDOMTopLevelType('touchmove');
|
|
800
|
+
var TOP_TOUCH_START = unsafeCastStringToDOMTopLevelType('touchstart');
|
|
801
|
+
var TOP_TRANSITION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('transitionend'));
|
|
802
|
+
var TOP_VOLUME_CHANGE = unsafeCastStringToDOMTopLevelType('volumechange');
|
|
803
|
+
var TOP_WAITING = unsafeCastStringToDOMTopLevelType('waiting');
|
|
804
|
+
var TOP_WHEEL = unsafeCastStringToDOMTopLevelType('wheel'); // List of events that need to be individually attached to media elements.
|
|
805
|
+
|
|
806
|
+
var PLUGIN_EVENT_SYSTEM = 1;
|
|
807
|
+
|
|
808
|
+
var didWarnAboutMessageChannel = false;
|
|
809
|
+
var enqueueTaskImpl = null;
|
|
810
|
+
function enqueueTask(task) {
|
|
811
|
+
if (enqueueTaskImpl === null) {
|
|
812
|
+
try {
|
|
813
|
+
// read require off the module object to get around the bundlers.
|
|
814
|
+
// we don't want them to detect a require and bundle a Node polyfill.
|
|
815
|
+
var requireString = ('require' + Math.random()).slice(0, 7);
|
|
816
|
+
var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
|
|
817
|
+
// version of setImmediate, bypassing fake timers if any.
|
|
818
|
+
|
|
819
|
+
enqueueTaskImpl = nodeRequire('timers').setImmediate;
|
|
820
|
+
} catch (_err) {
|
|
821
|
+
// we're in a browser
|
|
822
|
+
// we can't use regular timers because they may still be faked
|
|
823
|
+
// so we try MessageChannel+postMessage instead
|
|
824
|
+
enqueueTaskImpl = function (callback) {
|
|
825
|
+
{
|
|
826
|
+
if (didWarnAboutMessageChannel === false) {
|
|
827
|
+
didWarnAboutMessageChannel = true;
|
|
904
828
|
|
|
905
|
-
|
|
829
|
+
if (typeof MessageChannel === 'undefined') {
|
|
830
|
+
error('This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.');
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
906
834
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
835
|
+
var channel = new MessageChannel();
|
|
836
|
+
channel.port1.onmessage = callback;
|
|
837
|
+
channel.port2.postMessage(undefined);
|
|
838
|
+
};
|
|
839
|
+
}
|
|
910
840
|
}
|
|
841
|
+
|
|
842
|
+
return enqueueTaskImpl(task);
|
|
911
843
|
}
|
|
912
844
|
|
|
913
|
-
|
|
914
|
-
|
|
845
|
+
var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
846
|
+
var _ReactInternals$Sched = ReactInternals$1.Scheduler,
|
|
847
|
+
unstable_cancelCallback = _ReactInternals$Sched.unstable_cancelCallback,
|
|
848
|
+
unstable_now = _ReactInternals$Sched.unstable_now,
|
|
849
|
+
unstable_scheduleCallback = _ReactInternals$Sched.unstable_scheduleCallback,
|
|
850
|
+
unstable_shouldYield = _ReactInternals$Sched.unstable_shouldYield,
|
|
851
|
+
unstable_requestPaint = _ReactInternals$Sched.unstable_requestPaint,
|
|
852
|
+
unstable_getFirstCallbackNode = _ReactInternals$Sched.unstable_getFirstCallbackNode,
|
|
853
|
+
unstable_runWithPriority = _ReactInternals$Sched.unstable_runWithPriority,
|
|
854
|
+
unstable_next = _ReactInternals$Sched.unstable_next,
|
|
855
|
+
unstable_continueExecution = _ReactInternals$Sched.unstable_continueExecution,
|
|
856
|
+
unstable_pauseExecution = _ReactInternals$Sched.unstable_pauseExecution,
|
|
857
|
+
unstable_getCurrentPriorityLevel = _ReactInternals$Sched.unstable_getCurrentPriorityLevel,
|
|
858
|
+
unstable_ImmediatePriority = _ReactInternals$Sched.unstable_ImmediatePriority,
|
|
859
|
+
unstable_UserBlockingPriority = _ReactInternals$Sched.unstable_UserBlockingPriority,
|
|
860
|
+
unstable_NormalPriority = _ReactInternals$Sched.unstable_NormalPriority,
|
|
861
|
+
unstable_LowPriority = _ReactInternals$Sched.unstable_LowPriority,
|
|
862
|
+
unstable_IdlePriority = _ReactInternals$Sched.unstable_IdlePriority,
|
|
863
|
+
unstable_forceFrameRate = _ReactInternals$Sched.unstable_forceFrameRate,
|
|
864
|
+
unstable_flushAllWithoutAsserting = _ReactInternals$Sched.unstable_flushAllWithoutAsserting;
|
|
865
|
+
|
|
866
|
+
// ReactDOM.js, and ReactTestUtils.js:
|
|
867
|
+
|
|
868
|
+
var _ReactDOM$__SECRET_IN = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events,
|
|
869
|
+
|
|
870
|
+
/* eslint-disable no-unused-vars */
|
|
871
|
+
getInstanceFromNode = _ReactDOM$__SECRET_IN[0],
|
|
872
|
+
getNodeFromInstance = _ReactDOM$__SECRET_IN[1],
|
|
873
|
+
getFiberCurrentPropsFromNode = _ReactDOM$__SECRET_IN[2],
|
|
874
|
+
injectEventPluginsByName = _ReactDOM$__SECRET_IN[3],
|
|
875
|
+
eventNameDispatchConfigs = _ReactDOM$__SECRET_IN[4],
|
|
876
|
+
accumulateTwoPhaseDispatches = _ReactDOM$__SECRET_IN[5],
|
|
877
|
+
accumulateDirectDispatches = _ReactDOM$__SECRET_IN[6],
|
|
878
|
+
enqueueStateRestore = _ReactDOM$__SECRET_IN[7],
|
|
879
|
+
restoreStateIfNeeded = _ReactDOM$__SECRET_IN[8],
|
|
880
|
+
dispatchEvent = _ReactDOM$__SECRET_IN[9],
|
|
881
|
+
runEventsInBatch = _ReactDOM$__SECRET_IN[10],
|
|
882
|
+
|
|
883
|
+
/* eslint-enable no-unused-vars */
|
|
884
|
+
flushPassiveEffects = _ReactDOM$__SECRET_IN[11],
|
|
885
|
+
IsThisRendererActing = _ReactDOM$__SECRET_IN[12];
|
|
886
|
+
var batchedUpdates = ReactDOM.unstable_batchedUpdates;
|
|
887
|
+
var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
|
|
888
|
+
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js
|
|
889
|
+
|
|
890
|
+
var isSchedulerMocked = typeof unstable_flushAllWithoutAsserting === 'function';
|
|
891
|
+
|
|
892
|
+
var flushWork = unstable_flushAllWithoutAsserting || function () {
|
|
893
|
+
var didFlushWork = false;
|
|
894
|
+
|
|
895
|
+
while (flushPassiveEffects()) {
|
|
896
|
+
didFlushWork = true;
|
|
897
|
+
}
|
|
915
898
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
* module. This is the only module that uses the unsafe* methods to express
|
|
919
|
-
* that the constants actually correspond to the browser event names. This lets
|
|
920
|
-
* us save some bundle size by avoiding a top level type -> event name map.
|
|
921
|
-
* The rest of ReactDOM code should import top level types from this file.
|
|
922
|
-
*/
|
|
899
|
+
return didFlushWork;
|
|
900
|
+
};
|
|
923
901
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
var TOP_COMPOSITION_START = unsafeCastStringToDOMTopLevelType('compositionstart');
|
|
937
|
-
var TOP_COMPOSITION_UPDATE = unsafeCastStringToDOMTopLevelType('compositionupdate');
|
|
938
|
-
var TOP_CONTEXT_MENU = unsafeCastStringToDOMTopLevelType('contextmenu');
|
|
939
|
-
var TOP_COPY = unsafeCastStringToDOMTopLevelType('copy');
|
|
940
|
-
var TOP_CUT = unsafeCastStringToDOMTopLevelType('cut');
|
|
941
|
-
var TOP_DOUBLE_CLICK = unsafeCastStringToDOMTopLevelType('dblclick');
|
|
942
|
-
|
|
943
|
-
var TOP_DRAG = unsafeCastStringToDOMTopLevelType('drag');
|
|
944
|
-
var TOP_DRAG_END = unsafeCastStringToDOMTopLevelType('dragend');
|
|
945
|
-
var TOP_DRAG_ENTER = unsafeCastStringToDOMTopLevelType('dragenter');
|
|
946
|
-
var TOP_DRAG_EXIT = unsafeCastStringToDOMTopLevelType('dragexit');
|
|
947
|
-
var TOP_DRAG_LEAVE = unsafeCastStringToDOMTopLevelType('dragleave');
|
|
948
|
-
var TOP_DRAG_OVER = unsafeCastStringToDOMTopLevelType('dragover');
|
|
949
|
-
var TOP_DRAG_START = unsafeCastStringToDOMTopLevelType('dragstart');
|
|
950
|
-
var TOP_DROP = unsafeCastStringToDOMTopLevelType('drop');
|
|
951
|
-
var TOP_DURATION_CHANGE = unsafeCastStringToDOMTopLevelType('durationchange');
|
|
952
|
-
var TOP_EMPTIED = unsafeCastStringToDOMTopLevelType('emptied');
|
|
953
|
-
var TOP_ENCRYPTED = unsafeCastStringToDOMTopLevelType('encrypted');
|
|
954
|
-
var TOP_ENDED = unsafeCastStringToDOMTopLevelType('ended');
|
|
955
|
-
var TOP_ERROR = unsafeCastStringToDOMTopLevelType('error');
|
|
956
|
-
var TOP_FOCUS = unsafeCastStringToDOMTopLevelType('focus');
|
|
957
|
-
|
|
958
|
-
var TOP_INPUT = unsafeCastStringToDOMTopLevelType('input');
|
|
959
|
-
|
|
960
|
-
var TOP_KEY_DOWN = unsafeCastStringToDOMTopLevelType('keydown');
|
|
961
|
-
var TOP_KEY_PRESS = unsafeCastStringToDOMTopLevelType('keypress');
|
|
962
|
-
var TOP_KEY_UP = unsafeCastStringToDOMTopLevelType('keyup');
|
|
963
|
-
var TOP_LOAD = unsafeCastStringToDOMTopLevelType('load');
|
|
964
|
-
var TOP_LOAD_START = unsafeCastStringToDOMTopLevelType('loadstart');
|
|
965
|
-
var TOP_LOADED_DATA = unsafeCastStringToDOMTopLevelType('loadeddata');
|
|
966
|
-
var TOP_LOADED_METADATA = unsafeCastStringToDOMTopLevelType('loadedmetadata');
|
|
967
|
-
|
|
968
|
-
var TOP_MOUSE_DOWN = unsafeCastStringToDOMTopLevelType('mousedown');
|
|
969
|
-
var TOP_MOUSE_MOVE = unsafeCastStringToDOMTopLevelType('mousemove');
|
|
970
|
-
var TOP_MOUSE_OUT = unsafeCastStringToDOMTopLevelType('mouseout');
|
|
971
|
-
var TOP_MOUSE_OVER = unsafeCastStringToDOMTopLevelType('mouseover');
|
|
972
|
-
var TOP_MOUSE_UP = unsafeCastStringToDOMTopLevelType('mouseup');
|
|
973
|
-
var TOP_PASTE = unsafeCastStringToDOMTopLevelType('paste');
|
|
974
|
-
var TOP_PAUSE = unsafeCastStringToDOMTopLevelType('pause');
|
|
975
|
-
var TOP_PLAY = unsafeCastStringToDOMTopLevelType('play');
|
|
976
|
-
var TOP_PLAYING = unsafeCastStringToDOMTopLevelType('playing');
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
var TOP_PROGRESS = unsafeCastStringToDOMTopLevelType('progress');
|
|
986
|
-
var TOP_RATE_CHANGE = unsafeCastStringToDOMTopLevelType('ratechange');
|
|
987
|
-
|
|
988
|
-
var TOP_SCROLL = unsafeCastStringToDOMTopLevelType('scroll');
|
|
989
|
-
var TOP_SEEKED = unsafeCastStringToDOMTopLevelType('seeked');
|
|
990
|
-
var TOP_SEEKING = unsafeCastStringToDOMTopLevelType('seeking');
|
|
991
|
-
var TOP_SELECTION_CHANGE = unsafeCastStringToDOMTopLevelType('selectionchange');
|
|
992
|
-
var TOP_STALLED = unsafeCastStringToDOMTopLevelType('stalled');
|
|
993
|
-
|
|
994
|
-
var TOP_SUSPEND = unsafeCastStringToDOMTopLevelType('suspend');
|
|
995
|
-
var TOP_TEXT_INPUT = unsafeCastStringToDOMTopLevelType('textInput');
|
|
996
|
-
var TOP_TIME_UPDATE = unsafeCastStringToDOMTopLevelType('timeupdate');
|
|
997
|
-
var TOP_TOGGLE = unsafeCastStringToDOMTopLevelType('toggle');
|
|
998
|
-
var TOP_TOUCH_CANCEL = unsafeCastStringToDOMTopLevelType('touchcancel');
|
|
999
|
-
var TOP_TOUCH_END = unsafeCastStringToDOMTopLevelType('touchend');
|
|
1000
|
-
var TOP_TOUCH_MOVE = unsafeCastStringToDOMTopLevelType('touchmove');
|
|
1001
|
-
var TOP_TOUCH_START = unsafeCastStringToDOMTopLevelType('touchstart');
|
|
1002
|
-
var TOP_TRANSITION_END = unsafeCastStringToDOMTopLevelType(getVendorPrefixedEventName('transitionend'));
|
|
1003
|
-
var TOP_VOLUME_CHANGE = unsafeCastStringToDOMTopLevelType('volumechange');
|
|
1004
|
-
var TOP_WAITING = unsafeCastStringToDOMTopLevelType('waiting');
|
|
1005
|
-
var TOP_WHEEL = unsafeCastStringToDOMTopLevelType('wheel'); // List of events that need to be individually attached to media elements.
|
|
1006
|
-
// Note that events in this list will *not* be listened to at the top level
|
|
1007
|
-
// unless they're explicitly whitelisted in `ReactBrowserEventEmitter.listenTo`.
|
|
1008
|
-
|
|
1009
|
-
var PLUGIN_EVENT_SYSTEM = 1;
|
|
1010
|
-
|
|
1011
|
-
var didWarnAboutMessageChannel = false;
|
|
1012
|
-
var enqueueTask;
|
|
1013
|
-
|
|
1014
|
-
try {
|
|
1015
|
-
// read require off the module object to get around the bundlers.
|
|
1016
|
-
// we don't want them to detect a require and bundle a Node polyfill.
|
|
1017
|
-
var requireString = ('require' + Math.random()).slice(0, 7);
|
|
1018
|
-
var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
|
|
1019
|
-
// version of setImmediate, bypassing fake timers if any.
|
|
1020
|
-
|
|
1021
|
-
enqueueTask = nodeRequire('timers').setImmediate;
|
|
1022
|
-
} catch (_err) {
|
|
1023
|
-
// we're in a browser
|
|
1024
|
-
// we can't use regular timers because they may still be faked
|
|
1025
|
-
// so we try MessageChannel+postMessage instead
|
|
1026
|
-
enqueueTask = function (callback) {
|
|
1027
|
-
{
|
|
1028
|
-
if (didWarnAboutMessageChannel === false) {
|
|
1029
|
-
didWarnAboutMessageChannel = true;
|
|
1030
|
-
!(typeof MessageChannel !== 'undefined') ? warningWithoutStack$1(false, 'This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.') : void 0;
|
|
1031
|
-
}
|
|
902
|
+
function flushWorkAndMicroTasks(onDone) {
|
|
903
|
+
try {
|
|
904
|
+
flushWork();
|
|
905
|
+
enqueueTask(function () {
|
|
906
|
+
if (flushWork()) {
|
|
907
|
+
flushWorkAndMicroTasks(onDone);
|
|
908
|
+
} else {
|
|
909
|
+
onDone();
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
} catch (err) {
|
|
913
|
+
onDone(err);
|
|
1032
914
|
}
|
|
915
|
+
} // we track the 'depth' of the act() calls with this counter,
|
|
916
|
+
// so we can tell if any async act() calls try to run in parallel.
|
|
1033
917
|
|
|
1034
|
-
var channel = new MessageChannel();
|
|
1035
|
-
channel.port1.onmessage = callback;
|
|
1036
|
-
channel.port2.postMessage(undefined);
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
var enqueueTask$1 = enqueueTask;
|
|
1041
|
-
|
|
1042
|
-
var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
1043
|
-
var _ReactInternals$Sched = ReactInternals$1.Scheduler;
|
|
1044
|
-
var unstable_cancelCallback = _ReactInternals$Sched.unstable_cancelCallback;
|
|
1045
|
-
var unstable_now = _ReactInternals$Sched.unstable_now;
|
|
1046
|
-
var unstable_scheduleCallback = _ReactInternals$Sched.unstable_scheduleCallback;
|
|
1047
|
-
var unstable_shouldYield = _ReactInternals$Sched.unstable_shouldYield;
|
|
1048
|
-
var unstable_requestPaint = _ReactInternals$Sched.unstable_requestPaint;
|
|
1049
|
-
var unstable_getFirstCallbackNode = _ReactInternals$Sched.unstable_getFirstCallbackNode;
|
|
1050
|
-
var unstable_runWithPriority = _ReactInternals$Sched.unstable_runWithPriority;
|
|
1051
|
-
var unstable_next = _ReactInternals$Sched.unstable_next;
|
|
1052
|
-
var unstable_continueExecution = _ReactInternals$Sched.unstable_continueExecution;
|
|
1053
|
-
var unstable_pauseExecution = _ReactInternals$Sched.unstable_pauseExecution;
|
|
1054
|
-
var unstable_getCurrentPriorityLevel = _ReactInternals$Sched.unstable_getCurrentPriorityLevel;
|
|
1055
|
-
var unstable_ImmediatePriority = _ReactInternals$Sched.unstable_ImmediatePriority;
|
|
1056
|
-
var unstable_UserBlockingPriority = _ReactInternals$Sched.unstable_UserBlockingPriority;
|
|
1057
|
-
var unstable_NormalPriority = _ReactInternals$Sched.unstable_NormalPriority;
|
|
1058
|
-
var unstable_LowPriority = _ReactInternals$Sched.unstable_LowPriority;
|
|
1059
|
-
var unstable_IdlePriority = _ReactInternals$Sched.unstable_IdlePriority;
|
|
1060
|
-
var unstable_forceFrameRate = _ReactInternals$Sched.unstable_forceFrameRate;
|
|
1061
|
-
var unstable_flushAllWithoutAsserting = _ReactInternals$Sched.unstable_flushAllWithoutAsserting;
|
|
1062
|
-
|
|
1063
|
-
// ReactDOM.js, and ReactTestUtils.js:
|
|
1064
|
-
|
|
1065
|
-
var _ReactDOM$__SECRET_IN$1 = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
|
|
1066
|
-
var getInstanceFromNode$1 = _ReactDOM$__SECRET_IN$1[0];
|
|
1067
|
-
var getNodeFromInstance$1 = _ReactDOM$__SECRET_IN$1[1];
|
|
1068
|
-
var getFiberCurrentPropsFromNode$1 = _ReactDOM$__SECRET_IN$1[2];
|
|
1069
|
-
var injectEventPluginsByName$1 = _ReactDOM$__SECRET_IN$1[3];
|
|
1070
|
-
var eventNameDispatchConfigs$1 = _ReactDOM$__SECRET_IN$1[4];
|
|
1071
|
-
var accumulateTwoPhaseDispatches$1 = _ReactDOM$__SECRET_IN$1[5];
|
|
1072
|
-
var accumulateDirectDispatches$1 = _ReactDOM$__SECRET_IN$1[6];
|
|
1073
|
-
var enqueueStateRestore$1 = _ReactDOM$__SECRET_IN$1[7];
|
|
1074
|
-
var restoreStateIfNeeded$1 = _ReactDOM$__SECRET_IN$1[8];
|
|
1075
|
-
var dispatchEvent$1 = _ReactDOM$__SECRET_IN$1[9];
|
|
1076
|
-
var runEventsInBatch$1 = _ReactDOM$__SECRET_IN$1[10];
|
|
1077
|
-
var flushPassiveEffects$1 = _ReactDOM$__SECRET_IN$1[11];
|
|
1078
|
-
var IsThisRendererActing$1 = _ReactDOM$__SECRET_IN$1[12];
|
|
1079
|
-
var batchedUpdates = ReactDOM.unstable_batchedUpdates;
|
|
1080
|
-
var IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing; // this implementation should be exactly the same in
|
|
1081
|
-
// ReactTestUtilsAct.js, ReactTestRendererAct.js, createReactNoop.js
|
|
1082
|
-
|
|
1083
|
-
var isSchedulerMocked = typeof unstable_flushAllWithoutAsserting === 'function';
|
|
1084
|
-
|
|
1085
|
-
var flushWork = unstable_flushAllWithoutAsserting || function () {
|
|
1086
|
-
var didFlushWork = false;
|
|
1087
|
-
|
|
1088
|
-
while (flushPassiveEffects$1()) {
|
|
1089
|
-
didFlushWork = true;
|
|
1090
|
-
}
|
|
1091
918
|
|
|
1092
|
-
|
|
1093
|
-
};
|
|
919
|
+
var actingUpdatesScopeDepth = 0;
|
|
1094
920
|
|
|
1095
|
-
function
|
|
1096
|
-
try {
|
|
1097
|
-
flushWork();
|
|
1098
|
-
enqueueTask$1(function () {
|
|
1099
|
-
if (flushWork()) {
|
|
1100
|
-
flushWorkAndMicroTasks(onDone);
|
|
1101
|
-
} else {
|
|
1102
|
-
onDone();
|
|
1103
|
-
}
|
|
1104
|
-
});
|
|
1105
|
-
} catch (err) {
|
|
1106
|
-
onDone(err);
|
|
1107
|
-
}
|
|
1108
|
-
} // we track the 'depth' of the act() calls with this counter,
|
|
1109
|
-
// so we can tell if any async act() calls try to run in parallel.
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
var actingUpdatesScopeDepth = 0;
|
|
1113
|
-
function act(callback) {
|
|
1114
|
-
var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
|
1115
|
-
var previousIsSomeRendererActing;
|
|
1116
|
-
var previousIsThisRendererActing;
|
|
1117
|
-
actingUpdatesScopeDepth++;
|
|
1118
|
-
previousIsSomeRendererActing = IsSomeRendererActing.current;
|
|
1119
|
-
previousIsThisRendererActing = IsThisRendererActing$1.current;
|
|
1120
|
-
IsSomeRendererActing.current = true;
|
|
1121
|
-
IsThisRendererActing$1.current = true;
|
|
1122
|
-
|
|
1123
|
-
function onDone() {
|
|
1124
|
-
actingUpdatesScopeDepth--;
|
|
1125
|
-
IsSomeRendererActing.current = previousIsSomeRendererActing;
|
|
1126
|
-
IsThisRendererActing$1.current = previousIsThisRendererActing;
|
|
921
|
+
function act(callback) {
|
|
1127
922
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
923
|
+
var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
|
924
|
+
var previousIsSomeRendererActing;
|
|
925
|
+
var previousIsThisRendererActing;
|
|
926
|
+
actingUpdatesScopeDepth++;
|
|
927
|
+
previousIsSomeRendererActing = IsSomeRendererActing.current;
|
|
928
|
+
previousIsThisRendererActing = IsThisRendererActing.current;
|
|
929
|
+
IsSomeRendererActing.current = true;
|
|
930
|
+
IsThisRendererActing.current = true;
|
|
931
|
+
|
|
932
|
+
function onDone() {
|
|
933
|
+
actingUpdatesScopeDepth--;
|
|
934
|
+
IsSomeRendererActing.current = previousIsSomeRendererActing;
|
|
935
|
+
IsThisRendererActing.current = previousIsThisRendererActing;
|
|
936
|
+
|
|
937
|
+
{
|
|
938
|
+
if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) {
|
|
939
|
+
// if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned
|
|
940
|
+
error('You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
|
|
941
|
+
}
|
|
1132
942
|
}
|
|
1133
943
|
}
|
|
1134
|
-
}
|
|
1135
944
|
|
|
1136
|
-
|
|
945
|
+
var result;
|
|
1137
946
|
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
947
|
+
try {
|
|
948
|
+
result = batchedUpdates(callback);
|
|
949
|
+
} catch (error) {
|
|
950
|
+
// on sync errors, we still want to 'cleanup' and decrement actingUpdatesScopeDepth
|
|
951
|
+
onDone();
|
|
952
|
+
throw error;
|
|
953
|
+
}
|
|
1145
954
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
955
|
+
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
|
|
956
|
+
// setup a boolean that gets set to true only
|
|
957
|
+
// once this act() call is await-ed
|
|
958
|
+
var called = false;
|
|
1150
959
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
960
|
+
{
|
|
961
|
+
if (typeof Promise !== 'undefined') {
|
|
962
|
+
//eslint-disable-next-line no-undef
|
|
963
|
+
Promise.resolve().then(function () {}).then(function () {
|
|
964
|
+
if (called === false) {
|
|
965
|
+
error('You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);');
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
} // in the async case, the returned thenable runs the callback, flushes
|
|
970
|
+
// effects and microtasks in a loop until flushPassiveEffects() === false,
|
|
971
|
+
// and cleans up
|
|
1163
972
|
|
|
1164
973
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
974
|
+
return {
|
|
975
|
+
then: function (resolve, reject) {
|
|
976
|
+
called = true;
|
|
977
|
+
result.then(function () {
|
|
978
|
+
if (actingUpdatesScopeDepth > 1 || isSchedulerMocked === true && previousIsSomeRendererActing === true) {
|
|
979
|
+
onDone();
|
|
980
|
+
resolve();
|
|
981
|
+
return;
|
|
982
|
+
} // we're about to exit the act() scope,
|
|
983
|
+
// now's the time to flush tasks/effects
|
|
1175
984
|
|
|
1176
985
|
|
|
1177
|
-
|
|
1178
|
-
|
|
986
|
+
flushWorkAndMicroTasks(function (err) {
|
|
987
|
+
onDone();
|
|
1179
988
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
989
|
+
if (err) {
|
|
990
|
+
reject(err);
|
|
991
|
+
} else {
|
|
992
|
+
resolve();
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
}, function (err) {
|
|
996
|
+
onDone();
|
|
997
|
+
reject(err);
|
|
1185
998
|
});
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
!(result === undefined) ? warningWithoutStack$1(false, 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result) : void 0;
|
|
1195
|
-
} // flush effects until none remain, and cleanup
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
} else {
|
|
1002
|
+
{
|
|
1003
|
+
if (result !== undefined) {
|
|
1004
|
+
error('The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result);
|
|
1005
|
+
}
|
|
1006
|
+
} // flush effects until none remain, and cleanup
|
|
1196
1007
|
|
|
1197
1008
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1009
|
+
try {
|
|
1010
|
+
if (actingUpdatesScopeDepth === 1 && (isSchedulerMocked === false || previousIsSomeRendererActing === false)) {
|
|
1011
|
+
// we're about to exit the act() scope,
|
|
1012
|
+
// now's the time to flush effects
|
|
1013
|
+
flushWork();
|
|
1014
|
+
}
|
|
1204
1015
|
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1016
|
+
onDone();
|
|
1017
|
+
} catch (err) {
|
|
1018
|
+
onDone();
|
|
1019
|
+
throw err;
|
|
1020
|
+
} // in the sync case, the returned thenable only warns *if* await-ed
|
|
1210
1021
|
|
|
1211
1022
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1023
|
+
return {
|
|
1024
|
+
then: function (resolve) {
|
|
1025
|
+
{
|
|
1026
|
+
error('Do not await the result of calling act(...) with sync logic, it is not a Promise.');
|
|
1027
|
+
}
|
|
1217
1028
|
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1029
|
+
resolve();
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1221
1033
|
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
var findDOMNode = ReactDOM.findDOMNode; // Keep in sync with ReactDOMUnstableNativeDependencies.js
|
|
1225
|
-
// ReactDOM.js, and ReactTestUtilsAct.js:
|
|
1226
|
-
|
|
1227
|
-
var _ReactDOM$__SECRET_IN = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
|
|
1228
|
-
var getInstanceFromNode = _ReactDOM$__SECRET_IN[0];
|
|
1229
|
-
var getNodeFromInstance = _ReactDOM$__SECRET_IN[1];
|
|
1230
|
-
var getFiberCurrentPropsFromNode = _ReactDOM$__SECRET_IN[2];
|
|
1231
|
-
var injectEventPluginsByName = _ReactDOM$__SECRET_IN[3];
|
|
1232
|
-
var eventNameDispatchConfigs = _ReactDOM$__SECRET_IN[4];
|
|
1233
|
-
var accumulateTwoPhaseDispatches = _ReactDOM$__SECRET_IN[5];
|
|
1234
|
-
var accumulateDirectDispatches = _ReactDOM$__SECRET_IN[6];
|
|
1235
|
-
var enqueueStateRestore = _ReactDOM$__SECRET_IN[7];
|
|
1236
|
-
var restoreStateIfNeeded = _ReactDOM$__SECRET_IN[8];
|
|
1237
|
-
var dispatchEvent = _ReactDOM$__SECRET_IN[9];
|
|
1238
|
-
var runEventsInBatch = _ReactDOM$__SECRET_IN[10];
|
|
1239
|
-
var flushPassiveEffects = _ReactDOM$__SECRET_IN[11];
|
|
1240
|
-
var IsThisRendererActing = _ReactDOM$__SECRET_IN[12];
|
|
1241
|
-
|
|
1242
|
-
function Event(suffix) {}
|
|
1243
|
-
|
|
1244
|
-
var hasWarnedAboutDeprecatedMockComponent = false;
|
|
1245
|
-
/**
|
|
1246
|
-
* @class ReactTestUtils
|
|
1247
|
-
*/
|
|
1248
1034
|
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
* on an `Element` node.
|
|
1252
|
-
* @param {number} topLevelType A number from `TopLevelEventTypes`
|
|
1253
|
-
* @param {!Element} node The dom to simulate an event occurring on.
|
|
1254
|
-
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
1255
|
-
*/
|
|
1035
|
+
var findDOMNode = ReactDOM.findDOMNode; // Keep in sync with ReactDOMUnstableNativeDependencies.js
|
|
1036
|
+
// ReactDOM.js, and ReactTestUtilsAct.js:
|
|
1256
1037
|
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
dispatchEvent(topLevelType, PLUGIN_EVENT_SYSTEM, fakeNativeEvent);
|
|
1260
|
-
}
|
|
1261
|
-
/**
|
|
1262
|
-
* Simulates a top level event being dispatched from a raw event that occurred
|
|
1263
|
-
* on the `ReactDOMComponent` `comp`.
|
|
1264
|
-
* @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`.
|
|
1265
|
-
* @param {!ReactDOMComponent} comp
|
|
1266
|
-
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
1267
|
-
*/
|
|
1038
|
+
var _ReactDOM$__SECRET_IN$1 = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events,
|
|
1039
|
+
getInstanceFromNode$1 = _ReactDOM$__SECRET_IN$1[0],
|
|
1268
1040
|
|
|
1041
|
+
/* eslint-disable no-unused-vars */
|
|
1042
|
+
getNodeFromInstance$1 = _ReactDOM$__SECRET_IN$1[1],
|
|
1043
|
+
getFiberCurrentPropsFromNode$1 = _ReactDOM$__SECRET_IN$1[2],
|
|
1044
|
+
injectEventPluginsByName$1 = _ReactDOM$__SECRET_IN$1[3],
|
|
1269
1045
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1046
|
+
/* eslint-enable no-unused-vars */
|
|
1047
|
+
eventNameDispatchConfigs$1 = _ReactDOM$__SECRET_IN$1[4],
|
|
1048
|
+
accumulateTwoPhaseDispatches$1 = _ReactDOM$__SECRET_IN$1[5],
|
|
1049
|
+
accumulateDirectDispatches$1 = _ReactDOM$__SECRET_IN$1[6],
|
|
1050
|
+
enqueueStateRestore$1 = _ReactDOM$__SECRET_IN$1[7],
|
|
1051
|
+
restoreStateIfNeeded$1 = _ReactDOM$__SECRET_IN$1[8],
|
|
1052
|
+
dispatchEvent$1 = _ReactDOM$__SECRET_IN$1[9],
|
|
1053
|
+
runEventsInBatch$1 = _ReactDOM$__SECRET_IN$1[10],
|
|
1273
1054
|
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1055
|
+
/* eslint-disable no-unused-vars */
|
|
1056
|
+
flushPassiveEffects$1 = _ReactDOM$__SECRET_IN$1[11],
|
|
1057
|
+
IsThisRendererActing$1
|
|
1058
|
+
/* eslint-enable no-unused-vars */
|
|
1059
|
+
= _ReactDOM$__SECRET_IN$1[12];
|
|
1278
1060
|
|
|
1279
|
-
|
|
1061
|
+
function Event(suffix) {}
|
|
1280
1062
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1063
|
+
var hasWarnedAboutDeprecatedMockComponent = false;
|
|
1064
|
+
/**
|
|
1065
|
+
* @class ReactTestUtils
|
|
1066
|
+
*/
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Simulates a top level event being dispatched from a raw event that occurred
|
|
1070
|
+
* on an `Element` node.
|
|
1071
|
+
* @param {number} topLevelType A number from `TopLevelEventTypes`
|
|
1072
|
+
* @param {!Element} node The dom to simulate an event occurring on.
|
|
1073
|
+
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
1074
|
+
*/
|
|
1075
|
+
|
|
1076
|
+
function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
|
|
1077
|
+
fakeNativeEvent.target = node;
|
|
1078
|
+
dispatchEvent$1(topLevelType, PLUGIN_EVENT_SYSTEM, document, fakeNativeEvent);
|
|
1283
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Simulates a top level event being dispatched from a raw event that occurred
|
|
1082
|
+
* on the `ReactDOMComponent` `comp`.
|
|
1083
|
+
* @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`.
|
|
1084
|
+
* @param {!ReactDOMComponent} comp
|
|
1085
|
+
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
1086
|
+
*/
|
|
1284
1087
|
|
|
1285
|
-
var node = currentParent;
|
|
1286
|
-
var ret = [];
|
|
1287
1088
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1089
|
+
function simulateNativeEventOnDOMComponent(topLevelType, comp, fakeNativeEvent) {
|
|
1090
|
+
simulateNativeEventOnNode(topLevelType, findDOMNode(comp), fakeNativeEvent);
|
|
1091
|
+
}
|
|
1291
1092
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1093
|
+
function findAllInRenderedFiberTreeInternal(fiber, test) {
|
|
1094
|
+
if (!fiber) {
|
|
1095
|
+
return [];
|
|
1295
1096
|
}
|
|
1296
1097
|
|
|
1297
|
-
|
|
1298
|
-
node.child.return = node;
|
|
1299
|
-
node = node.child;
|
|
1300
|
-
continue;
|
|
1301
|
-
}
|
|
1098
|
+
var currentParent = findCurrentFiberUsingSlowPath(fiber);
|
|
1302
1099
|
|
|
1303
|
-
if (
|
|
1304
|
-
return
|
|
1100
|
+
if (!currentParent) {
|
|
1101
|
+
return [];
|
|
1305
1102
|
}
|
|
1306
1103
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
return ret;
|
|
1310
|
-
}
|
|
1104
|
+
var node = currentParent;
|
|
1105
|
+
var ret = [];
|
|
1311
1106
|
|
|
1312
|
-
|
|
1313
|
-
|
|
1107
|
+
while (true) {
|
|
1108
|
+
if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionComponent) {
|
|
1109
|
+
var publicInst = node.stateNode;
|
|
1314
1110
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1111
|
+
if (test(publicInst)) {
|
|
1112
|
+
ret.push(publicInst);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1319
1115
|
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1116
|
+
if (node.child) {
|
|
1117
|
+
node.child.return = node;
|
|
1118
|
+
node = node.child;
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1325
1121
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
}
|
|
1122
|
+
if (node === currentParent) {
|
|
1123
|
+
return ret;
|
|
1124
|
+
}
|
|
1330
1125
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
received = 'an array';
|
|
1336
|
-
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
|
1337
|
-
received = 'a DOM node';
|
|
1338
|
-
} else if (stringified === '[object Object]') {
|
|
1339
|
-
received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
|
|
1340
|
-
} else {
|
|
1341
|
-
received = stringified;
|
|
1342
|
-
}
|
|
1126
|
+
while (!node.sibling) {
|
|
1127
|
+
if (!node.return || node.return === currentParent) {
|
|
1128
|
+
return ret;
|
|
1129
|
+
}
|
|
1343
1130
|
|
|
1344
|
-
|
|
1345
|
-
{
|
|
1346
|
-
{
|
|
1347
|
-
throw ReactError(Error(methodName + "(...): the first argument must be a React class instance. Instead received: " + received + "."));
|
|
1131
|
+
node = node.return;
|
|
1348
1132
|
}
|
|
1349
|
-
}
|
|
1350
|
-
})();
|
|
1351
|
-
}
|
|
1352
|
-
/**
|
|
1353
|
-
* Utilities for making it easy to test React components.
|
|
1354
|
-
*
|
|
1355
|
-
* See https://reactjs.org/docs/test-utils.html
|
|
1356
|
-
*
|
|
1357
|
-
* Todo: Support the entire DOM.scry query syntax. For now, these simple
|
|
1358
|
-
* utilities will suffice for testing purposes.
|
|
1359
|
-
* @lends ReactTestUtils
|
|
1360
|
-
*/
|
|
1361
1133
|
|
|
1134
|
+
node.sibling.return = node.return;
|
|
1135
|
+
node = node.sibling;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1362
1138
|
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
// clean up, so we're going to stop honoring the name of this method
|
|
1368
|
-
// (and probably rename it eventually) if no problems arise.
|
|
1369
|
-
// document.documentElement.appendChild(div);
|
|
1370
|
-
|
|
1371
|
-
return ReactDOM.render(element, div);
|
|
1372
|
-
},
|
|
1373
|
-
isElement: function (element) {
|
|
1374
|
-
return React.isValidElement(element);
|
|
1375
|
-
},
|
|
1376
|
-
isElementOfType: function (inst, convenienceConstructor) {
|
|
1377
|
-
return React.isValidElement(inst) && inst.type === convenienceConstructor;
|
|
1378
|
-
},
|
|
1379
|
-
isDOMComponent: function (inst) {
|
|
1380
|
-
return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
|
|
1381
|
-
},
|
|
1382
|
-
isDOMComponentElement: function (inst) {
|
|
1383
|
-
return !!(inst && React.isValidElement(inst) && !!inst.tagName);
|
|
1384
|
-
},
|
|
1385
|
-
isCompositeComponent: function (inst) {
|
|
1386
|
-
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
1387
|
-
// Accessing inst.setState warns; just return false as that'll be what
|
|
1388
|
-
// this returns when we have DOM nodes as refs directly
|
|
1389
|
-
return false;
|
|
1139
|
+
function validateClassInstance(inst, methodName) {
|
|
1140
|
+
if (!inst) {
|
|
1141
|
+
// This is probably too relaxed but it's existing behavior.
|
|
1142
|
+
return;
|
|
1390
1143
|
}
|
|
1391
1144
|
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
if (!ReactTestUtils.isCompositeComponent(inst)) {
|
|
1396
|
-
return false;
|
|
1145
|
+
if (get(inst)) {
|
|
1146
|
+
// This is a public instance indeed.
|
|
1147
|
+
return;
|
|
1397
1148
|
}
|
|
1398
1149
|
|
|
1399
|
-
var
|
|
1400
|
-
var
|
|
1401
|
-
return constructor === type;
|
|
1402
|
-
},
|
|
1403
|
-
findAllInRenderedTree: function (inst, test) {
|
|
1404
|
-
validateClassInstance(inst, 'findAllInRenderedTree');
|
|
1150
|
+
var received;
|
|
1151
|
+
var stringified = '' + inst;
|
|
1405
1152
|
|
|
1406
|
-
if (
|
|
1407
|
-
|
|
1153
|
+
if (Array.isArray(inst)) {
|
|
1154
|
+
received = 'an array';
|
|
1155
|
+
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
|
1156
|
+
received = 'a DOM node';
|
|
1157
|
+
} else if (stringified === '[object Object]') {
|
|
1158
|
+
received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
|
|
1159
|
+
} else {
|
|
1160
|
+
received = stringified;
|
|
1408
1161
|
}
|
|
1409
1162
|
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1163
|
+
{
|
|
1164
|
+
{
|
|
1165
|
+
throw Error( methodName + "(...): the first argument must be a React class instance. Instead received: " + received + "." );
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1414
1169
|
/**
|
|
1415
|
-
*
|
|
1416
|
-
*
|
|
1417
|
-
*
|
|
1170
|
+
* Utilities for making it easy to test React components.
|
|
1171
|
+
*
|
|
1172
|
+
* See https://reactjs.org/docs/test-utils.html
|
|
1173
|
+
*
|
|
1174
|
+
* Todo: Support the entire DOM.scry query syntax. For now, these simple
|
|
1175
|
+
* utilities will suffice for testing purposes.
|
|
1176
|
+
* @lends ReactTestUtils
|
|
1418
1177
|
*/
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
var ReactTestUtils = {
|
|
1181
|
+
renderIntoDocument: function (element) {
|
|
1182
|
+
var div = document.createElement('div'); // None of our tests actually require attaching the container to the
|
|
1183
|
+
// DOM, and doing so creates a mess that we rely on test isolation to
|
|
1184
|
+
// clean up, so we're going to stop honoring the name of this method
|
|
1185
|
+
// (and probably rename it eventually) if no problems arise.
|
|
1186
|
+
// document.documentElement.appendChild(div);
|
|
1187
|
+
|
|
1188
|
+
return ReactDOM.render(element, div);
|
|
1189
|
+
},
|
|
1190
|
+
isElement: function (element) {
|
|
1191
|
+
return React.isValidElement(element);
|
|
1192
|
+
},
|
|
1193
|
+
isElementOfType: function (inst, convenienceConstructor) {
|
|
1194
|
+
return React.isValidElement(inst) && inst.type === convenienceConstructor;
|
|
1195
|
+
},
|
|
1196
|
+
isDOMComponent: function (inst) {
|
|
1197
|
+
return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
|
|
1198
|
+
},
|
|
1199
|
+
isDOMComponentElement: function (inst) {
|
|
1200
|
+
return !!(inst && React.isValidElement(inst) && !!inst.tagName);
|
|
1201
|
+
},
|
|
1202
|
+
isCompositeComponent: function (inst) {
|
|
1422
1203
|
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
1423
|
-
|
|
1204
|
+
// Accessing inst.setState warns; just return false as that'll be what
|
|
1205
|
+
// this returns when we have DOM nodes as refs directly
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1424
1208
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1209
|
+
return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
|
|
1210
|
+
},
|
|
1211
|
+
isCompositeComponentWithType: function (inst, type) {
|
|
1212
|
+
if (!ReactTestUtils.isCompositeComponent(inst)) {
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
var internalInstance = get(inst);
|
|
1217
|
+
var constructor = internalInstance.type;
|
|
1218
|
+
return constructor === type;
|
|
1219
|
+
},
|
|
1220
|
+
findAllInRenderedTree: function (inst, test) {
|
|
1221
|
+
validateClassInstance(inst, 'findAllInRenderedTree');
|
|
1222
|
+
|
|
1223
|
+
if (!inst) {
|
|
1224
|
+
return [];
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
var internalInstance = get(inst);
|
|
1228
|
+
return findAllInRenderedFiberTreeInternal(internalInstance, test);
|
|
1229
|
+
},
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Finds all instance of components in the rendered tree that are DOM
|
|
1233
|
+
* components with the class name matching `className`.
|
|
1234
|
+
* @return {array} an array of all the matches.
|
|
1235
|
+
*/
|
|
1236
|
+
scryRenderedDOMComponentsWithClass: function (root, classNames) {
|
|
1237
|
+
validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
|
|
1238
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
1239
|
+
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
1240
|
+
var className = inst.className;
|
|
1241
|
+
|
|
1242
|
+
if (typeof className !== 'string') {
|
|
1243
|
+
// SVG, probably.
|
|
1244
|
+
className = inst.getAttribute('class') || '';
|
|
1245
|
+
}
|
|
1429
1246
|
|
|
1430
|
-
|
|
1247
|
+
var classList = className.split(/\s+/);
|
|
1431
1248
|
|
|
1432
|
-
|
|
1433
|
-
(function () {
|
|
1249
|
+
if (!Array.isArray(classNames)) {
|
|
1434
1250
|
if (!(classNames !== undefined)) {
|
|
1435
1251
|
{
|
|
1436
|
-
throw
|
|
1252
|
+
throw Error( "TestUtils.scryRenderedDOMComponentsWithClass expects a className as a second argument." );
|
|
1437
1253
|
}
|
|
1438
1254
|
}
|
|
1439
|
-
})();
|
|
1440
1255
|
|
|
1441
|
-
|
|
1256
|
+
classNames = classNames.split(/\s+/);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
return classNames.every(function (name) {
|
|
1260
|
+
return classList.indexOf(name) !== -1;
|
|
1261
|
+
});
|
|
1442
1262
|
}
|
|
1443
1263
|
|
|
1444
|
-
return
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
}
|
|
1264
|
+
return false;
|
|
1265
|
+
});
|
|
1266
|
+
},
|
|
1448
1267
|
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1268
|
+
/**
|
|
1269
|
+
* Like scryRenderedDOMComponentsWithClass but expects there to be one result,
|
|
1270
|
+
* and returns that one result, or throws exception if there is any other
|
|
1271
|
+
* number of matches besides one.
|
|
1272
|
+
* @return {!ReactDOMComponent} The one match.
|
|
1273
|
+
*/
|
|
1274
|
+
findRenderedDOMComponentWithClass: function (root, className) {
|
|
1275
|
+
validateClassInstance(root, 'findRenderedDOMComponentWithClass');
|
|
1276
|
+
var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
1452
1277
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
* number of matches besides one.
|
|
1457
|
-
* @return {!ReactDOMComponent} The one match.
|
|
1458
|
-
*/
|
|
1459
|
-
findRenderedDOMComponentWithClass: function (root, className) {
|
|
1460
|
-
validateClassInstance(root, 'findRenderedDOMComponentWithClass');
|
|
1461
|
-
var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
1278
|
+
if (all.length !== 1) {
|
|
1279
|
+
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
|
|
1280
|
+
}
|
|
1462
1281
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
}
|
|
1282
|
+
return all[0];
|
|
1283
|
+
},
|
|
1466
1284
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1285
|
+
/**
|
|
1286
|
+
* Finds all instance of components in the rendered tree that are DOM
|
|
1287
|
+
* components with the tag name matching `tagName`.
|
|
1288
|
+
* @return {array} an array of all the matches.
|
|
1289
|
+
*/
|
|
1290
|
+
scryRenderedDOMComponentsWithTag: function (root, tagName) {
|
|
1291
|
+
validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
|
|
1292
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
1293
|
+
return ReactTestUtils.isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
|
|
1294
|
+
});
|
|
1295
|
+
},
|
|
1469
1296
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
});
|
|
1480
|
-
},
|
|
1297
|
+
/**
|
|
1298
|
+
* Like scryRenderedDOMComponentsWithTag but expects there to be one result,
|
|
1299
|
+
* and returns that one result, or throws exception if there is any other
|
|
1300
|
+
* number of matches besides one.
|
|
1301
|
+
* @return {!ReactDOMComponent} The one match.
|
|
1302
|
+
*/
|
|
1303
|
+
findRenderedDOMComponentWithTag: function (root, tagName) {
|
|
1304
|
+
validateClassInstance(root, 'findRenderedDOMComponentWithTag');
|
|
1305
|
+
var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
|
|
1481
1306
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
* number of matches besides one.
|
|
1486
|
-
* @return {!ReactDOMComponent} The one match.
|
|
1487
|
-
*/
|
|
1488
|
-
findRenderedDOMComponentWithTag: function (root, tagName) {
|
|
1489
|
-
validateClassInstance(root, 'findRenderedDOMComponentWithTag');
|
|
1490
|
-
var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
|
|
1307
|
+
if (all.length !== 1) {
|
|
1308
|
+
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
|
|
1309
|
+
}
|
|
1491
1310
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1311
|
+
return all[0];
|
|
1312
|
+
},
|
|
1495
1313
|
|
|
1496
|
-
|
|
1497
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* Finds all instances of components with type equal to `componentType`.
|
|
1316
|
+
* @return {array} an array of all the matches.
|
|
1317
|
+
*/
|
|
1318
|
+
scryRenderedComponentsWithType: function (root, componentType) {
|
|
1319
|
+
validateClassInstance(root, 'scryRenderedComponentsWithType');
|
|
1320
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
1321
|
+
return ReactTestUtils.isCompositeComponentWithType(inst, componentType);
|
|
1322
|
+
});
|
|
1323
|
+
},
|
|
1498
1324
|
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
},
|
|
1325
|
+
/**
|
|
1326
|
+
* Same as `scryRenderedComponentsWithType` but expects there to be one result
|
|
1327
|
+
* and returns that one result, or throws exception if there is any other
|
|
1328
|
+
* number of matches besides one.
|
|
1329
|
+
* @return {!ReactComponent} The one match.
|
|
1330
|
+
*/
|
|
1331
|
+
findRenderedComponentWithType: function (root, componentType) {
|
|
1332
|
+
validateClassInstance(root, 'findRenderedComponentWithType');
|
|
1333
|
+
var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
|
1509
1334
|
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
* number of matches besides one.
|
|
1514
|
-
* @return {!ReactComponent} The one match.
|
|
1515
|
-
*/
|
|
1516
|
-
findRenderedComponentWithType: function (root, componentType) {
|
|
1517
|
-
validateClassInstance(root, 'findRenderedComponentWithType');
|
|
1518
|
-
var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
|
1335
|
+
if (all.length !== 1) {
|
|
1336
|
+
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
|
|
1337
|
+
}
|
|
1519
1338
|
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1339
|
+
return all[0];
|
|
1340
|
+
},
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* Pass a mocked component module to this method to augment it with
|
|
1344
|
+
* useful methods that allow it to be used as a dummy React component.
|
|
1345
|
+
* Instead of rendering as usual, the component will become a simple
|
|
1346
|
+
* <div> containing any provided children.
|
|
1347
|
+
*
|
|
1348
|
+
* @param {object} module the mock function object exported from a
|
|
1349
|
+
* module that defines the component to be mocked
|
|
1350
|
+
* @param {?string} mockTagName optional dummy root tag name to return
|
|
1351
|
+
* from render method (overrides
|
|
1352
|
+
* module.mockTagName if provided)
|
|
1353
|
+
* @return {object} the ReactTestUtils object (for chaining)
|
|
1354
|
+
*/
|
|
1355
|
+
mockComponent: function (module, mockTagName) {
|
|
1356
|
+
{
|
|
1357
|
+
if (!hasWarnedAboutDeprecatedMockComponent) {
|
|
1358
|
+
hasWarnedAboutDeprecatedMockComponent = true;
|
|
1523
1359
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1360
|
+
warn('ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://fb.me/test-utils-mock-component for more information.');
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1526
1363
|
|
|
1364
|
+
mockTagName = mockTagName || module.mockTagName || 'div';
|
|
1365
|
+
module.prototype.render.mockImplementation(function () {
|
|
1366
|
+
return React.createElement(mockTagName, null, this.props.children);
|
|
1367
|
+
});
|
|
1368
|
+
return this;
|
|
1369
|
+
},
|
|
1370
|
+
nativeTouchData: function (x, y) {
|
|
1371
|
+
return {
|
|
1372
|
+
touches: [{
|
|
1373
|
+
pageX: x,
|
|
1374
|
+
pageY: y
|
|
1375
|
+
}]
|
|
1376
|
+
};
|
|
1377
|
+
},
|
|
1378
|
+
Simulate: null,
|
|
1379
|
+
SimulateNative: {},
|
|
1380
|
+
act: act
|
|
1381
|
+
};
|
|
1527
1382
|
/**
|
|
1528
|
-
*
|
|
1529
|
-
* useful methods that allow it to be used as a dummy React component.
|
|
1530
|
-
* Instead of rendering as usual, the component will become a simple
|
|
1531
|
-
* <div> containing any provided children.
|
|
1383
|
+
* Exports:
|
|
1532
1384
|
*
|
|
1533
|
-
*
|
|
1534
|
-
*
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
* module.mockTagName if provided)
|
|
1538
|
-
* @return {object} the ReactTestUtils object (for chaining)
|
|
1385
|
+
* - `ReactTestUtils.Simulate.click(Element)`
|
|
1386
|
+
* - `ReactTestUtils.Simulate.mouseMove(Element)`
|
|
1387
|
+
* - `ReactTestUtils.Simulate.change(Element)`
|
|
1388
|
+
* - ... (All keys from event plugin `eventTypes` objects)
|
|
1539
1389
|
*/
|
|
1540
|
-
mockComponent: function (module, mockTagName) {
|
|
1541
|
-
if (!hasWarnedAboutDeprecatedMockComponent) {
|
|
1542
|
-
hasWarnedAboutDeprecatedMockComponent = true;
|
|
1543
|
-
lowPriorityWarningWithoutStack$1(false, 'ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://fb.me/test-utils-mock-component for more information.');
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
mockTagName = mockTagName || module.mockTagName || 'div';
|
|
1547
|
-
module.prototype.render.mockImplementation(function () {
|
|
1548
|
-
return React.createElement(mockTagName, null, this.props.children);
|
|
1549
|
-
});
|
|
1550
|
-
return this;
|
|
1551
|
-
},
|
|
1552
|
-
nativeTouchData: function (x, y) {
|
|
1553
|
-
return {
|
|
1554
|
-
touches: [{
|
|
1555
|
-
pageX: x,
|
|
1556
|
-
pageY: y
|
|
1557
|
-
}]
|
|
1558
|
-
};
|
|
1559
|
-
},
|
|
1560
|
-
Simulate: null,
|
|
1561
|
-
SimulateNative: {},
|
|
1562
|
-
act: act
|
|
1563
|
-
};
|
|
1564
|
-
/**
|
|
1565
|
-
* Exports:
|
|
1566
|
-
*
|
|
1567
|
-
* - `ReactTestUtils.Simulate.click(Element)`
|
|
1568
|
-
* - `ReactTestUtils.Simulate.mouseMove(Element)`
|
|
1569
|
-
* - `ReactTestUtils.Simulate.change(Element)`
|
|
1570
|
-
* - ... (All keys from event plugin `eventTypes` objects)
|
|
1571
|
-
*/
|
|
1572
1390
|
|
|
1573
|
-
function makeSimulator(eventType) {
|
|
1574
|
-
|
|
1575
|
-
(function () {
|
|
1391
|
+
function makeSimulator(eventType) {
|
|
1392
|
+
return function (domNode, eventData) {
|
|
1576
1393
|
if (!!React.isValidElement(domNode)) {
|
|
1577
1394
|
{
|
|
1578
|
-
throw
|
|
1395
|
+
throw Error( "TestUtils.Simulate expected a DOM node as the first argument but received a React element. Pass the DOM node you wish to simulate the event on instead. Note that TestUtils.Simulate will not work if you are using shallow rendering." );
|
|
1579
1396
|
}
|
|
1580
1397
|
}
|
|
1581
|
-
})();
|
|
1582
1398
|
|
|
1583
|
-
(function () {
|
|
1584
1399
|
if (!!ReactTestUtils.isCompositeComponent(domNode)) {
|
|
1585
1400
|
{
|
|
1586
|
-
throw
|
|
1401
|
+
throw Error( "TestUtils.Simulate expected a DOM node as the first argument but received a component instance. Pass the DOM node you wish to simulate the event on instead." );
|
|
1587
1402
|
}
|
|
1588
1403
|
}
|
|
1589
|
-
})();
|
|
1590
|
-
|
|
1591
|
-
var dispatchConfig = eventNameDispatchConfigs[eventType];
|
|
1592
|
-
var fakeNativeEvent = new Event();
|
|
1593
|
-
fakeNativeEvent.target = domNode;
|
|
1594
|
-
fakeNativeEvent.type = eventType.toLowerCase(); // We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
1595
|
-
// properly destroying any properties assigned from `eventData` upon release
|
|
1596
1404
|
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1405
|
+
var dispatchConfig = eventNameDispatchConfigs$1[eventType];
|
|
1406
|
+
var fakeNativeEvent = new Event();
|
|
1407
|
+
fakeNativeEvent.target = domNode;
|
|
1408
|
+
fakeNativeEvent.type = eventType.toLowerCase(); // We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
1409
|
+
// properly destroying any properties assigned from `eventData` upon release
|
|
1600
1410
|
|
|
1601
|
-
|
|
1411
|
+
var targetInst = getInstanceFromNode$1(domNode);
|
|
1412
|
+
var event = new SyntheticEvent(dispatchConfig, targetInst, fakeNativeEvent, domNode); // Since we aren't using pooling, always persist the event. This will make
|
|
1413
|
+
// sure it's marked and won't warn when setting additional properties.
|
|
1602
1414
|
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
if (dispatchConfig.phasedRegistrationNames) {
|
|
1606
|
-
accumulateTwoPhaseDispatches(event);
|
|
1607
|
-
} else {
|
|
1608
|
-
accumulateDirectDispatches(event);
|
|
1609
|
-
}
|
|
1415
|
+
event.persist();
|
|
1610
1416
|
|
|
1611
|
-
|
|
1612
|
-
// Normally extractEvent enqueues a state restore, but we'll just always
|
|
1613
|
-
// do that since we're by-passing it here.
|
|
1614
|
-
enqueueStateRestore(domNode);
|
|
1615
|
-
runEventsInBatch(event);
|
|
1616
|
-
});
|
|
1617
|
-
restoreStateIfNeeded();
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1417
|
+
_assign(event, eventData);
|
|
1620
1418
|
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1419
|
+
if (dispatchConfig.phasedRegistrationNames) {
|
|
1420
|
+
accumulateTwoPhaseDispatches$1(event);
|
|
1421
|
+
} else {
|
|
1422
|
+
accumulateDirectDispatches$1(event);
|
|
1423
|
+
}
|
|
1624
1424
|
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1425
|
+
ReactDOM.unstable_batchedUpdates(function () {
|
|
1426
|
+
// Normally extractEvent enqueues a state restore, but we'll just always
|
|
1427
|
+
// do that since we're by-passing it here.
|
|
1428
|
+
enqueueStateRestore$1(domNode);
|
|
1429
|
+
runEventsInBatch$1(event);
|
|
1430
|
+
});
|
|
1431
|
+
restoreStateIfNeeded$1();
|
|
1432
|
+
};
|
|
1631
1433
|
}
|
|
1632
|
-
}
|
|
1633
1434
|
|
|
1634
|
-
buildSimulators()
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
*
|
|
1638
|
-
* - `ReactTestUtils.SimulateNative.click(Element/ReactDOMComponent)`
|
|
1639
|
-
* - `ReactTestUtils.SimulateNative.mouseMove(Element/ReactDOMComponent)`
|
|
1640
|
-
* - `ReactTestUtils.SimulateNative.mouseIn/ReactDOMComponent)`
|
|
1641
|
-
* - `ReactTestUtils.SimulateNative.mouseOut(Element/ReactDOMComponent)`
|
|
1642
|
-
* - ... (All keys from `BrowserEventConstants.topLevelTypes`)
|
|
1643
|
-
*
|
|
1644
|
-
* Note: Top level event types are a subset of the entire set of handler types
|
|
1645
|
-
* (which include a broader set of "synthetic" events). For example, onDragDone
|
|
1646
|
-
* is a synthetic event. Except when testing an event plugin or React's event
|
|
1647
|
-
* handling code specifically, you probably want to use ReactTestUtils.Simulate
|
|
1648
|
-
* to dispatch synthetic events.
|
|
1649
|
-
*/
|
|
1435
|
+
function buildSimulators() {
|
|
1436
|
+
ReactTestUtils.Simulate = {};
|
|
1437
|
+
var eventType;
|
|
1650
1438
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
|
1658
|
-
simulateNativeEventOnDOMComponent(topLevelType, domComponentOrNode, fakeNativeEvent);
|
|
1659
|
-
} else if (domComponentOrNode.tagName) {
|
|
1660
|
-
// Will allow on actual dom nodes.
|
|
1661
|
-
simulateNativeEventOnNode(topLevelType, domComponentOrNode, fakeNativeEvent);
|
|
1439
|
+
for (eventType in eventNameDispatchConfigs$1) {
|
|
1440
|
+
/**
|
|
1441
|
+
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
1442
|
+
* @param {?object} eventData Fake event data to use in SyntheticEvent.
|
|
1443
|
+
*/
|
|
1444
|
+
ReactTestUtils.Simulate[eventType] = makeSimulator(eventType);
|
|
1662
1445
|
}
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
[[TOP_ABORT, 'abort'], [TOP_ANIMATION_END, 'animationEnd'], [TOP_ANIMATION_ITERATION, 'animationIteration'], [TOP_ANIMATION_START, 'animationStart'], [TOP_BLUR, 'blur'], [TOP_CAN_PLAY_THROUGH, 'canPlayThrough'], [TOP_CAN_PLAY, 'canPlay'], [TOP_CANCEL, 'cancel'], [TOP_CHANGE, 'change'], [TOP_CLICK, 'click'], [TOP_CLOSE, 'close'], [TOP_COMPOSITION_END, 'compositionEnd'], [TOP_COMPOSITION_START, 'compositionStart'], [TOP_COMPOSITION_UPDATE, 'compositionUpdate'], [TOP_CONTEXT_MENU, 'contextMenu'], [TOP_COPY, 'copy'], [TOP_CUT, 'cut'], [TOP_DOUBLE_CLICK, 'doubleClick'], [TOP_DRAG_END, 'dragEnd'], [TOP_DRAG_ENTER, 'dragEnter'], [TOP_DRAG_EXIT, 'dragExit'], [TOP_DRAG_LEAVE, 'dragLeave'], [TOP_DRAG_OVER, 'dragOver'], [TOP_DRAG_START, 'dragStart'], [TOP_DRAG, 'drag'], [TOP_DROP, 'drop'], [TOP_DURATION_CHANGE, 'durationChange'], [TOP_EMPTIED, 'emptied'], [TOP_ENCRYPTED, 'encrypted'], [TOP_ENDED, 'ended'], [TOP_ERROR, 'error'], [TOP_FOCUS, 'focus'], [TOP_INPUT, 'input'], [TOP_KEY_DOWN, 'keyDown'], [TOP_KEY_PRESS, 'keyPress'], [TOP_KEY_UP, 'keyUp'], [TOP_LOAD_START, 'loadStart'], [TOP_LOAD_START, 'loadStart'], [TOP_LOAD, 'load'], [TOP_LOADED_DATA, 'loadedData'], [TOP_LOADED_METADATA, 'loadedMetadata'], [TOP_MOUSE_DOWN, 'mouseDown'], [TOP_MOUSE_MOVE, 'mouseMove'], [TOP_MOUSE_OUT, 'mouseOut'], [TOP_MOUSE_OVER, 'mouseOver'], [TOP_MOUSE_UP, 'mouseUp'], [TOP_PASTE, 'paste'], [TOP_PAUSE, 'pause'], [TOP_PLAY, 'play'], [TOP_PLAYING, 'playing'], [TOP_PROGRESS, 'progress'], [TOP_RATE_CHANGE, 'rateChange'], [TOP_SCROLL, 'scroll'], [TOP_SEEKED, 'seeked'], [TOP_SEEKING, 'seeking'], [TOP_SELECTION_CHANGE, 'selectionChange'], [TOP_STALLED, 'stalled'], [TOP_SUSPEND, 'suspend'], [TOP_TEXT_INPUT, 'textInput'], [TOP_TIME_UPDATE, 'timeUpdate'], [TOP_TOGGLE, 'toggle'], [TOP_TOUCH_CANCEL, 'touchCancel'], [TOP_TOUCH_END, 'touchEnd'], [TOP_TOUCH_MOVE, 'touchMove'], [TOP_TOUCH_START, 'touchStart'], [TOP_TRANSITION_END, 'transitionEnd'], [TOP_VOLUME_CHANGE, 'volumeChange'], [TOP_WAITING, 'waiting'], [TOP_WHEEL, 'wheel']].forEach(function (_ref) {
|
|
1667
|
-
var topLevelType = _ref[0],
|
|
1668
|
-
eventType = _ref[1];
|
|
1446
|
+
}
|
|
1669
1447
|
|
|
1448
|
+
buildSimulators();
|
|
1670
1449
|
/**
|
|
1671
|
-
*
|
|
1672
|
-
*
|
|
1450
|
+
* Exports:
|
|
1451
|
+
*
|
|
1452
|
+
* - `ReactTestUtils.SimulateNative.click(Element/ReactDOMComponent)`
|
|
1453
|
+
* - `ReactTestUtils.SimulateNative.mouseMove(Element/ReactDOMComponent)`
|
|
1454
|
+
* - `ReactTestUtils.SimulateNative.mouseIn/ReactDOMComponent)`
|
|
1455
|
+
* - `ReactTestUtils.SimulateNative.mouseOut(Element/ReactDOMComponent)`
|
|
1456
|
+
* - ... (All keys from `BrowserEventConstants.topLevelTypes`)
|
|
1457
|
+
*
|
|
1458
|
+
* Note: Top level event types are a subset of the entire set of handler types
|
|
1459
|
+
* (which include a broader set of "synthetic" events). For example, onDragDone
|
|
1460
|
+
* is a synthetic event. Except when testing an event plugin or React's event
|
|
1461
|
+
* handling code specifically, you probably want to use ReactTestUtils.Simulate
|
|
1462
|
+
* to dispatch synthetic events.
|
|
1673
1463
|
*/
|
|
1674
|
-
ReactTestUtils.SimulateNative[eventType] = makeNativeSimulator(eventType, topLevelType);
|
|
1675
|
-
});
|
|
1676
1464
|
|
|
1465
|
+
function makeNativeSimulator(eventType, topLevelType) {
|
|
1466
|
+
return function (domComponentOrNode, nativeEventData) {
|
|
1467
|
+
var fakeNativeEvent = new Event(eventType);
|
|
1677
1468
|
|
|
1678
|
-
|
|
1679
|
-
default: ReactTestUtils
|
|
1680
|
-
});
|
|
1469
|
+
_assign(fakeNativeEvent, nativeEventData);
|
|
1681
1470
|
|
|
1682
|
-
|
|
1471
|
+
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
|
1472
|
+
simulateNativeEventOnDOMComponent(topLevelType, domComponentOrNode, fakeNativeEvent);
|
|
1473
|
+
} else if (domComponentOrNode.tagName) {
|
|
1474
|
+
// Will allow on actual dom nodes.
|
|
1475
|
+
simulateNativeEventOnNode(topLevelType, domComponentOrNode, fakeNativeEvent);
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
[[TOP_ABORT, 'abort'], [TOP_ANIMATION_END, 'animationEnd'], [TOP_ANIMATION_ITERATION, 'animationIteration'], [TOP_ANIMATION_START, 'animationStart'], [TOP_BLUR, 'blur'], [TOP_CAN_PLAY_THROUGH, 'canPlayThrough'], [TOP_CAN_PLAY, 'canPlay'], [TOP_CANCEL, 'cancel'], [TOP_CHANGE, 'change'], [TOP_CLICK, 'click'], [TOP_CLOSE, 'close'], [TOP_COMPOSITION_END, 'compositionEnd'], [TOP_COMPOSITION_START, 'compositionStart'], [TOP_COMPOSITION_UPDATE, 'compositionUpdate'], [TOP_CONTEXT_MENU, 'contextMenu'], [TOP_COPY, 'copy'], [TOP_CUT, 'cut'], [TOP_DOUBLE_CLICK, 'doubleClick'], [TOP_DRAG_END, 'dragEnd'], [TOP_DRAG_ENTER, 'dragEnter'], [TOP_DRAG_EXIT, 'dragExit'], [TOP_DRAG_LEAVE, 'dragLeave'], [TOP_DRAG_OVER, 'dragOver'], [TOP_DRAG_START, 'dragStart'], [TOP_DRAG, 'drag'], [TOP_DROP, 'drop'], [TOP_DURATION_CHANGE, 'durationChange'], [TOP_EMPTIED, 'emptied'], [TOP_ENCRYPTED, 'encrypted'], [TOP_ENDED, 'ended'], [TOP_ERROR, 'error'], [TOP_FOCUS, 'focus'], [TOP_INPUT, 'input'], [TOP_KEY_DOWN, 'keyDown'], [TOP_KEY_PRESS, 'keyPress'], [TOP_KEY_UP, 'keyUp'], [TOP_LOAD_START, 'loadStart'], [TOP_LOAD_START, 'loadStart'], [TOP_LOAD, 'load'], [TOP_LOADED_DATA, 'loadedData'], [TOP_LOADED_METADATA, 'loadedMetadata'], [TOP_MOUSE_DOWN, 'mouseDown'], [TOP_MOUSE_MOVE, 'mouseMove'], [TOP_MOUSE_OUT, 'mouseOut'], [TOP_MOUSE_OVER, 'mouseOver'], [TOP_MOUSE_UP, 'mouseUp'], [TOP_PASTE, 'paste'], [TOP_PAUSE, 'pause'], [TOP_PLAY, 'play'], [TOP_PLAYING, 'playing'], [TOP_PROGRESS, 'progress'], [TOP_RATE_CHANGE, 'rateChange'], [TOP_SCROLL, 'scroll'], [TOP_SEEKED, 'seeked'], [TOP_SEEKING, 'seeking'], [TOP_SELECTION_CHANGE, 'selectionChange'], [TOP_STALLED, 'stalled'], [TOP_SUSPEND, 'suspend'], [TOP_TEXT_INPUT, 'textInput'], [TOP_TIME_UPDATE, 'timeUpdate'], [TOP_TOGGLE, 'toggle'], [TOP_TOUCH_CANCEL, 'touchCancel'], [TOP_TOUCH_END, 'touchEnd'], [TOP_TOUCH_MOVE, 'touchMove'], [TOP_TOUCH_START, 'touchStart'], [TOP_TRANSITION_END, 'transitionEnd'], [TOP_VOLUME_CHANGE, 'volumeChange'], [TOP_WAITING, 'waiting'], [TOP_WHEEL, 'wheel']].forEach(function (_ref) {
|
|
1481
|
+
var topLevelType = _ref[0],
|
|
1482
|
+
eventType = _ref[1];
|
|
1483
|
+
|
|
1484
|
+
/**
|
|
1485
|
+
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
1486
|
+
* @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
|
|
1487
|
+
*/
|
|
1488
|
+
ReactTestUtils.SimulateNative[eventType] = makeNativeSimulator(eventType, topLevelType);
|
|
1489
|
+
});
|
|
1683
1490
|
|
|
1684
|
-
// TODO: decide on the top-level export form.
|
|
1685
|
-
// This is hacky but makes it work with both Rollup and Jest.
|
|
1491
|
+
// TODO: decide on the top-level export form.
|
|
1492
|
+
// This is hacky but makes it work with both Rollup and Jest.
|
|
1686
1493
|
|
|
1687
1494
|
|
|
1688
|
-
var testUtils = ReactTestUtils
|
|
1495
|
+
var testUtils = ReactTestUtils.default || ReactTestUtils;
|
|
1689
1496
|
|
|
1690
|
-
return testUtils;
|
|
1497
|
+
return testUtils;
|
|
1691
1498
|
|
|
1692
1499
|
})));
|