1 |
3a515b92
|
cagy
|
(function (global, factory) {
|
2 |
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('redux'), require('react-dom')) :
|
3 |
|
|
typeof define === 'function' && define.amd ? define(['exports', 'react', 'redux', 'react-dom'], factory) :
|
4 |
|
|
(global = global || self, factory(global.ReactRedux = {}, global.React, global.Redux, global.ReactDOM));
|
5 |
|
|
}(this, function (exports, React, redux, reactDom) { 'use strict';
|
6 |
|
|
|
7 |
|
|
var React__default = 'default' in React ? React['default'] : React;
|
8 |
|
|
|
9 |
|
|
function unwrapExports (x) {
|
10 |
|
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
function createCommonjsModule(fn, module) {
|
14 |
|
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
var reactIs_development = createCommonjsModule(function (module, exports) {
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
{
|
22 |
|
|
(function() {
|
23 |
|
|
|
24 |
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
25 |
|
|
|
26 |
|
|
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
27 |
|
|
// nor polyfill, then a plain number is used for performance.
|
28 |
|
|
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
29 |
|
|
|
30 |
|
|
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
31 |
|
|
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
32 |
|
|
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
33 |
|
|
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
34 |
|
|
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
35 |
|
|
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
36 |
|
|
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
37 |
|
|
// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
|
38 |
|
|
// (unstable) APIs that have been removed. Can we remove the symbols?
|
39 |
|
|
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
40 |
|
|
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
41 |
|
|
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
42 |
|
|
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
43 |
|
|
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
|
44 |
|
|
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
45 |
|
|
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
46 |
|
|
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
|
47 |
|
|
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
|
48 |
|
|
|
49 |
|
|
function isValidElementType(type) {
|
50 |
|
|
return typeof type === 'string' || typeof type === 'function' ||
|
51 |
|
|
// Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
52 |
|
|
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Forked from fbjs/warning:
|
57 |
|
|
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
58 |
|
|
*
|
59 |
|
|
* Only change is we use console.warn instead of console.error,
|
60 |
|
|
* and do nothing when 'console' is not supported.
|
61 |
|
|
* This really simplifies the code.
|
62 |
|
|
* ---
|
63 |
|
|
* Similar to invariant but only logs a warning if the condition is not met.
|
64 |
|
|
* This can be used to log issues in development environments in critical
|
65 |
|
|
* paths. Removing the logging code for production environments will keep the
|
66 |
|
|
* same logic and follow the same code paths.
|
67 |
|
|
*/
|
68 |
|
|
|
69 |
|
|
var lowPriorityWarning = function () {};
|
70 |
|
|
|
71 |
|
|
{
|
72 |
|
|
var printWarning = function (format) {
|
73 |
|
|
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
74 |
|
|
args[_key - 1] = arguments[_key];
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
var argIndex = 0;
|
78 |
|
|
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
79 |
|
|
return args[argIndex++];
|
80 |
|
|
});
|
81 |
|
|
if (typeof console !== 'undefined') {
|
82 |
|
|
console.warn(message);
|
83 |
|
|
}
|
84 |
|
|
try {
|
85 |
|
|
// --- Welcome to debugging React ---
|
86 |
|
|
// This error was thrown as a convenience so that you can use this stack
|
87 |
|
|
// to find the callsite that caused this warning to fire.
|
88 |
|
|
throw new Error(message);
|
89 |
|
|
} catch (x) {}
|
90 |
|
|
};
|
91 |
|
|
|
92 |
|
|
lowPriorityWarning = function (condition, format) {
|
93 |
|
|
if (format === undefined) {
|
94 |
|
|
throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
|
95 |
|
|
}
|
96 |
|
|
if (!condition) {
|
97 |
|
|
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
98 |
|
|
args[_key2 - 2] = arguments[_key2];
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
printWarning.apply(undefined, [format].concat(args));
|
102 |
|
|
}
|
103 |
|
|
};
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
var lowPriorityWarning$1 = lowPriorityWarning;
|
107 |
|
|
|
108 |
|
|
function typeOf(object) {
|
109 |
|
|
if (typeof object === 'object' && object !== null) {
|
110 |
|
|
var $$typeof = object.$$typeof;
|
111 |
|
|
switch ($$typeof) {
|
112 |
|
|
case REACT_ELEMENT_TYPE:
|
113 |
|
|
var type = object.type;
|
114 |
|
|
|
115 |
|
|
switch (type) {
|
116 |
|
|
case REACT_ASYNC_MODE_TYPE:
|
117 |
|
|
case REACT_CONCURRENT_MODE_TYPE:
|
118 |
|
|
case REACT_FRAGMENT_TYPE:
|
119 |
|
|
case REACT_PROFILER_TYPE:
|
120 |
|
|
case REACT_STRICT_MODE_TYPE:
|
121 |
|
|
case REACT_SUSPENSE_TYPE:
|
122 |
|
|
return type;
|
123 |
|
|
default:
|
124 |
|
|
var $$typeofType = type && type.$$typeof;
|
125 |
|
|
|
126 |
|
|
switch ($$typeofType) {
|
127 |
|
|
case REACT_CONTEXT_TYPE:
|
128 |
|
|
case REACT_FORWARD_REF_TYPE:
|
129 |
|
|
case REACT_PROVIDER_TYPE:
|
130 |
|
|
return $$typeofType;
|
131 |
|
|
default:
|
132 |
|
|
return $$typeof;
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
case REACT_LAZY_TYPE:
|
136 |
|
|
case REACT_MEMO_TYPE:
|
137 |
|
|
case REACT_PORTAL_TYPE:
|
138 |
|
|
return $$typeof;
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
return undefined;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
// AsyncMode is deprecated along with isAsyncMode
|
146 |
|
|
var AsyncMode = REACT_ASYNC_MODE_TYPE;
|
147 |
|
|
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
|
148 |
|
|
var ContextConsumer = REACT_CONTEXT_TYPE;
|
149 |
|
|
var ContextProvider = REACT_PROVIDER_TYPE;
|
150 |
|
|
var Element = REACT_ELEMENT_TYPE;
|
151 |
|
|
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
152 |
|
|
var Fragment = REACT_FRAGMENT_TYPE;
|
153 |
|
|
var Lazy = REACT_LAZY_TYPE;
|
154 |
|
|
var Memo = REACT_MEMO_TYPE;
|
155 |
|
|
var Portal = REACT_PORTAL_TYPE;
|
156 |
|
|
var Profiler = REACT_PROFILER_TYPE;
|
157 |
|
|
var StrictMode = REACT_STRICT_MODE_TYPE;
|
158 |
|
|
var Suspense = REACT_SUSPENSE_TYPE;
|
159 |
|
|
|
160 |
|
|
var hasWarnedAboutDeprecatedIsAsyncMode = false;
|
161 |
|
|
|
162 |
|
|
// AsyncMode should be deprecated
|
163 |
|
|
function isAsyncMode(object) {
|
164 |
|
|
{
|
165 |
|
|
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
166 |
|
|
hasWarnedAboutDeprecatedIsAsyncMode = true;
|
167 |
|
|
lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
|
168 |
|
|
}
|
169 |
|
|
}
|
170 |
|
|
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
171 |
|
|
}
|
172 |
|
|
function isConcurrentMode(object) {
|
173 |
|
|
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
|
174 |
|
|
}
|
175 |
|
|
function isContextConsumer(object) {
|
176 |
|
|
return typeOf(object) === REACT_CONTEXT_TYPE;
|
177 |
|
|
}
|
178 |
|
|
function isContextProvider(object) {
|
179 |
|
|
return typeOf(object) === REACT_PROVIDER_TYPE;
|
180 |
|
|
}
|
181 |
|
|
function isElement(object) {
|
182 |
|
|
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
183 |
|
|
}
|
184 |
|
|
function isForwardRef(object) {
|
185 |
|
|
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
186 |
|
|
}
|
187 |
|
|
function isFragment(object) {
|
188 |
|
|
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
189 |
|
|
}
|
190 |
|
|
function isLazy(object) {
|
191 |
|
|
return typeOf(object) === REACT_LAZY_TYPE;
|
192 |
|
|
}
|
193 |
|
|
function isMemo(object) {
|
194 |
|
|
return typeOf(object) === REACT_MEMO_TYPE;
|
195 |
|
|
}
|
196 |
|
|
function isPortal(object) {
|
197 |
|
|
return typeOf(object) === REACT_PORTAL_TYPE;
|
198 |
|
|
}
|
199 |
|
|
function isProfiler(object) {
|
200 |
|
|
return typeOf(object) === REACT_PROFILER_TYPE;
|
201 |
|
|
}
|
202 |
|
|
function isStrictMode(object) {
|
203 |
|
|
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
204 |
|
|
}
|
205 |
|
|
function isSuspense(object) {
|
206 |
|
|
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
exports.typeOf = typeOf;
|
210 |
|
|
exports.AsyncMode = AsyncMode;
|
211 |
|
|
exports.ConcurrentMode = ConcurrentMode;
|
212 |
|
|
exports.ContextConsumer = ContextConsumer;
|
213 |
|
|
exports.ContextProvider = ContextProvider;
|
214 |
|
|
exports.Element = Element;
|
215 |
|
|
exports.ForwardRef = ForwardRef;
|
216 |
|
|
exports.Fragment = Fragment;
|
217 |
|
|
exports.Lazy = Lazy;
|
218 |
|
|
exports.Memo = Memo;
|
219 |
|
|
exports.Portal = Portal;
|
220 |
|
|
exports.Profiler = Profiler;
|
221 |
|
|
exports.StrictMode = StrictMode;
|
222 |
|
|
exports.Suspense = Suspense;
|
223 |
|
|
exports.isValidElementType = isValidElementType;
|
224 |
|
|
exports.isAsyncMode = isAsyncMode;
|
225 |
|
|
exports.isConcurrentMode = isConcurrentMode;
|
226 |
|
|
exports.isContextConsumer = isContextConsumer;
|
227 |
|
|
exports.isContextProvider = isContextProvider;
|
228 |
|
|
exports.isElement = isElement;
|
229 |
|
|
exports.isForwardRef = isForwardRef;
|
230 |
|
|
exports.isFragment = isFragment;
|
231 |
|
|
exports.isLazy = isLazy;
|
232 |
|
|
exports.isMemo = isMemo;
|
233 |
|
|
exports.isPortal = isPortal;
|
234 |
|
|
exports.isProfiler = isProfiler;
|
235 |
|
|
exports.isStrictMode = isStrictMode;
|
236 |
|
|
exports.isSuspense = isSuspense;
|
237 |
|
|
})();
|
238 |
|
|
}
|
239 |
|
|
});
|
240 |
|
|
|
241 |
|
|
unwrapExports(reactIs_development);
|
242 |
|
|
var reactIs_development_1 = reactIs_development.typeOf;
|
243 |
|
|
var reactIs_development_2 = reactIs_development.AsyncMode;
|
244 |
|
|
var reactIs_development_3 = reactIs_development.ConcurrentMode;
|
245 |
|
|
var reactIs_development_4 = reactIs_development.ContextConsumer;
|
246 |
|
|
var reactIs_development_5 = reactIs_development.ContextProvider;
|
247 |
|
|
var reactIs_development_6 = reactIs_development.Element;
|
248 |
|
|
var reactIs_development_7 = reactIs_development.ForwardRef;
|
249 |
|
|
var reactIs_development_8 = reactIs_development.Fragment;
|
250 |
|
|
var reactIs_development_9 = reactIs_development.Lazy;
|
251 |
|
|
var reactIs_development_10 = reactIs_development.Memo;
|
252 |
|
|
var reactIs_development_11 = reactIs_development.Portal;
|
253 |
|
|
var reactIs_development_12 = reactIs_development.Profiler;
|
254 |
|
|
var reactIs_development_13 = reactIs_development.StrictMode;
|
255 |
|
|
var reactIs_development_14 = reactIs_development.Suspense;
|
256 |
|
|
var reactIs_development_15 = reactIs_development.isValidElementType;
|
257 |
|
|
var reactIs_development_16 = reactIs_development.isAsyncMode;
|
258 |
|
|
var reactIs_development_17 = reactIs_development.isConcurrentMode;
|
259 |
|
|
var reactIs_development_18 = reactIs_development.isContextConsumer;
|
260 |
|
|
var reactIs_development_19 = reactIs_development.isContextProvider;
|
261 |
|
|
var reactIs_development_20 = reactIs_development.isElement;
|
262 |
|
|
var reactIs_development_21 = reactIs_development.isForwardRef;
|
263 |
|
|
var reactIs_development_22 = reactIs_development.isFragment;
|
264 |
|
|
var reactIs_development_23 = reactIs_development.isLazy;
|
265 |
|
|
var reactIs_development_24 = reactIs_development.isMemo;
|
266 |
|
|
var reactIs_development_25 = reactIs_development.isPortal;
|
267 |
|
|
var reactIs_development_26 = reactIs_development.isProfiler;
|
268 |
|
|
var reactIs_development_27 = reactIs_development.isStrictMode;
|
269 |
|
|
var reactIs_development_28 = reactIs_development.isSuspense;
|
270 |
|
|
|
271 |
|
|
var reactIs = createCommonjsModule(function (module) {
|
272 |
|
|
|
273 |
|
|
{
|
274 |
|
|
module.exports = reactIs_development;
|
275 |
|
|
}
|
276 |
|
|
});
|
277 |
|
|
var reactIs_1 = reactIs.isValidElementType;
|
278 |
|
|
var reactIs_2 = reactIs.isContextConsumer;
|
279 |
|
|
|
280 |
|
|
/*
|
281 |
|
|
object-assign
|
282 |
|
|
(c) Sindre Sorhus
|
283 |
|
|
@license MIT
|
284 |
|
|
*/
|
285 |
|
|
/* eslint-disable no-unused-vars */
|
286 |
|
|
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
287 |
|
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
288 |
|
|
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
289 |
|
|
|
290 |
|
|
function toObject(val) {
|
291 |
|
|
if (val === null || val === undefined) {
|
292 |
|
|
throw new TypeError('Object.assign cannot be called with null or undefined');
|
293 |
|
|
}
|
294 |
|
|
|
295 |
|
|
return Object(val);
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
function shouldUseNative() {
|
299 |
|
|
try {
|
300 |
|
|
if (!Object.assign) {
|
301 |
|
|
return false;
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
// Detect buggy property enumeration order in older V8 versions.
|
305 |
|
|
|
306 |
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
307 |
|
|
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
|
308 |
|
|
test1[5] = 'de';
|
309 |
|
|
if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
310 |
|
|
return false;
|
311 |
|
|
}
|
312 |
|
|
|
313 |
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
314 |
|
|
var test2 = {};
|
315 |
|
|
for (var i = 0; i < 10; i++) {
|
316 |
|
|
test2['_' + String.fromCharCode(i)] = i;
|
317 |
|
|
}
|
318 |
|
|
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
319 |
|
|
return test2[n];
|
320 |
|
|
});
|
321 |
|
|
if (order2.join('') !== '0123456789') {
|
322 |
|
|
return false;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
326 |
|
|
var test3 = {};
|
327 |
|
|
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
328 |
|
|
test3[letter] = letter;
|
329 |
|
|
});
|
330 |
|
|
if (Object.keys(Object.assign({}, test3)).join('') !==
|
331 |
|
|
'abcdefghijklmnopqrst') {
|
332 |
|
|
return false;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
return true;
|
336 |
|
|
} catch (err) {
|
337 |
|
|
// We don't expect any of the above to throw, but better to be safe.
|
338 |
|
|
return false;
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
343 |
|
|
var from;
|
344 |
|
|
var to = toObject(target);
|
345 |
|
|
var symbols;
|
346 |
|
|
|
347 |
|
|
for (var s = 1; s < arguments.length; s++) {
|
348 |
|
|
from = Object(arguments[s]);
|
349 |
|
|
|
350 |
|
|
for (var key in from) {
|
351 |
|
|
if (hasOwnProperty.call(from, key)) {
|
352 |
|
|
to[key] = from[key];
|
353 |
|
|
}
|
354 |
|
|
}
|
355 |
|
|
|
356 |
|
|
if (getOwnPropertySymbols) {
|
357 |
|
|
symbols = getOwnPropertySymbols(from);
|
358 |
|
|
for (var i = 0; i < symbols.length; i++) {
|
359 |
|
|
if (propIsEnumerable.call(from, symbols[i])) {
|
360 |
|
|
to[symbols[i]] = from[symbols[i]];
|
361 |
|
|
}
|
362 |
|
|
}
|
363 |
|
|
}
|
364 |
|
|
}
|
365 |
|
|
|
366 |
|
|
return to;
|
367 |
|
|
};
|
368 |
|
|
|
369 |
|
|
/**
|
370 |
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
371 |
|
|
*
|
372 |
|
|
* This source code is licensed under the MIT license found in the
|
373 |
|
|
* LICENSE file in the root directory of this source tree.
|
374 |
|
|
*/
|
375 |
|
|
|
376 |
|
|
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
377 |
|
|
|
378 |
|
|
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
|
379 |
|
|
|
380 |
|
|
var printWarning = function() {};
|
381 |
|
|
|
382 |
|
|
{
|
383 |
|
|
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
384 |
|
|
var loggedTypeFailures = {};
|
385 |
|
|
var has = Function.call.bind(Object.prototype.hasOwnProperty);
|
386 |
|
|
|
387 |
|
|
printWarning = function(text) {
|
388 |
|
|
var message = 'Warning: ' + text;
|
389 |
|
|
if (typeof console !== 'undefined') {
|
390 |
|
|
console.error(message);
|
391 |
|
|
}
|
392 |
|
|
try {
|
393 |
|
|
// --- Welcome to debugging React ---
|
394 |
|
|
// This error was thrown as a convenience so that you can use this stack
|
395 |
|
|
// to find the callsite that caused this warning to fire.
|
396 |
|
|
throw new Error(message);
|
397 |
|
|
} catch (x) {}
|
398 |
|
|
};
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
/**
|
402 |
|
|
* Assert that the values match with the type specs.
|
403 |
|
|
* Error messages are memorized and will only be shown once.
|
404 |
|
|
*
|
405 |
|
|
* @param {object} typeSpecs Map of name to a ReactPropType
|
406 |
|
|
* @param {object} values Runtime values that need to be type-checked
|
407 |
|
|
* @param {string} location e.g. "prop", "context", "child context"
|
408 |
|
|
* @param {string} componentName Name of the component for error messages.
|
409 |
|
|
* @param {?Function} getStack Returns the component stack.
|
410 |
|
|
* @private
|
411 |
|
|
*/
|
412 |
|
|
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
413 |
|
|
{
|
414 |
|
|
for (var typeSpecName in typeSpecs) {
|
415 |
|
|
if (has(typeSpecs, typeSpecName)) {
|
416 |
|
|
var error;
|
417 |
|
|
// Prop type validation may throw. In case they do, we don't want to
|
418 |
|
|
// fail the render phase where it didn't fail before. So we log it.
|
419 |
|
|
// After these have been cleaned up, we'll let them throw.
|
420 |
|
|
try {
|
421 |
|
|
// This is intentionally an invariant that gets caught. It's the same
|
422 |
|
|
// behavior as without this statement except with a better message.
|
423 |
|
|
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
424 |
|
|
var err = Error(
|
425 |
|
|
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
426 |
|
|
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
427 |
|
|
);
|
428 |
|
|
err.name = 'Invariant Violation';
|
429 |
|
|
throw err;
|
430 |
|
|
}
|
431 |
|
|
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
|
432 |
|
|
} catch (ex) {
|
433 |
|
|
error = ex;
|
434 |
|
|
}
|
435 |
|
|
if (error && !(error instanceof Error)) {
|
436 |
|
|
printWarning(
|
437 |
|
|
(componentName || 'React class') + ': type specification of ' +
|
438 |
|
|
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
439 |
|
|
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
440 |
|
|
'You may have forgotten to pass an argument to the type checker ' +
|
441 |
|
|
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
442 |
|
|
'shape all require an argument).'
|
443 |
|
|
);
|
444 |
|
|
}
|
445 |
|
|
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
446 |
|
|
// Only monitor this failure once because there tends to be a lot of the
|
447 |
|
|
// same error.
|
448 |
|
|
loggedTypeFailures[error.message] = true;
|
449 |
|
|
|
450 |
|
|
var stack = getStack ? getStack() : '';
|
451 |
|
|
|
452 |
|
|
printWarning(
|
453 |
|
|
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
454 |
|
|
);
|
455 |
|
|
}
|
456 |
|
|
}
|
457 |
|
|
}
|
458 |
|
|
}
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
/**
|
462 |
|
|
* Resets warning cache when testing.
|
463 |
|
|
*
|
464 |
|
|
* @private
|
465 |
|
|
*/
|
466 |
|
|
checkPropTypes.resetWarningCache = function() {
|
467 |
|
|
{
|
468 |
|
|
loggedTypeFailures = {};
|
469 |
|
|
}
|
470 |
|
|
};
|
471 |
|
|
|
472 |
|
|
var checkPropTypes_1 = checkPropTypes;
|
473 |
|
|
|
474 |
|
|
var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
|
475 |
|
|
var printWarning$1 = function() {};
|
476 |
|
|
|
477 |
|
|
{
|
478 |
|
|
printWarning$1 = function(text) {
|
479 |
|
|
var message = 'Warning: ' + text;
|
480 |
|
|
if (typeof console !== 'undefined') {
|
481 |
|
|
console.error(message);
|
482 |
|
|
}
|
483 |
|
|
try {
|
484 |
|
|
// --- Welcome to debugging React ---
|
485 |
|
|
// This error was thrown as a convenience so that you can use this stack
|
486 |
|
|
// to find the callsite that caused this warning to fire.
|
487 |
|
|
throw new Error(message);
|
488 |
|
|
} catch (x) {}
|
489 |
|
|
};
|
490 |
|
|
}
|
491 |
|
|
|
492 |
|
|
function emptyFunctionThatReturnsNull() {
|
493 |
|
|
return null;
|
494 |
|
|
}
|
495 |
|
|
|
496 |
|
|
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
497 |
|
|
/* global Symbol */
|
498 |
|
|
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
499 |
|
|
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
500 |
|
|
|
501 |
|
|
/**
|
502 |
|
|
* Returns the iterator method function contained on the iterable object.
|
503 |
|
|
*
|
504 |
|
|
* Be sure to invoke the function with the iterable as context:
|
505 |
|
|
*
|
506 |
|
|
* var iteratorFn = getIteratorFn(myIterable);
|
507 |
|
|
* if (iteratorFn) {
|
508 |
|
|
* var iterator = iteratorFn.call(myIterable);
|
509 |
|
|
* ...
|
510 |
|
|
* }
|
511 |
|
|
*
|
512 |
|
|
* @param {?object} maybeIterable
|
513 |
|
|
* @return {?function}
|
514 |
|
|
*/
|
515 |
|
|
function getIteratorFn(maybeIterable) {
|
516 |
|
|
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
517 |
|
|
if (typeof iteratorFn === 'function') {
|
518 |
|
|
return iteratorFn;
|
519 |
|
|
}
|
520 |
|
|
}
|
521 |
|
|
|
522 |
|
|
/**
|
523 |
|
|
* Collection of methods that allow declaration and validation of props that are
|
524 |
|
|
* supplied to React components. Example usage:
|
525 |
|
|
*
|
526 |
|
|
* var Props = require('ReactPropTypes');
|
527 |
|
|
* var MyArticle = React.createClass({
|
528 |
|
|
* propTypes: {
|
529 |
|
|
* // An optional string prop named "description".
|
530 |
|
|
* description: Props.string,
|
531 |
|
|
*
|
532 |
|
|
* // A required enum prop named "category".
|
533 |
|
|
* category: Props.oneOf(['News','Photos']).isRequired,
|
534 |
|
|
*
|
535 |
|
|
* // A prop named "dialog" that requires an instance of Dialog.
|
536 |
|
|
* dialog: Props.instanceOf(Dialog).isRequired
|
537 |
|
|
* },
|
538 |
|
|
* render: function() { ... }
|
539 |
|
|
* });
|
540 |
|
|
*
|
541 |
|
|
* A more formal specification of how these methods are used:
|
542 |
|
|
*
|
543 |
|
|
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
544 |
|
|
* decl := ReactPropTypes.{type}(.isRequired)?
|
545 |
|
|
*
|
546 |
|
|
* Each and every declaration produces a function with the same signature. This
|
547 |
|
|
* allows the creation of custom validation functions. For example:
|
548 |
|
|
*
|
549 |
|
|
* var MyLink = React.createClass({
|
550 |
|
|
* propTypes: {
|
551 |
|
|
* // An optional string or URI prop named "href".
|
552 |
|
|
* href: function(props, propName, componentName) {
|
553 |
|
|
* var propValue = props[propName];
|
554 |
|
|
* if (propValue != null && typeof propValue !== 'string' &&
|
555 |
|
|
* !(propValue instanceof URI)) {
|
556 |
|
|
* return new Error(
|
557 |
|
|
* 'Expected a string or an URI for ' + propName + ' in ' +
|
558 |
|
|
* componentName
|
559 |
|
|
* );
|
560 |
|
|
* }
|
561 |
|
|
* }
|
562 |
|
|
* },
|
563 |
|
|
* render: function() {...}
|
564 |
|
|
* });
|
565 |
|
|
*
|
566 |
|
|
* @internal
|
567 |
|
|
*/
|
568 |
|
|
|
569 |
|
|
var ANONYMOUS = '<<anonymous>>';
|
570 |
|
|
|
571 |
|
|
// Important!
|
572 |
|
|
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
573 |
|
|
var ReactPropTypes = {
|
574 |
|
|
array: createPrimitiveTypeChecker('array'),
|
575 |
|
|
bool: createPrimitiveTypeChecker('boolean'),
|
576 |
|
|
func: createPrimitiveTypeChecker('function'),
|
577 |
|
|
number: createPrimitiveTypeChecker('number'),
|
578 |
|
|
object: createPrimitiveTypeChecker('object'),
|
579 |
|
|
string: createPrimitiveTypeChecker('string'),
|
580 |
|
|
symbol: createPrimitiveTypeChecker('symbol'),
|
581 |
|
|
|
582 |
|
|
any: createAnyTypeChecker(),
|
583 |
|
|
arrayOf: createArrayOfTypeChecker,
|
584 |
|
|
element: createElementTypeChecker(),
|
585 |
|
|
elementType: createElementTypeTypeChecker(),
|
586 |
|
|
instanceOf: createInstanceTypeChecker,
|
587 |
|
|
node: createNodeChecker(),
|
588 |
|
|
objectOf: createObjectOfTypeChecker,
|
589 |
|
|
oneOf: createEnumTypeChecker,
|
590 |
|
|
oneOfType: createUnionTypeChecker,
|
591 |
|
|
shape: createShapeTypeChecker,
|
592 |
|
|
exact: createStrictShapeTypeChecker,
|
593 |
|
|
};
|
594 |
|
|
|
595 |
|
|
/**
|
596 |
|
|
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
597 |
|
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
598 |
|
|
*/
|
599 |
|
|
/*eslint-disable no-self-compare*/
|
600 |
|
|
function is(x, y) {
|
601 |
|
|
// SameValue algorithm
|
602 |
|
|
if (x === y) {
|
603 |
|
|
// Steps 1-5, 7-10
|
604 |
|
|
// Steps 6.b-6.e: +0 != -0
|
605 |
|
|
return x !== 0 || 1 / x === 1 / y;
|
606 |
|
|
} else {
|
607 |
|
|
// Step 6.a: NaN == NaN
|
608 |
|
|
return x !== x && y !== y;
|
609 |
|
|
}
|
610 |
|
|
}
|
611 |
|
|
/*eslint-enable no-self-compare*/
|
612 |
|
|
|
613 |
|
|
/**
|
614 |
|
|
* We use an Error-like object for backward compatibility as people may call
|
615 |
|
|
* PropTypes directly and inspect their output. However, we don't use real
|
616 |
|
|
* Errors anymore. We don't inspect their stack anyway, and creating them
|
617 |
|
|
* is prohibitively expensive if they are created too often, such as what
|
618 |
|
|
* happens in oneOfType() for any type before the one that matched.
|
619 |
|
|
*/
|
620 |
|
|
function PropTypeError(message) {
|
621 |
|
|
this.message = message;
|
622 |
|
|
this.stack = '';
|
623 |
|
|
}
|
624 |
|
|
// Make `instanceof Error` still work for returned errors.
|
625 |
|
|
PropTypeError.prototype = Error.prototype;
|
626 |
|
|
|
627 |
|
|
function createChainableTypeChecker(validate) {
|
628 |
|
|
{
|
629 |
|
|
var manualPropTypeCallCache = {};
|
630 |
|
|
var manualPropTypeWarningCount = 0;
|
631 |
|
|
}
|
632 |
|
|
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
633 |
|
|
componentName = componentName || ANONYMOUS;
|
634 |
|
|
propFullName = propFullName || propName;
|
635 |
|
|
|
636 |
|
|
if (secret !== ReactPropTypesSecret_1) {
|
637 |
|
|
if (throwOnDirectAccess) {
|
638 |
|
|
// New behavior only for users of `prop-types` package
|
639 |
|
|
var err = new Error(
|
640 |
|
|
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
641 |
|
|
'Use `PropTypes.checkPropTypes()` to call them. ' +
|
642 |
|
|
'Read more at http://fb.me/use-check-prop-types'
|
643 |
|
|
);
|
644 |
|
|
err.name = 'Invariant Violation';
|
645 |
|
|
throw err;
|
646 |
|
|
} else if ( typeof console !== 'undefined') {
|
647 |
|
|
// Old behavior for people using React.PropTypes
|
648 |
|
|
var cacheKey = componentName + ':' + propName;
|
649 |
|
|
if (
|
650 |
|
|
!manualPropTypeCallCache[cacheKey] &&
|
651 |
|
|
// Avoid spamming the console because they are often not actionable except for lib authors
|
652 |
|
|
manualPropTypeWarningCount < 3
|
653 |
|
|
) {
|
654 |
|
|
printWarning$1(
|
655 |
|
|
'You are manually calling a React.PropTypes validation ' +
|
656 |
|
|
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
657 |
|
|
'and will throw in the standalone `prop-types` package. ' +
|
658 |
|
|
'You may be seeing this warning due to a third-party PropTypes ' +
|
659 |
|
|
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
660 |
|
|
);
|
661 |
|
|
manualPropTypeCallCache[cacheKey] = true;
|
662 |
|
|
manualPropTypeWarningCount++;
|
663 |
|
|
}
|
664 |
|
|
}
|
665 |
|
|
}
|
666 |
|
|
if (props[propName] == null) {
|
667 |
|
|
if (isRequired) {
|
668 |
|
|
if (props[propName] === null) {
|
669 |
|
|
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
670 |
|
|
}
|
671 |
|
|
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
672 |
|
|
}
|
673 |
|
|
return null;
|
674 |
|
|
} else {
|
675 |
|
|
return validate(props, propName, componentName, location, propFullName);
|
676 |
|
|
}
|
677 |
|
|
}
|
678 |
|
|
|
679 |
|
|
var chainedCheckType = checkType.bind(null, false);
|
680 |
|
|
chainedCheckType.isRequired = checkType.bind(null, true);
|
681 |
|
|
|
682 |
|
|
return chainedCheckType;
|
683 |
|
|
}
|
684 |
|
|
|
685 |
|
|
function createPrimitiveTypeChecker(expectedType) {
|
686 |
|
|
function validate(props, propName, componentName, location, propFullName, secret) {
|
687 |
|
|
var propValue = props[propName];
|
688 |
|
|
var propType = getPropType(propValue);
|
689 |
|
|
if (propType !== expectedType) {
|
690 |
|
|
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
691 |
|
|
// check, but we can offer a more precise error message here rather than
|
692 |
|
|
// 'of type `object`'.
|
693 |
|
|
var preciseType = getPreciseType(propValue);
|
694 |
|
|
|
695 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
696 |
|
|
}
|
697 |
|
|
return null;
|
698 |
|
|
}
|
699 |
|
|
return createChainableTypeChecker(validate);
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
function createAnyTypeChecker() {
|
703 |
|
|
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
704 |
|
|
}
|
705 |
|
|
|
706 |
|
|
function createArrayOfTypeChecker(typeChecker) {
|
707 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
708 |
|
|
if (typeof typeChecker !== 'function') {
|
709 |
|
|
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
710 |
|
|
}
|
711 |
|
|
var propValue = props[propName];
|
712 |
|
|
if (!Array.isArray(propValue)) {
|
713 |
|
|
var propType = getPropType(propValue);
|
714 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
715 |
|
|
}
|
716 |
|
|
for (var i = 0; i < propValue.length; i++) {
|
717 |
|
|
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
|
718 |
|
|
if (error instanceof Error) {
|
719 |
|
|
return error;
|
720 |
|
|
}
|
721 |
|
|
}
|
722 |
|
|
return null;
|
723 |
|
|
}
|
724 |
|
|
return createChainableTypeChecker(validate);
|
725 |
|
|
}
|
726 |
|
|
|
727 |
|
|
function createElementTypeChecker() {
|
728 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
729 |
|
|
var propValue = props[propName];
|
730 |
|
|
if (!isValidElement(propValue)) {
|
731 |
|
|
var propType = getPropType(propValue);
|
732 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
733 |
|
|
}
|
734 |
|
|
return null;
|
735 |
|
|
}
|
736 |
|
|
return createChainableTypeChecker(validate);
|
737 |
|
|
}
|
738 |
|
|
|
739 |
|
|
function createElementTypeTypeChecker() {
|
740 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
741 |
|
|
var propValue = props[propName];
|
742 |
|
|
if (!reactIs.isValidElementType(propValue)) {
|
743 |
|
|
var propType = getPropType(propValue);
|
744 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
745 |
|
|
}
|
746 |
|
|
return null;
|
747 |
|
|
}
|
748 |
|
|
return createChainableTypeChecker(validate);
|
749 |
|
|
}
|
750 |
|
|
|
751 |
|
|
function createInstanceTypeChecker(expectedClass) {
|
752 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
753 |
|
|
if (!(props[propName] instanceof expectedClass)) {
|
754 |
|
|
var expectedClassName = expectedClass.name || ANONYMOUS;
|
755 |
|
|
var actualClassName = getClassName(props[propName]);
|
756 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
757 |
|
|
}
|
758 |
|
|
return null;
|
759 |
|
|
}
|
760 |
|
|
return createChainableTypeChecker(validate);
|
761 |
|
|
}
|
762 |
|
|
|
763 |
|
|
function createEnumTypeChecker(expectedValues) {
|
764 |
|
|
if (!Array.isArray(expectedValues)) {
|
765 |
|
|
{
|
766 |
|
|
if (arguments.length > 1) {
|
767 |
|
|
printWarning$1(
|
768 |
|
|
'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
|
769 |
|
|
'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
|
770 |
|
|
);
|
771 |
|
|
} else {
|
772 |
|
|
printWarning$1('Invalid argument supplied to oneOf, expected an array.');
|
773 |
|
|
}
|
774 |
|
|
}
|
775 |
|
|
return emptyFunctionThatReturnsNull;
|
776 |
|
|
}
|
777 |
|
|
|
778 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
779 |
|
|
var propValue = props[propName];
|
780 |
|
|
for (var i = 0; i < expectedValues.length; i++) {
|
781 |
|
|
if (is(propValue, expectedValues[i])) {
|
782 |
|
|
return null;
|
783 |
|
|
}
|
784 |
|
|
}
|
785 |
|
|
|
786 |
|
|
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
|
787 |
|
|
var type = getPreciseType(value);
|
788 |
|
|
if (type === 'symbol') {
|
789 |
|
|
return String(value);
|
790 |
|
|
}
|
791 |
|
|
return value;
|
792 |
|
|
});
|
793 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
794 |
|
|
}
|
795 |
|
|
return createChainableTypeChecker(validate);
|
796 |
|
|
}
|
797 |
|
|
|
798 |
|
|
function createObjectOfTypeChecker(typeChecker) {
|
799 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
800 |
|
|
if (typeof typeChecker !== 'function') {
|
801 |
|
|
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
802 |
|
|
}
|
803 |
|
|
var propValue = props[propName];
|
804 |
|
|
var propType = getPropType(propValue);
|
805 |
|
|
if (propType !== 'object') {
|
806 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
807 |
|
|
}
|
808 |
|
|
for (var key in propValue) {
|
809 |
|
|
if (has$1(propValue, key)) {
|
810 |
|
|
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
811 |
|
|
if (error instanceof Error) {
|
812 |
|
|
return error;
|
813 |
|
|
}
|
814 |
|
|
}
|
815 |
|
|
}
|
816 |
|
|
return null;
|
817 |
|
|
}
|
818 |
|
|
return createChainableTypeChecker(validate);
|
819 |
|
|
}
|
820 |
|
|
|
821 |
|
|
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
822 |
|
|
if (!Array.isArray(arrayOfTypeCheckers)) {
|
823 |
|
|
printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') ;
|
824 |
|
|
return emptyFunctionThatReturnsNull;
|
825 |
|
|
}
|
826 |
|
|
|
827 |
|
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
828 |
|
|
var checker = arrayOfTypeCheckers[i];
|
829 |
|
|
if (typeof checker !== 'function') {
|
830 |
|
|
printWarning$1(
|
831 |
|
|
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
832 |
|
|
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
|
833 |
|
|
);
|
834 |
|
|
return emptyFunctionThatReturnsNull;
|
835 |
|
|
}
|
836 |
|
|
}
|
837 |
|
|
|
838 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
839 |
|
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
840 |
|
|
var checker = arrayOfTypeCheckers[i];
|
841 |
|
|
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
|
842 |
|
|
return null;
|
843 |
|
|
}
|
844 |
|
|
}
|
845 |
|
|
|
846 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
847 |
|
|
}
|
848 |
|
|
return createChainableTypeChecker(validate);
|
849 |
|
|
}
|
850 |
|
|
|
851 |
|
|
function createNodeChecker() {
|
852 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
853 |
|
|
if (!isNode(props[propName])) {
|
854 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
855 |
|
|
}
|
856 |
|
|
return null;
|
857 |
|
|
}
|
858 |
|
|
return createChainableTypeChecker(validate);
|
859 |
|
|
}
|
860 |
|
|
|
861 |
|
|
function createShapeTypeChecker(shapeTypes) {
|
862 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
863 |
|
|
var propValue = props[propName];
|
864 |
|
|
var propType = getPropType(propValue);
|
865 |
|
|
if (propType !== 'object') {
|
866 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
867 |
|
|
}
|
868 |
|
|
for (var key in shapeTypes) {
|
869 |
|
|
var checker = shapeTypes[key];
|
870 |
|
|
if (!checker) {
|
871 |
|
|
continue;
|
872 |
|
|
}
|
873 |
|
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
874 |
|
|
if (error) {
|
875 |
|
|
return error;
|
876 |
|
|
}
|
877 |
|
|
}
|
878 |
|
|
return null;
|
879 |
|
|
}
|
880 |
|
|
return createChainableTypeChecker(validate);
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
function createStrictShapeTypeChecker(shapeTypes) {
|
884 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
885 |
|
|
var propValue = props[propName];
|
886 |
|
|
var propType = getPropType(propValue);
|
887 |
|
|
if (propType !== 'object') {
|
888 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
889 |
|
|
}
|
890 |
|
|
// We need to check all keys in case some are required but missing from
|
891 |
|
|
// props.
|
892 |
|
|
var allKeys = objectAssign({}, props[propName], shapeTypes);
|
893 |
|
|
for (var key in allKeys) {
|
894 |
|
|
var checker = shapeTypes[key];
|
895 |
|
|
if (!checker) {
|
896 |
|
|
return new PropTypeError(
|
897 |
|
|
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
898 |
|
|
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
899 |
|
|
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
900 |
|
|
);
|
901 |
|
|
}
|
902 |
|
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
903 |
|
|
if (error) {
|
904 |
|
|
return error;
|
905 |
|
|
}
|
906 |
|
|
}
|
907 |
|
|
return null;
|
908 |
|
|
}
|
909 |
|
|
|
910 |
|
|
return createChainableTypeChecker(validate);
|
911 |
|
|
}
|
912 |
|
|
|
913 |
|
|
function isNode(propValue) {
|
914 |
|
|
switch (typeof propValue) {
|
915 |
|
|
case 'number':
|
916 |
|
|
case 'string':
|
917 |
|
|
case 'undefined':
|
918 |
|
|
return true;
|
919 |
|
|
case 'boolean':
|
920 |
|
|
return !propValue;
|
921 |
|
|
case 'object':
|
922 |
|
|
if (Array.isArray(propValue)) {
|
923 |
|
|
return propValue.every(isNode);
|
924 |
|
|
}
|
925 |
|
|
if (propValue === null || isValidElement(propValue)) {
|
926 |
|
|
return true;
|
927 |
|
|
}
|
928 |
|
|
|
929 |
|
|
var iteratorFn = getIteratorFn(propValue);
|
930 |
|
|
if (iteratorFn) {
|
931 |
|
|
var iterator = iteratorFn.call(propValue);
|
932 |
|
|
var step;
|
933 |
|
|
if (iteratorFn !== propValue.entries) {
|
934 |
|
|
while (!(step = iterator.next()).done) {
|
935 |
|
|
if (!isNode(step.value)) {
|
936 |
|
|
return false;
|
937 |
|
|
}
|
938 |
|
|
}
|
939 |
|
|
} else {
|
940 |
|
|
// Iterator will provide entry [k,v] tuples rather than values.
|
941 |
|
|
while (!(step = iterator.next()).done) {
|
942 |
|
|
var entry = step.value;
|
943 |
|
|
if (entry) {
|
944 |
|
|
if (!isNode(entry[1])) {
|
945 |
|
|
return false;
|
946 |
|
|
}
|
947 |
|
|
}
|
948 |
|
|
}
|
949 |
|
|
}
|
950 |
|
|
} else {
|
951 |
|
|
return false;
|
952 |
|
|
}
|
953 |
|
|
|
954 |
|
|
return true;
|
955 |
|
|
default:
|
956 |
|
|
return false;
|
957 |
|
|
}
|
958 |
|
|
}
|
959 |
|
|
|
960 |
|
|
function isSymbol(propType, propValue) {
|
961 |
|
|
// Native Symbol.
|
962 |
|
|
if (propType === 'symbol') {
|
963 |
|
|
return true;
|
964 |
|
|
}
|
965 |
|
|
|
966 |
|
|
// falsy value can't be a Symbol
|
967 |
|
|
if (!propValue) {
|
968 |
|
|
return false;
|
969 |
|
|
}
|
970 |
|
|
|
971 |
|
|
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
972 |
|
|
if (propValue['@@toStringTag'] === 'Symbol') {
|
973 |
|
|
return true;
|
974 |
|
|
}
|
975 |
|
|
|
976 |
|
|
// Fallback for non-spec compliant Symbols which are polyfilled.
|
977 |
|
|
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
978 |
|
|
return true;
|
979 |
|
|
}
|
980 |
|
|
|
981 |
|
|
return false;
|
982 |
|
|
}
|
983 |
|
|
|
984 |
|
|
// Equivalent of `typeof` but with special handling for array and regexp.
|
985 |
|
|
function getPropType(propValue) {
|
986 |
|
|
var propType = typeof propValue;
|
987 |
|
|
if (Array.isArray(propValue)) {
|
988 |
|
|
return 'array';
|
989 |
|
|
}
|
990 |
|
|
if (propValue instanceof RegExp) {
|
991 |
|
|
// Old webkits (at least until Android 4.0) return 'function' rather than
|
992 |
|
|
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
993 |
|
|
// passes PropTypes.object.
|
994 |
|
|
return 'object';
|
995 |
|
|
}
|
996 |
|
|
if (isSymbol(propType, propValue)) {
|
997 |
|
|
return 'symbol';
|
998 |
|
|
}
|
999 |
|
|
return propType;
|
1000 |
|
|
}
|
1001 |
|
|
|
1002 |
|
|
// This handles more types than `getPropType`. Only used for error messages.
|
1003 |
|
|
// See `createPrimitiveTypeChecker`.
|
1004 |
|
|
function getPreciseType(propValue) {
|
1005 |
|
|
if (typeof propValue === 'undefined' || propValue === null) {
|
1006 |
|
|
return '' + propValue;
|
1007 |
|
|
}
|
1008 |
|
|
var propType = getPropType(propValue);
|
1009 |
|
|
if (propType === 'object') {
|
1010 |
|
|
if (propValue instanceof Date) {
|
1011 |
|
|
return 'date';
|
1012 |
|
|
} else if (propValue instanceof RegExp) {
|
1013 |
|
|
return 'regexp';
|
1014 |
|
|
}
|
1015 |
|
|
}
|
1016 |
|
|
return propType;
|
1017 |
|
|
}
|
1018 |
|
|
|
1019 |
|
|
// Returns a string that is postfixed to a warning about an invalid type.
|
1020 |
|
|
// For example, "undefined" or "of type array"
|
1021 |
|
|
function getPostfixForTypeWarning(value) {
|
1022 |
|
|
var type = getPreciseType(value);
|
1023 |
|
|
switch (type) {
|
1024 |
|
|
case 'array':
|
1025 |
|
|
case 'object':
|
1026 |
|
|
return 'an ' + type;
|
1027 |
|
|
case 'boolean':
|
1028 |
|
|
case 'date':
|
1029 |
|
|
case 'regexp':
|
1030 |
|
|
return 'a ' + type;
|
1031 |
|
|
default:
|
1032 |
|
|
return type;
|
1033 |
|
|
}
|
1034 |
|
|
}
|
1035 |
|
|
|
1036 |
|
|
// Returns class name of the object, if any.
|
1037 |
|
|
function getClassName(propValue) {
|
1038 |
|
|
if (!propValue.constructor || !propValue.constructor.name) {
|
1039 |
|
|
return ANONYMOUS;
|
1040 |
|
|
}
|
1041 |
|
|
return propValue.constructor.name;
|
1042 |
|
|
}
|
1043 |
|
|
|
1044 |
|
|
ReactPropTypes.checkPropTypes = checkPropTypes_1;
|
1045 |
|
|
ReactPropTypes.resetWarningCache = checkPropTypes_1.resetWarningCache;
|
1046 |
|
|
ReactPropTypes.PropTypes = ReactPropTypes;
|
1047 |
|
|
|
1048 |
|
|
return ReactPropTypes;
|
1049 |
|
|
};
|
1050 |
|
|
|
1051 |
|
|
var propTypes = createCommonjsModule(function (module) {
|
1052 |
|
|
/**
|
1053 |
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
1054 |
|
|
*
|
1055 |
|
|
* This source code is licensed under the MIT license found in the
|
1056 |
|
|
* LICENSE file in the root directory of this source tree.
|
1057 |
|
|
*/
|
1058 |
|
|
|
1059 |
|
|
{
|
1060 |
|
|
var ReactIs = reactIs;
|
1061 |
|
|
|
1062 |
|
|
// By explicitly using `prop-types` you are opting into new development behavior.
|
1063 |
|
|
// http://fb.me/prop-types-in-prod
|
1064 |
|
|
var throwOnDirectAccess = true;
|
1065 |
|
|
module.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess);
|
1066 |
|
|
}
|
1067 |
|
|
});
|
1068 |
|
|
|
1069 |
|
|
var ReactReduxContext =
|
1070 |
|
|
/*#__PURE__*/
|
1071 |
|
|
React__default.createContext(null);
|
1072 |
|
|
|
1073 |
|
|
{
|
1074 |
|
|
ReactReduxContext.displayName = 'ReactRedux';
|
1075 |
|
|
}
|
1076 |
|
|
|
1077 |
|
|
// Default to a dummy "batch" implementation that just runs the callback
|
1078 |
|
|
function defaultNoopBatch(callback) {
|
1079 |
|
|
callback();
|
1080 |
|
|
}
|
1081 |
|
|
|
1082 |
|
|
var batch = defaultNoopBatch; // Allow injecting another batching function later
|
1083 |
|
|
|
1084 |
|
|
var setBatch = function setBatch(newBatch) {
|
1085 |
|
|
return batch = newBatch;
|
1086 |
|
|
}; // Supply a getter just to skip dealing with ESM bindings
|
1087 |
|
|
|
1088 |
|
|
var getBatch = function getBatch() {
|
1089 |
|
|
return batch;
|
1090 |
|
|
};
|
1091 |
|
|
|
1092 |
|
|
// well as nesting subscriptions of descendant components, so that we can ensure the
|
1093 |
|
|
// ancestor components re-render before descendants
|
1094 |
|
|
|
1095 |
|
|
var nullListeners = {
|
1096 |
|
|
notify: function notify() {}
|
1097 |
|
|
};
|
1098 |
|
|
|
1099 |
|
|
function createListenerCollection() {
|
1100 |
|
|
var batch = getBatch();
|
1101 |
|
|
var first = null;
|
1102 |
|
|
var last = null;
|
1103 |
|
|
return {
|
1104 |
|
|
clear: function clear() {
|
1105 |
|
|
first = null;
|
1106 |
|
|
last = null;
|
1107 |
|
|
},
|
1108 |
|
|
notify: function notify() {
|
1109 |
|
|
batch(function () {
|
1110 |
|
|
var listener = first;
|
1111 |
|
|
|
1112 |
|
|
while (listener) {
|
1113 |
|
|
listener.callback();
|
1114 |
|
|
listener = listener.next;
|
1115 |
|
|
}
|
1116 |
|
|
});
|
1117 |
|
|
},
|
1118 |
|
|
get: function get() {
|
1119 |
|
|
var listeners = [];
|
1120 |
|
|
var listener = first;
|
1121 |
|
|
|
1122 |
|
|
while (listener) {
|
1123 |
|
|
listeners.push(listener);
|
1124 |
|
|
listener = listener.next;
|
1125 |
|
|
}
|
1126 |
|
|
|
1127 |
|
|
return listeners;
|
1128 |
|
|
},
|
1129 |
|
|
subscribe: function subscribe(callback) {
|
1130 |
|
|
var isSubscribed = true;
|
1131 |
|
|
var listener = last = {
|
1132 |
|
|
callback: callback,
|
1133 |
|
|
next: null,
|
1134 |
|
|
prev: last
|
1135 |
|
|
};
|
1136 |
|
|
|
1137 |
|
|
if (listener.prev) {
|
1138 |
|
|
listener.prev.next = listener;
|
1139 |
|
|
} else {
|
1140 |
|
|
first = listener;
|
1141 |
|
|
}
|
1142 |
|
|
|
1143 |
|
|
return function unsubscribe() {
|
1144 |
|
|
if (!isSubscribed || first === null) return;
|
1145 |
|
|
isSubscribed = false;
|
1146 |
|
|
|
1147 |
|
|
if (listener.next) {
|
1148 |
|
|
listener.next.prev = listener.prev;
|
1149 |
|
|
} else {
|
1150 |
|
|
last = listener.prev;
|
1151 |
|
|
}
|
1152 |
|
|
|
1153 |
|
|
if (listener.prev) {
|
1154 |
|
|
listener.prev.next = listener.next;
|
1155 |
|
|
} else {
|
1156 |
|
|
first = listener.next;
|
1157 |
|
|
}
|
1158 |
|
|
};
|
1159 |
|
|
}
|
1160 |
|
|
};
|
1161 |
|
|
}
|
1162 |
|
|
|
1163 |
|
|
var Subscription =
|
1164 |
|
|
/*#__PURE__*/
|
1165 |
|
|
function () {
|
1166 |
|
|
function Subscription(store, parentSub) {
|
1167 |
|
|
this.store = store;
|
1168 |
|
|
this.parentSub = parentSub;
|
1169 |
|
|
this.unsubscribe = null;
|
1170 |
|
|
this.listeners = nullListeners;
|
1171 |
|
|
this.handleChangeWrapper = this.handleChangeWrapper.bind(this);
|
1172 |
|
|
}
|
1173 |
|
|
|
1174 |
|
|
var _proto = Subscription.prototype;
|
1175 |
|
|
|
1176 |
|
|
_proto.addNestedSub = function addNestedSub(listener) {
|
1177 |
|
|
this.trySubscribe();
|
1178 |
|
|
return this.listeners.subscribe(listener);
|
1179 |
|
|
};
|
1180 |
|
|
|
1181 |
|
|
_proto.notifyNestedSubs = function notifyNestedSubs() {
|
1182 |
|
|
this.listeners.notify();
|
1183 |
|
|
};
|
1184 |
|
|
|
1185 |
|
|
_proto.handleChangeWrapper = function handleChangeWrapper() {
|
1186 |
|
|
if (this.onStateChange) {
|
1187 |
|
|
this.onStateChange();
|
1188 |
|
|
}
|
1189 |
|
|
};
|
1190 |
|
|
|
1191 |
|
|
_proto.isSubscribed = function isSubscribed() {
|
1192 |
|
|
return Boolean(this.unsubscribe);
|
1193 |
|
|
};
|
1194 |
|
|
|
1195 |
|
|
_proto.trySubscribe = function trySubscribe() {
|
1196 |
|
|
if (!this.unsubscribe) {
|
1197 |
|
|
this.unsubscribe = this.parentSub ? this.parentSub.addNestedSub(this.handleChangeWrapper) : this.store.subscribe(this.handleChangeWrapper);
|
1198 |
|
|
this.listeners = createListenerCollection();
|
1199 |
|
|
}
|
1200 |
|
|
};
|
1201 |
|
|
|
1202 |
|
|
_proto.tryUnsubscribe = function tryUnsubscribe() {
|
1203 |
|
|
if (this.unsubscribe) {
|
1204 |
|
|
this.unsubscribe();
|
1205 |
|
|
this.unsubscribe = null;
|
1206 |
|
|
this.listeners.clear();
|
1207 |
|
|
this.listeners = nullListeners;
|
1208 |
|
|
}
|
1209 |
|
|
};
|
1210 |
|
|
|
1211 |
|
|
return Subscription;
|
1212 |
|
|
}();
|
1213 |
|
|
|
1214 |
|
|
function Provider(_ref) {
|
1215 |
|
|
var store = _ref.store,
|
1216 |
|
|
context = _ref.context,
|
1217 |
|
|
children = _ref.children;
|
1218 |
|
|
var contextValue = React.useMemo(function () {
|
1219 |
|
|
var subscription = new Subscription(store);
|
1220 |
|
|
subscription.onStateChange = subscription.notifyNestedSubs;
|
1221 |
|
|
return {
|
1222 |
|
|
store: store,
|
1223 |
|
|
subscription: subscription
|
1224 |
|
|
};
|
1225 |
|
|
}, [store]);
|
1226 |
|
|
var previousState = React.useMemo(function () {
|
1227 |
|
|
return store.getState();
|
1228 |
|
|
}, [store]);
|
1229 |
|
|
React.useEffect(function () {
|
1230 |
|
|
var subscription = contextValue.subscription;
|
1231 |
|
|
subscription.trySubscribe();
|
1232 |
|
|
|
1233 |
|
|
if (previousState !== store.getState()) {
|
1234 |
|
|
subscription.notifyNestedSubs();
|
1235 |
|
|
}
|
1236 |
|
|
|
1237 |
|
|
return function () {
|
1238 |
|
|
subscription.tryUnsubscribe();
|
1239 |
|
|
subscription.onStateChange = null;
|
1240 |
|
|
};
|
1241 |
|
|
}, [contextValue, previousState]);
|
1242 |
|
|
var Context = context || ReactReduxContext;
|
1243 |
|
|
return React__default.createElement(Context.Provider, {
|
1244 |
|
|
value: contextValue
|
1245 |
|
|
}, children);
|
1246 |
|
|
}
|
1247 |
|
|
|
1248 |
|
|
{
|
1249 |
|
|
Provider.propTypes = {
|
1250 |
|
|
store: propTypes.shape({
|
1251 |
|
|
subscribe: propTypes.func.isRequired,
|
1252 |
|
|
dispatch: propTypes.func.isRequired,
|
1253 |
|
|
getState: propTypes.func.isRequired
|
1254 |
|
|
}),
|
1255 |
|
|
context: propTypes.object,
|
1256 |
|
|
children: propTypes.any
|
1257 |
|
|
};
|
1258 |
|
|
}
|
1259 |
|
|
|
1260 |
|
|
function _extends() {
|
1261 |
|
|
_extends = Object.assign || function (target) {
|
1262 |
|
|
for (var i = 1; i < arguments.length; i++) {
|
1263 |
|
|
var source = arguments[i];
|
1264 |
|
|
|
1265 |
|
|
for (var key in source) {
|
1266 |
|
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1267 |
|
|
target[key] = source[key];
|
1268 |
|
|
}
|
1269 |
|
|
}
|
1270 |
|
|
}
|
1271 |
|
|
|
1272 |
|
|
return target;
|
1273 |
|
|
};
|
1274 |
|
|
|
1275 |
|
|
return _extends.apply(this, arguments);
|
1276 |
|
|
}
|
1277 |
|
|
|
1278 |
|
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
1279 |
|
|
if (source == null) return {};
|
1280 |
|
|
var target = {};
|
1281 |
|
|
var sourceKeys = Object.keys(source);
|
1282 |
|
|
var key, i;
|
1283 |
|
|
|
1284 |
|
|
for (i = 0; i < sourceKeys.length; i++) {
|
1285 |
|
|
key = sourceKeys[i];
|
1286 |
|
|
if (excluded.indexOf(key) >= 0) continue;
|
1287 |
|
|
target[key] = source[key];
|
1288 |
|
|
}
|
1289 |
|
|
|
1290 |
|
|
return target;
|
1291 |
|
|
}
|
1292 |
|
|
|
1293 |
|
|
/**
|
1294 |
|
|
* Copyright 2015, Yahoo! Inc.
|
1295 |
|
|
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
|
1296 |
|
|
*/
|
1297 |
|
|
|
1298 |
|
|
var REACT_STATICS = {
|
1299 |
|
|
childContextTypes: true,
|
1300 |
|
|
contextType: true,
|
1301 |
|
|
contextTypes: true,
|
1302 |
|
|
defaultProps: true,
|
1303 |
|
|
displayName: true,
|
1304 |
|
|
getDefaultProps: true,
|
1305 |
|
|
getDerivedStateFromError: true,
|
1306 |
|
|
getDerivedStateFromProps: true,
|
1307 |
|
|
mixins: true,
|
1308 |
|
|
propTypes: true,
|
1309 |
|
|
type: true
|
1310 |
|
|
};
|
1311 |
|
|
|
1312 |
|
|
var KNOWN_STATICS = {
|
1313 |
|
|
name: true,
|
1314 |
|
|
length: true,
|
1315 |
|
|
prototype: true,
|
1316 |
|
|
caller: true,
|
1317 |
|
|
callee: true,
|
1318 |
|
|
arguments: true,
|
1319 |
|
|
arity: true
|
1320 |
|
|
};
|
1321 |
|
|
|
1322 |
|
|
var FORWARD_REF_STATICS = {
|
1323 |
|
|
'$$typeof': true,
|
1324 |
|
|
render: true,
|
1325 |
|
|
defaultProps: true,
|
1326 |
|
|
displayName: true,
|
1327 |
|
|
propTypes: true
|
1328 |
|
|
};
|
1329 |
|
|
|
1330 |
|
|
var MEMO_STATICS = {
|
1331 |
|
|
'$$typeof': true,
|
1332 |
|
|
compare: true,
|
1333 |
|
|
defaultProps: true,
|
1334 |
|
|
displayName: true,
|
1335 |
|
|
propTypes: true,
|
1336 |
|
|
type: true
|
1337 |
|
|
};
|
1338 |
|
|
|
1339 |
|
|
var TYPE_STATICS = {};
|
1340 |
|
|
TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS;
|
1341 |
|
|
|
1342 |
|
|
function getStatics(component) {
|
1343 |
|
|
if (reactIs.isMemo(component)) {
|
1344 |
|
|
return MEMO_STATICS;
|
1345 |
|
|
}
|
1346 |
|
|
return TYPE_STATICS[component['$$typeof']] || REACT_STATICS;
|
1347 |
|
|
}
|
1348 |
|
|
|
1349 |
|
|
var defineProperty = Object.defineProperty;
|
1350 |
|
|
var getOwnPropertyNames = Object.getOwnPropertyNames;
|
1351 |
|
|
var getOwnPropertySymbols$1 = Object.getOwnPropertySymbols;
|
1352 |
|
|
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
1353 |
|
|
var getPrototypeOf = Object.getPrototypeOf;
|
1354 |
|
|
var objectPrototype = Object.prototype;
|
1355 |
|
|
|
1356 |
|
|
function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
1357 |
|
|
if (typeof sourceComponent !== 'string') {
|
1358 |
|
|
// don't hoist over string (html) components
|
1359 |
|
|
|
1360 |
|
|
if (objectPrototype) {
|
1361 |
|
|
var inheritedComponent = getPrototypeOf(sourceComponent);
|
1362 |
|
|
if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
1363 |
|
|
hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
1364 |
|
|
}
|
1365 |
|
|
}
|
1366 |
|
|
|
1367 |
|
|
var keys = getOwnPropertyNames(sourceComponent);
|
1368 |
|
|
|
1369 |
|
|
if (getOwnPropertySymbols$1) {
|
1370 |
|
|
keys = keys.concat(getOwnPropertySymbols$1(sourceComponent));
|
1371 |
|
|
}
|
1372 |
|
|
|
1373 |
|
|
var targetStatics = getStatics(targetComponent);
|
1374 |
|
|
var sourceStatics = getStatics(sourceComponent);
|
1375 |
|
|
|
1376 |
|
|
for (var i = 0; i < keys.length; ++i) {
|
1377 |
|
|
var key = keys[i];
|
1378 |
|
|
if (!KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
|
1379 |
|
|
var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
1380 |
|
|
try {
|
1381 |
|
|
// Avoid failures from read-only properties
|
1382 |
|
|
defineProperty(targetComponent, key, descriptor);
|
1383 |
|
|
} catch (e) {}
|
1384 |
|
|
}
|
1385 |
|
|
}
|
1386 |
|
|
|
1387 |
|
|
return targetComponent;
|
1388 |
|
|
}
|
1389 |
|
|
|
1390 |
|
|
return targetComponent;
|
1391 |
|
|
}
|
1392 |
|
|
|
1393 |
|
|
var hoistNonReactStatics_cjs = hoistNonReactStatics;
|
1394 |
|
|
|
1395 |
|
|
// To get around it, we can conditionally useEffect on the server (no-op) and
|
1396 |
|
|
// useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
|
1397 |
|
|
// subscription callback always has the selector from the latest render commit
|
1398 |
|
|
// available, otherwise a store update may happen between render and the effect,
|
1399 |
|
|
// which may cause missed updates; we also must ensure the store subscription
|
1400 |
|
|
// is created synchronously, otherwise a store update may occur before the
|
1401 |
|
|
// subscription is created and an inconsistent state may be observed
|
1402 |
|
|
|
1403 |
|
|
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
1404 |
|
|
|
1405 |
|
|
var EMPTY_ARRAY = [];
|
1406 |
|
|
var NO_SUBSCRIPTION_ARRAY = [null, null];
|
1407 |
|
|
|
1408 |
|
|
var stringifyComponent = function stringifyComponent(Comp) {
|
1409 |
|
|
try {
|
1410 |
|
|
return JSON.stringify(Comp);
|
1411 |
|
|
} catch (err) {
|
1412 |
|
|
return String(Comp);
|
1413 |
|
|
}
|
1414 |
|
|
};
|
1415 |
|
|
|
1416 |
|
|
function storeStateUpdatesReducer(state, action) {
|
1417 |
|
|
var updateCount = state[1];
|
1418 |
|
|
return [action.payload, updateCount + 1];
|
1419 |
|
|
}
|
1420 |
|
|
|
1421 |
|
|
function useIsomorphicLayoutEffectWithArgs(effectFunc, effectArgs, dependencies) {
|
1422 |
|
|
useIsomorphicLayoutEffect(function () {
|
1423 |
|
|
return effectFunc.apply(void 0, effectArgs);
|
1424 |
|
|
}, dependencies);
|
1425 |
|
|
}
|
1426 |
|
|
|
1427 |
|
|
function captureWrapperProps(lastWrapperProps, lastChildProps, renderIsScheduled, wrapperProps, actualChildProps, childPropsFromStoreUpdate, notifyNestedSubs) {
|
1428 |
|
|
// We want to capture the wrapper props and child props we used for later comparisons
|
1429 |
|
|
lastWrapperProps.current = wrapperProps;
|
1430 |
|
|
lastChildProps.current = actualChildProps;
|
1431 |
|
|
renderIsScheduled.current = false; // If the render was from a store update, clear out that reference and cascade the subscriber update
|
1432 |
|
|
|
1433 |
|
|
if (childPropsFromStoreUpdate.current) {
|
1434 |
|
|
childPropsFromStoreUpdate.current = null;
|
1435 |
|
|
notifyNestedSubs();
|
1436 |
|
|
}
|
1437 |
|
|
}
|
1438 |
|
|
|
1439 |
|
|
function subscribeUpdates(shouldHandleStateChanges, store, subscription, childPropsSelector, lastWrapperProps, lastChildProps, renderIsScheduled, childPropsFromStoreUpdate, notifyNestedSubs, forceComponentUpdateDispatch) {
|
1440 |
|
|
// If we're not subscribed to the store, nothing to do here
|
1441 |
|
|
if (!shouldHandleStateChanges) return; // Capture values for checking if and when this component unmounts
|
1442 |
|
|
|
1443 |
|
|
var didUnsubscribe = false;
|
1444 |
|
|
var lastThrownError = null; // We'll run this callback every time a store subscription update propagates to this component
|
1445 |
|
|
|
1446 |
|
|
var checkForUpdates = function checkForUpdates() {
|
1447 |
|
|
if (didUnsubscribe) {
|
1448 |
|
|
// Don't run stale listeners.
|
1449 |
|
|
// Redux doesn't guarantee unsubscriptions happen until next dispatch.
|
1450 |
|
|
return;
|
1451 |
|
|
}
|
1452 |
|
|
|
1453 |
|
|
var latestStoreState = store.getState();
|
1454 |
|
|
var newChildProps, error;
|
1455 |
|
|
|
1456 |
|
|
try {
|
1457 |
|
|
// Actually run the selector with the most recent store state and wrapper props
|
1458 |
|
|
// to determine what the child props should be
|
1459 |
|
|
newChildProps = childPropsSelector(latestStoreState, lastWrapperProps.current);
|
1460 |
|
|
} catch (e) {
|
1461 |
|
|
error = e;
|
1462 |
|
|
lastThrownError = e;
|
1463 |
|
|
}
|
1464 |
|
|
|
1465 |
|
|
if (!error) {
|
1466 |
|
|
lastThrownError = null;
|
1467 |
|
|
} // If the child props haven't changed, nothing to do here - cascade the subscription update
|
1468 |
|
|
|
1469 |
|
|
|
1470 |
|
|
if (newChildProps === lastChildProps.current) {
|
1471 |
|
|
if (!renderIsScheduled.current) {
|
1472 |
|
|
notifyNestedSubs();
|
1473 |
|
|
}
|
1474 |
|
|
} else {
|
1475 |
|
|
// Save references to the new child props. Note that we track the "child props from store update"
|
1476 |
|
|
// as a ref instead of a useState/useReducer because we need a way to determine if that value has
|
1477 |
|
|
// been processed. If this went into useState/useReducer, we couldn't clear out the value without
|
1478 |
|
|
// forcing another re-render, which we don't want.
|
1479 |
|
|
lastChildProps.current = newChildProps;
|
1480 |
|
|
childPropsFromStoreUpdate.current = newChildProps;
|
1481 |
|
|
renderIsScheduled.current = true; // If the child props _did_ change (or we caught an error), this wrapper component needs to re-render
|
1482 |
|
|
|
1483 |
|
|
forceComponentUpdateDispatch({
|
1484 |
|
|
type: 'STORE_UPDATED',
|
1485 |
|
|
payload: {
|
1486 |
|
|
error: error
|
1487 |
|
|
}
|
1488 |
|
|
});
|
1489 |
|
|
}
|
1490 |
|
|
}; // Actually subscribe to the nearest connected ancestor (or store)
|
1491 |
|
|
|
1492 |
|
|
|
1493 |
|
|
subscription.onStateChange = checkForUpdates;
|
1494 |
|
|
subscription.trySubscribe(); // Pull data from the store after first render in case the store has
|
1495 |
|
|
// changed since we began.
|
1496 |
|
|
|
1497 |
|
|
checkForUpdates();
|
1498 |
|
|
|
1499 |
|
|
var unsubscribeWrapper = function unsubscribeWrapper() {
|
1500 |
|
|
didUnsubscribe = true;
|
1501 |
|
|
subscription.tryUnsubscribe();
|
1502 |
|
|
subscription.onStateChange = null;
|
1503 |
|
|
|
1504 |
|
|
if (lastThrownError) {
|
1505 |
|
|
// It's possible that we caught an error due to a bad mapState function, but the
|
1506 |
|
|
// parent re-rendered without this component and we're about to unmount.
|
1507 |
|
|
// This shouldn't happen as long as we do top-down subscriptions correctly, but
|
1508 |
|
|
// if we ever do those wrong, this throw will surface the error in our tests.
|
1509 |
|
|
// In that case, throw the error from here so it doesn't get lost.
|
1510 |
|
|
throw lastThrownError;
|
1511 |
|
|
}
|
1512 |
|
|
};
|
1513 |
|
|
|
1514 |
|
|
return unsubscribeWrapper;
|
1515 |
|
|
}
|
1516 |
|
|
|
1517 |
|
|
var initStateUpdates = function initStateUpdates() {
|
1518 |
|
|
return [null, 0];
|
1519 |
|
|
};
|
1520 |
|
|
|
1521 |
|
|
function connectAdvanced(
|
1522 |
|
|
/*
|
1523 |
|
|
selectorFactory is a func that is responsible for returning the selector function used to
|
1524 |
|
|
compute new props from state, props, and dispatch. For example:
|
1525 |
|
|
export default connectAdvanced((dispatch, options) => (state, props) => ({
|
1526 |
|
|
thing: state.things[props.thingId],
|
1527 |
|
|
saveThing: fields => dispatch(actionCreators.saveThing(props.thingId, fields)),
|
1528 |
|
|
}))(YourComponent)
|
1529 |
|
|
Access to dispatch is provided to the factory so selectorFactories can bind actionCreators
|
1530 |
|
|
outside of their selector as an optimization. Options passed to connectAdvanced are passed to
|
1531 |
|
|
the selectorFactory, along with displayName and WrappedComponent, as the second argument.
|
1532 |
|
|
Note that selectorFactory is responsible for all caching/memoization of inbound and outbound
|
1533 |
|
|
props. Do not use connectAdvanced directly without memoizing results between calls to your
|
1534 |
|
|
selector, otherwise the Connect component will re-render on every state or props change.
|
1535 |
|
|
*/
|
1536 |
|
|
selectorFactory, // options object:
|
1537 |
|
|
_ref) {
|
1538 |
|
|
if (_ref === void 0) {
|
1539 |
|
|
_ref = {};
|
1540 |
|
|
}
|
1541 |
|
|
|
1542 |
|
|
var _ref2 = _ref,
|
1543 |
|
|
_ref2$getDisplayName = _ref2.getDisplayName,
|
1544 |
|
|
getDisplayName = _ref2$getDisplayName === void 0 ? function (name) {
|
1545 |
|
|
return "ConnectAdvanced(" + name + ")";
|
1546 |
|
|
} : _ref2$getDisplayName,
|
1547 |
|
|
_ref2$methodName = _ref2.methodName,
|
1548 |
|
|
methodName = _ref2$methodName === void 0 ? 'connectAdvanced' : _ref2$methodName,
|
1549 |
|
|
_ref2$renderCountProp = _ref2.renderCountProp,
|
1550 |
|
|
renderCountProp = _ref2$renderCountProp === void 0 ? undefined : _ref2$renderCountProp,
|
1551 |
|
|
_ref2$shouldHandleSta = _ref2.shouldHandleStateChanges,
|
1552 |
|
|
shouldHandleStateChanges = _ref2$shouldHandleSta === void 0 ? true : _ref2$shouldHandleSta,
|
1553 |
|
|
_ref2$storeKey = _ref2.storeKey,
|
1554 |
|
|
storeKey = _ref2$storeKey === void 0 ? 'store' : _ref2$storeKey,
|
1555 |
|
|
_ref2$withRef = _ref2.withRef,
|
1556 |
|
|
withRef = _ref2$withRef === void 0 ? false : _ref2$withRef,
|
1557 |
|
|
_ref2$forwardRef = _ref2.forwardRef,
|
1558 |
|
|
forwardRef = _ref2$forwardRef === void 0 ? false : _ref2$forwardRef,
|
1559 |
|
|
_ref2$context = _ref2.context,
|
1560 |
|
|
context = _ref2$context === void 0 ? ReactReduxContext : _ref2$context,
|
1561 |
|
|
connectOptions = _objectWithoutPropertiesLoose(_ref2, ["getDisplayName", "methodName", "renderCountProp", "shouldHandleStateChanges", "storeKey", "withRef", "forwardRef", "context"]);
|
1562 |
|
|
|
1563 |
|
|
{
|
1564 |
|
|
if (renderCountProp !== undefined) {
|
1565 |
|
|
throw new Error("renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension");
|
1566 |
|
|
}
|
1567 |
|
|
|
1568 |
|
|
if (withRef) {
|
1569 |
|
|
throw new Error('withRef is removed. To access the wrapped instance, use a ref on the connected component');
|
1570 |
|
|
}
|
1571 |
|
|
|
1572 |
|
|
var customStoreWarningMessage = 'To use a custom Redux store for specific components, create a custom React context with ' + "React.createContext(), and pass the context object to React Redux's Provider and specific components" + ' like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. ' + 'You may also pass a {context : MyContext} option to connect';
|
1573 |
|
|
|
1574 |
|
|
if (storeKey !== 'store') {
|
1575 |
|
|
throw new Error('storeKey has been removed and does not do anything. ' + customStoreWarningMessage);
|
1576 |
|
|
}
|
1577 |
|
|
}
|
1578 |
|
|
|
1579 |
|
|
var Context = context;
|
1580 |
|
|
return function wrapWithConnect(WrappedComponent) {
|
1581 |
|
|
if ( !reactIs_1(WrappedComponent)) {
|
1582 |
|
|
throw new Error("You must pass a component to the function returned by " + (methodName + ". Instead received " + stringifyComponent(WrappedComponent)));
|
1583 |
|
|
}
|
1584 |
|
|
|
1585 |
|
|
var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
1586 |
|
|
var displayName = getDisplayName(wrappedComponentName);
|
1587 |
|
|
|
1588 |
|
|
var selectorFactoryOptions = _extends({}, connectOptions, {
|
1589 |
|
|
getDisplayName: getDisplayName,
|
1590 |
|
|
methodName: methodName,
|
1591 |
|
|
renderCountProp: renderCountProp,
|
1592 |
|
|
shouldHandleStateChanges: shouldHandleStateChanges,
|
1593 |
|
|
storeKey: storeKey,
|
1594 |
|
|
displayName: displayName,
|
1595 |
|
|
wrappedComponentName: wrappedComponentName,
|
1596 |
|
|
WrappedComponent: WrappedComponent
|
1597 |
|
|
});
|
1598 |
|
|
|
1599 |
|
|
var pure = connectOptions.pure;
|
1600 |
|
|
|
1601 |
|
|
function createChildSelector(store) {
|
1602 |
|
|
return selectorFactory(store.dispatch, selectorFactoryOptions);
|
1603 |
|
|
} // If we aren't running in "pure" mode, we don't want to memoize values.
|
1604 |
|
|
// To avoid conditionally calling hooks, we fall back to a tiny wrapper
|
1605 |
|
|
// that just executes the given callback immediately.
|
1606 |
|
|
|
1607 |
|
|
|
1608 |
|
|
var usePureOnlyMemo = pure ? React.useMemo : function (callback) {
|
1609 |
|
|
return callback();
|
1610 |
|
|
};
|
1611 |
|
|
|
1612 |
|
|
function ConnectFunction(props) {
|
1613 |
|
|
var _useMemo = React.useMemo(function () {
|
1614 |
|
|
// Distinguish between actual "data" props that were passed to the wrapper component,
|
1615 |
|
|
// and values needed to control behavior (forwarded refs, alternate context instances).
|
1616 |
|
|
// To maintain the wrapperProps object reference, memoize this destructuring.
|
1617 |
|
|
var forwardedRef = props.forwardedRef,
|
1618 |
|
|
wrapperProps = _objectWithoutPropertiesLoose(props, ["forwardedRef"]);
|
1619 |
|
|
|
1620 |
|
|
return [props.context, forwardedRef, wrapperProps];
|
1621 |
|
|
}, [props]),
|
1622 |
|
|
propsContext = _useMemo[0],
|
1623 |
|
|
forwardedRef = _useMemo[1],
|
1624 |
|
|
wrapperProps = _useMemo[2];
|
1625 |
|
|
|
1626 |
|
|
var ContextToUse = React.useMemo(function () {
|
1627 |
|
|
// Users may optionally pass in a custom context instance to use instead of our ReactReduxContext.
|
1628 |
|
|
// Memoize the check that determines which context instance we should use.
|
1629 |
|
|
return propsContext && propsContext.Consumer && reactIs_2(React__default.createElement(propsContext.Consumer, null)) ? propsContext : Context;
|
1630 |
|
|
}, [propsContext, Context]); // Retrieve the store and ancestor subscription via context, if available
|
1631 |
|
|
|
1632 |
|
|
var contextValue = React.useContext(ContextToUse); // The store _must_ exist as either a prop or in context.
|
1633 |
|
|
// We'll check to see if it _looks_ like a Redux store first.
|
1634 |
|
|
// This allows us to pass through a `store` prop that is just a plain value.
|
1635 |
|
|
|
1636 |
|
|
var didStoreComeFromProps = Boolean(props.store) && Boolean(props.store.getState) && Boolean(props.store.dispatch);
|
1637 |
|
|
var didStoreComeFromContext = Boolean(contextValue) && Boolean(contextValue.store);
|
1638 |
|
|
|
1639 |
|
|
if ( !didStoreComeFromProps && !didStoreComeFromContext) {
|
1640 |
|
|
throw new Error("Could not find \"store\" in the context of " + ("\"" + displayName + "\". Either wrap the root component in a <Provider>, ") + "or pass a custom React context provider to <Provider> and the corresponding " + ("React context consumer to " + displayName + " in connect options."));
|
1641 |
|
|
} // Based on the previous check, one of these must be true
|
1642 |
|
|
|
1643 |
|
|
|
1644 |
|
|
var store = didStoreComeFromProps ? props.store : contextValue.store;
|
1645 |
|
|
var childPropsSelector = React.useMemo(function () {
|
1646 |
|
|
// The child props selector needs the store reference as an input.
|
1647 |
|
|
// Re-create this selector whenever the store changes.
|
1648 |
|
|
return createChildSelector(store);
|
1649 |
|
|
}, [store]);
|
1650 |
|
|
|
1651 |
|
|
var _useMemo2 = React.useMemo(function () {
|
1652 |
|
|
if (!shouldHandleStateChanges) return NO_SUBSCRIPTION_ARRAY; // This Subscription's source should match where store came from: props vs. context. A component
|
1653 |
|
|
// connected to the store via props shouldn't use subscription from context, or vice versa.
|
1654 |
|
|
|
1655 |
|
|
var subscription = new Subscription(store, didStoreComeFromProps ? null : contextValue.subscription); // `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in
|
1656 |
|
|
// the middle of the notification loop, where `subscription` will then be null. This can
|
1657 |
|
|
// probably be avoided if Subscription's listeners logic is changed to not call listeners
|
1658 |
|
|
// that have been unsubscribed in the middle of the notification loop.
|
1659 |
|
|
|
1660 |
|
|
var notifyNestedSubs = subscription.notifyNestedSubs.bind(subscription);
|
1661 |
|
|
return [subscription, notifyNestedSubs];
|
1662 |
|
|
}, [store, didStoreComeFromProps, contextValue]),
|
1663 |
|
|
subscription = _useMemo2[0],
|
1664 |
|
|
notifyNestedSubs = _useMemo2[1]; // Determine what {store, subscription} value should be put into nested context, if necessary,
|
1665 |
|
|
// and memoize that value to avoid unnecessary context updates.
|
1666 |
|
|
|
1667 |
|
|
|
1668 |
|
|
var overriddenContextValue = React.useMemo(function () {
|
1669 |
|
|
if (didStoreComeFromProps) {
|
1670 |
|
|
// This component is directly subscribed to a store from props.
|
1671 |
|
|
// We don't want descendants reading from this store - pass down whatever
|
1672 |
|
|
// the existing context value is from the nearest connected ancestor.
|
1673 |
|
|
return contextValue;
|
1674 |
|
|
} // Otherwise, put this component's subscription instance into context, so that
|
1675 |
|
|
// connected descendants won't update until after this component is done
|
1676 |
|
|
|
1677 |
|
|
|
1678 |
|
|
return _extends({}, contextValue, {
|
1679 |
|
|
subscription: subscription
|
1680 |
|
|
});
|
1681 |
|
|
}, [didStoreComeFromProps, contextValue, subscription]); // We need to force this wrapper component to re-render whenever a Redux store update
|
1682 |
|
|
// causes a change to the calculated child component props (or we caught an error in mapState)
|
1683 |
|
|
|
1684 |
|
|
var _useReducer = React.useReducer(storeStateUpdatesReducer, EMPTY_ARRAY, initStateUpdates),
|
1685 |
|
|
_useReducer$ = _useReducer[0],
|
1686 |
|
|
previousStateUpdateResult = _useReducer$[0],
|
1687 |
|
|
forceComponentUpdateDispatch = _useReducer[1]; // Propagate any mapState/mapDispatch errors upwards
|
1688 |
|
|
|
1689 |
|
|
|
1690 |
|
|
if (previousStateUpdateResult && previousStateUpdateResult.error) {
|
1691 |
|
|
throw previousStateUpdateResult.error;
|
1692 |
|
|
} // Set up refs to coordinate values between the subscription effect and the render logic
|
1693 |
|
|
|
1694 |
|
|
|
1695 |
|
|
var lastChildProps = React.useRef();
|
1696 |
|
|
var lastWrapperProps = React.useRef(wrapperProps);
|
1697 |
|
|
var childPropsFromStoreUpdate = React.useRef();
|
1698 |
|
|
var renderIsScheduled = React.useRef(false);
|
1699 |
|
|
var actualChildProps = usePureOnlyMemo(function () {
|
1700 |
|
|
// Tricky logic here:
|
1701 |
|
|
// - This render may have been triggered by a Redux store update that produced new child props
|
1702 |
|
|
// - However, we may have gotten new wrapper props after that
|
1703 |
|
|
// If we have new child props, and the same wrapper props, we know we should use the new child props as-is.
|
1704 |
|
|
// But, if we have new wrapper props, those might change the child props, so we have to recalculate things.
|
1705 |
|
|
// So, we'll use the child props from store update only if the wrapper props are the same as last time.
|
1706 |
|
|
if (childPropsFromStoreUpdate.current && wrapperProps === lastWrapperProps.current) {
|
1707 |
|
|
return childPropsFromStoreUpdate.current;
|
1708 |
|
|
} // TODO We're reading the store directly in render() here. Bad idea?
|
1709 |
|
|
// This will likely cause Bad Things (TM) to happen in Concurrent Mode.
|
1710 |
|
|
// Note that we do this because on renders _not_ caused by store updates, we need the latest store state
|
1711 |
|
|
// to determine what the child props should be.
|
1712 |
|
|
|
1713 |
|
|
|
1714 |
|
|
return childPropsSelector(store.getState(), wrapperProps);
|
1715 |
|
|
}, [store, previousStateUpdateResult, wrapperProps]); // We need this to execute synchronously every time we re-render. However, React warns
|
1716 |
|
|
// about useLayoutEffect in SSR, so we try to detect environment and fall back to
|
1717 |
|
|
// just useEffect instead to avoid the warning, since neither will run anyway.
|
1718 |
|
|
|
1719 |
|
|
useIsomorphicLayoutEffectWithArgs(captureWrapperProps, [lastWrapperProps, lastChildProps, renderIsScheduled, wrapperProps, actualChildProps, childPropsFromStoreUpdate, notifyNestedSubs]); // Our re-subscribe logic only runs when the store/subscription setup changes
|
1720 |
|
|
|
1721 |
|
|
useIsomorphicLayoutEffectWithArgs(subscribeUpdates, [shouldHandleStateChanges, store, subscription, childPropsSelector, lastWrapperProps, lastChildProps, renderIsScheduled, childPropsFromStoreUpdate, notifyNestedSubs, forceComponentUpdateDispatch], [store, subscription, childPropsSelector]); // Now that all that's done, we can finally try to actually render the child component.
|
1722 |
|
|
// We memoize the elements for the rendered child component as an optimization.
|
1723 |
|
|
|
1724 |
|
|
var renderedWrappedComponent = React.useMemo(function () {
|
1725 |
|
|
return React__default.createElement(WrappedComponent, _extends({}, actualChildProps, {
|
1726 |
|
|
ref: forwardedRef
|
1727 |
|
|
}));
|
1728 |
|
|
}, [forwardedRef, WrappedComponent, actualChildProps]); // If React sees the exact same element reference as last time, it bails out of re-rendering
|
1729 |
|
|
// that child, same as if it was wrapped in React.memo() or returned false from shouldComponentUpdate.
|
1730 |
|
|
|
1731 |
|
|
var renderedChild = React.useMemo(function () {
|
1732 |
|
|
if (shouldHandleStateChanges) {
|
1733 |
|
|
// If this component is subscribed to store updates, we need to pass its own
|
1734 |
|
|
// subscription instance down to our descendants. That means rendering the same
|
1735 |
|
|
// Context instance, and putting a different value into the context.
|
1736 |
|
|
return React__default.createElement(ContextToUse.Provider, {
|
1737 |
|
|
value: overriddenContextValue
|
1738 |
|
|
}, renderedWrappedComponent);
|
1739 |
|
|
}
|
1740 |
|
|
|
1741 |
|
|
return renderedWrappedComponent;
|
1742 |
|
|
}, [ContextToUse, renderedWrappedComponent, overriddenContextValue]);
|
1743 |
|
|
return renderedChild;
|
1744 |
|
|
} // If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
|
1745 |
|
|
|
1746 |
|
|
|
1747 |
|
|
var Connect = pure ? React__default.memo(ConnectFunction) : ConnectFunction;
|
1748 |
|
|
Connect.WrappedComponent = WrappedComponent;
|
1749 |
|
|
Connect.displayName = displayName;
|
1750 |
|
|
|
1751 |
|
|
if (forwardRef) {
|
1752 |
|
|
var forwarded = React__default.forwardRef(function forwardConnectRef(props, ref) {
|
1753 |
|
|
return React__default.createElement(Connect, _extends({}, props, {
|
1754 |
|
|
forwardedRef: ref
|
1755 |
|
|
}));
|
1756 |
|
|
});
|
1757 |
|
|
forwarded.displayName = displayName;
|
1758 |
|
|
forwarded.WrappedComponent = WrappedComponent;
|
1759 |
|
|
return hoistNonReactStatics_cjs(forwarded, WrappedComponent);
|
1760 |
|
|
}
|
1761 |
|
|
|
1762 |
|
|
return hoistNonReactStatics_cjs(Connect, WrappedComponent);
|
1763 |
|
|
};
|
1764 |
|
|
}
|
1765 |
|
|
|
1766 |
|
|
function is(x, y) {
|
1767 |
|
|
if (x === y) {
|
1768 |
|
|
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
1769 |
|
|
} else {
|
1770 |
|
|
return x !== x && y !== y;
|
1771 |
|
|
}
|
1772 |
|
|
}
|
1773 |
|
|
|
1774 |
|
|
function shallowEqual(objA, objB) {
|
1775 |
|
|
if (is(objA, objB)) return true;
|
1776 |
|
|
|
1777 |
|
|
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
1778 |
|
|
return false;
|
1779 |
|
|
}
|
1780 |
|
|
|
1781 |
|
|
var keysA = Object.keys(objA);
|
1782 |
|
|
var keysB = Object.keys(objB);
|
1783 |
|
|
if (keysA.length !== keysB.length) return false;
|
1784 |
|
|
|
1785 |
|
|
for (var i = 0; i < keysA.length; i++) {
|
1786 |
|
|
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
1787 |
|
|
return false;
|
1788 |
|
|
}
|
1789 |
|
|
}
|
1790 |
|
|
|
1791 |
|
|
return true;
|
1792 |
|
|
}
|
1793 |
|
|
|
1794 |
|
|
/**
|
1795 |
|
|
* @param {any} obj The object to inspect.
|
1796 |
|
|
* @returns {boolean} True if the argument appears to be a plain object.
|
1797 |
|
|
*/
|
1798 |
|
|
function isPlainObject(obj) {
|
1799 |
|
|
if (typeof obj !== 'object' || obj === null) return false;
|
1800 |
|
|
var proto = Object.getPrototypeOf(obj);
|
1801 |
|
|
if (proto === null) return true;
|
1802 |
|
|
var baseProto = proto;
|
1803 |
|
|
|
1804 |
|
|
while (Object.getPrototypeOf(baseProto) !== null) {
|
1805 |
|
|
baseProto = Object.getPrototypeOf(baseProto);
|
1806 |
|
|
}
|
1807 |
|
|
|
1808 |
|
|
return proto === baseProto;
|
1809 |
|
|
}
|
1810 |
|
|
|
1811 |
|
|
/**
|
1812 |
|
|
* Prints a warning in the console if it exists.
|
1813 |
|
|
*
|
1814 |
|
|
* @param {String} message The warning message.
|
1815 |
|
|
* @returns {void}
|
1816 |
|
|
*/
|
1817 |
|
|
function warning(message) {
|
1818 |
|
|
/* eslint-disable no-console */
|
1819 |
|
|
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
1820 |
|
|
console.error(message);
|
1821 |
|
|
}
|
1822 |
|
|
/* eslint-enable no-console */
|
1823 |
|
|
|
1824 |
|
|
|
1825 |
|
|
try {
|
1826 |
|
|
// This error was thrown as a convenience so that if you enable
|
1827 |
|
|
// "break on all exceptions" in your console,
|
1828 |
|
|
// it would pause the execution at this line.
|
1829 |
|
|
throw new Error(message);
|
1830 |
|
|
/* eslint-disable no-empty */
|
1831 |
|
|
} catch (e) {}
|
1832 |
|
|
/* eslint-enable no-empty */
|
1833 |
|
|
|
1834 |
|
|
}
|
1835 |
|
|
|
1836 |
|
|
function verifyPlainObject(value, displayName, methodName) {
|
1837 |
|
|
if (!isPlainObject(value)) {
|
1838 |
|
|
warning(methodName + "() in " + displayName + " must return a plain object. Instead received " + value + ".");
|
1839 |
|
|
}
|
1840 |
|
|
}
|
1841 |
|
|
|
1842 |
|
|
function wrapMapToPropsConstant(getConstant) {
|
1843 |
|
|
return function initConstantSelector(dispatch, options) {
|
1844 |
|
|
var constant = getConstant(dispatch, options);
|
1845 |
|
|
|
1846 |
|
|
function constantSelector() {
|
1847 |
|
|
return constant;
|
1848 |
|
|
}
|
1849 |
|
|
|
1850 |
|
|
constantSelector.dependsOnOwnProps = false;
|
1851 |
|
|
return constantSelector;
|
1852 |
|
|
};
|
1853 |
|
|
} // dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args
|
1854 |
|
|
// to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine
|
1855 |
|
|
// whether mapToProps needs to be invoked when props have changed.
|
1856 |
|
|
//
|
1857 |
|
|
// A length of one signals that mapToProps does not depend on props from the parent component.
|
1858 |
|
|
// A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and
|
1859 |
|
|
// therefore not reporting its length accurately..
|
1860 |
|
|
|
1861 |
|
|
function getDependsOnOwnProps(mapToProps) {
|
1862 |
|
|
return mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1;
|
1863 |
|
|
} // Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction,
|
1864 |
|
|
// this function wraps mapToProps in a proxy function which does several things:
|
1865 |
|
|
//
|
1866 |
|
|
// * Detects whether the mapToProps function being called depends on props, which
|
1867 |
|
|
// is used by selectorFactory to decide if it should reinvoke on props changes.
|
1868 |
|
|
//
|
1869 |
|
|
// * On first call, handles mapToProps if returns another function, and treats that
|
1870 |
|
|
// new function as the true mapToProps for subsequent calls.
|
1871 |
|
|
//
|
1872 |
|
|
// * On first call, verifies the first result is a plain object, in order to warn
|
1873 |
|
|
// the developer that their mapToProps function is not returning a valid result.
|
1874 |
|
|
//
|
1875 |
|
|
|
1876 |
|
|
function wrapMapToPropsFunc(mapToProps, methodName) {
|
1877 |
|
|
return function initProxySelector(dispatch, _ref) {
|
1878 |
|
|
var displayName = _ref.displayName;
|
1879 |
|
|
|
1880 |
|
|
var proxy = function mapToPropsProxy(stateOrDispatch, ownProps) {
|
1881 |
|
|
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch);
|
1882 |
|
|
}; // allow detectFactoryAndVerify to get ownProps
|
1883 |
|
|
|
1884 |
|
|
|
1885 |
|
|
proxy.dependsOnOwnProps = true;
|
1886 |
|
|
|
1887 |
|
|
proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) {
|
1888 |
|
|
proxy.mapToProps = mapToProps;
|
1889 |
|
|
proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps);
|
1890 |
|
|
var props = proxy(stateOrDispatch, ownProps);
|
1891 |
|
|
|
1892 |
|
|
if (typeof props === 'function') {
|
1893 |
|
|
proxy.mapToProps = props;
|
1894 |
|
|
proxy.dependsOnOwnProps = getDependsOnOwnProps(props);
|
1895 |
|
|
props = proxy(stateOrDispatch, ownProps);
|
1896 |
|
|
}
|
1897 |
|
|
|
1898 |
|
|
verifyPlainObject(props, displayName, methodName);
|
1899 |
|
|
return props;
|
1900 |
|
|
};
|
1901 |
|
|
|
1902 |
|
|
return proxy;
|
1903 |
|
|
};
|
1904 |
|
|
}
|
1905 |
|
|
|
1906 |
|
|
function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {
|
1907 |
|
|
return typeof mapDispatchToProps === 'function' ? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') : undefined;
|
1908 |
|
|
}
|
1909 |
|
|
function whenMapDispatchToPropsIsMissing(mapDispatchToProps) {
|
1910 |
|
|
return !mapDispatchToProps ? wrapMapToPropsConstant(function (dispatch) {
|
1911 |
|
|
return {
|
1912 |
|
|
dispatch: dispatch
|
1913 |
|
|
};
|
1914 |
|
|
}) : undefined;
|
1915 |
|
|
}
|
1916 |
|
|
function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
|
1917 |
|
|
return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(function (dispatch) {
|
1918 |
|
|
return redux.bindActionCreators(mapDispatchToProps, dispatch);
|
1919 |
|
|
}) : undefined;
|
1920 |
|
|
}
|
1921 |
|
|
var defaultMapDispatchToPropsFactories = [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject];
|
1922 |
|
|
|
1923 |
|
|
function whenMapStateToPropsIsFunction(mapStateToProps) {
|
1924 |
|
|
return typeof mapStateToProps === 'function' ? wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') : undefined;
|
1925 |
|
|
}
|
1926 |
|
|
function whenMapStateToPropsIsMissing(mapStateToProps) {
|
1927 |
|
|
return !mapStateToProps ? wrapMapToPropsConstant(function () {
|
1928 |
|
|
return {};
|
1929 |
|
|
}) : undefined;
|
1930 |
|
|
}
|
1931 |
|
|
var defaultMapStateToPropsFactories = [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing];
|
1932 |
|
|
|
1933 |
|
|
function defaultMergeProps(stateProps, dispatchProps, ownProps) {
|
1934 |
|
|
return _extends({}, ownProps, {}, stateProps, {}, dispatchProps);
|
1935 |
|
|
}
|
1936 |
|
|
function wrapMergePropsFunc(mergeProps) {
|
1937 |
|
|
return function initMergePropsProxy(dispatch, _ref) {
|
1938 |
|
|
var displayName = _ref.displayName,
|
1939 |
|
|
pure = _ref.pure,
|
1940 |
|
|
areMergedPropsEqual = _ref.areMergedPropsEqual;
|
1941 |
|
|
var hasRunOnce = false;
|
1942 |
|
|
var mergedProps;
|
1943 |
|
|
return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
|
1944 |
|
|
var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
1945 |
|
|
|
1946 |
|
|
if (hasRunOnce) {
|
1947 |
|
|
if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
|
1948 |
|
|
} else {
|
1949 |
|
|
hasRunOnce = true;
|
1950 |
|
|
mergedProps = nextMergedProps;
|
1951 |
|
|
verifyPlainObject(mergedProps, displayName, 'mergeProps');
|
1952 |
|
|
}
|
1953 |
|
|
|
1954 |
|
|
return mergedProps;
|
1955 |
|
|
};
|
1956 |
|
|
};
|
1957 |
|
|
}
|
1958 |
|
|
function whenMergePropsIsFunction(mergeProps) {
|
1959 |
|
|
return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined;
|
1960 |
|
|
}
|
1961 |
|
|
function whenMergePropsIsOmitted(mergeProps) {
|
1962 |
|
|
return !mergeProps ? function () {
|
1963 |
|
|
return defaultMergeProps;
|
1964 |
|
|
} : undefined;
|
1965 |
|
|
}
|
1966 |
|
|
var defaultMergePropsFactories = [whenMergePropsIsFunction, whenMergePropsIsOmitted];
|
1967 |
|
|
|
1968 |
|
|
function verify(selector, methodName, displayName) {
|
1969 |
|
|
if (!selector) {
|
1970 |
|
|
throw new Error("Unexpected value for " + methodName + " in " + displayName + ".");
|
1971 |
|
|
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') {
|
1972 |
|
|
if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) {
|
1973 |
|
|
warning("The selector for " + methodName + " of " + displayName + " did not specify a value for dependsOnOwnProps.");
|
1974 |
|
|
}
|
1975 |
|
|
}
|
1976 |
|
|
}
|
1977 |
|
|
|
1978 |
|
|
function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) {
|
1979 |
|
|
verify(mapStateToProps, 'mapStateToProps', displayName);
|
1980 |
|
|
verify(mapDispatchToProps, 'mapDispatchToProps', displayName);
|
1981 |
|
|
verify(mergeProps, 'mergeProps', displayName);
|
1982 |
|
|
}
|
1983 |
|
|
|
1984 |
|
|
function impureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch) {
|
1985 |
|
|
return function impureFinalPropsSelector(state, ownProps) {
|
1986 |
|
|
return mergeProps(mapStateToProps(state, ownProps), mapDispatchToProps(dispatch, ownProps), ownProps);
|
1987 |
|
|
};
|
1988 |
|
|
}
|
1989 |
|
|
function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, _ref) {
|
1990 |
|
|
var areStatesEqual = _ref.areStatesEqual,
|
1991 |
|
|
areOwnPropsEqual = _ref.areOwnPropsEqual,
|
1992 |
|
|
areStatePropsEqual = _ref.areStatePropsEqual;
|
1993 |
|
|
var hasRunAtLeastOnce = false;
|
1994 |
|
|
var state;
|
1995 |
|
|
var ownProps;
|
1996 |
|
|
var stateProps;
|
1997 |
|
|
var dispatchProps;
|
1998 |
|
|
var mergedProps;
|
1999 |
|
|
|
2000 |
|
|
function handleFirstCall(firstState, firstOwnProps) {
|
2001 |
|
|
state = firstState;
|
2002 |
|
|
ownProps = firstOwnProps;
|
2003 |
|
|
stateProps = mapStateToProps(state, ownProps);
|
2004 |
|
|
dispatchProps = mapDispatchToProps(dispatch, ownProps);
|
2005 |
|
|
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
2006 |
|
|
hasRunAtLeastOnce = true;
|
2007 |
|
|
return mergedProps;
|
2008 |
|
|
}
|
2009 |
|
|
|
2010 |
|
|
function handleNewPropsAndNewState() {
|
2011 |
|
|
stateProps = mapStateToProps(state, ownProps);
|
2012 |
|
|
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
|
2013 |
|
|
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
2014 |
|
|
return mergedProps;
|
2015 |
|
|
}
|
2016 |
|
|
|
2017 |
|
|
function handleNewProps() {
|
2018 |
|
|
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps);
|
2019 |
|
|
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
|
2020 |
|
|
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
2021 |
|
|
return mergedProps;
|
2022 |
|
|
}
|
2023 |
|
|
|
2024 |
|
|
function handleNewState() {
|
2025 |
|
|
var nextStateProps = mapStateToProps(state, ownProps);
|
2026 |
|
|
var statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps);
|
2027 |
|
|
stateProps = nextStateProps;
|
2028 |
|
|
if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
|
2029 |
|
|
return mergedProps;
|
2030 |
|
|
}
|
2031 |
|
|
|
2032 |
|
|
function handleSubsequentCalls(nextState, nextOwnProps) {
|
2033 |
|
|
var propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps);
|
2034 |
|
|
var stateChanged = !areStatesEqual(nextState, state);
|
2035 |
|
|
state = nextState;
|
2036 |
|
|
ownProps = nextOwnProps;
|
2037 |
|
|
if (propsChanged && stateChanged) return handleNewPropsAndNewState();
|
2038 |
|
|
if (propsChanged) return handleNewProps();
|
2039 |
|
|
if (stateChanged) return handleNewState();
|
2040 |
|
|
return mergedProps;
|
2041 |
|
|
}
|
2042 |
|
|
|
2043 |
|
|
return function pureFinalPropsSelector(nextState, nextOwnProps) {
|
2044 |
|
|
return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps);
|
2045 |
|
|
};
|
2046 |
|
|
} // TODO: Add more comments
|
2047 |
|
|
// If pure is true, the selector returned by selectorFactory will memoize its results,
|
2048 |
|
|
// allowing connectAdvanced's shouldComponentUpdate to return false if final
|
2049 |
|
|
// props have not changed. If false, the selector will always return a new
|
2050 |
|
|
// object and shouldComponentUpdate will always return true.
|
2051 |
|
|
|
2052 |
|
|
function finalPropsSelectorFactory(dispatch, _ref2) {
|
2053 |
|
|
var initMapStateToProps = _ref2.initMapStateToProps,
|
2054 |
|
|
initMapDispatchToProps = _ref2.initMapDispatchToProps,
|
2055 |
|
|
initMergeProps = _ref2.initMergeProps,
|
2056 |
|
|
options = _objectWithoutPropertiesLoose(_ref2, ["initMapStateToProps", "initMapDispatchToProps", "initMergeProps"]);
|
2057 |
|
|
|
2058 |
|
|
var mapStateToProps = initMapStateToProps(dispatch, options);
|
2059 |
|
|
var mapDispatchToProps = initMapDispatchToProps(dispatch, options);
|
2060 |
|
|
var mergeProps = initMergeProps(dispatch, options);
|
2061 |
|
|
|
2062 |
|
|
{
|
2063 |
|
|
verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName);
|
2064 |
|
|
}
|
2065 |
|
|
|
2066 |
|
|
var selectorFactory = options.pure ? pureFinalPropsSelectorFactory : impureFinalPropsSelectorFactory;
|
2067 |
|
|
return selectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options);
|
2068 |
|
|
}
|
2069 |
|
|
|
2070 |
|
|
/*
|
2071 |
|
|
connect is a facade over connectAdvanced. It turns its args into a compatible
|
2072 |
|
|
selectorFactory, which has the signature:
|
2073 |
|
|
|
2074 |
|
|
(dispatch, options) => (nextState, nextOwnProps) => nextFinalProps
|
2075 |
|
|
|
2076 |
|
|
connect passes its args to connectAdvanced as options, which will in turn pass them to
|
2077 |
|
|
selectorFactory each time a Connect component instance is instantiated or hot reloaded.
|
2078 |
|
|
|
2079 |
|
|
selectorFactory returns a final props selector from its mapStateToProps,
|
2080 |
|
|
mapStateToPropsFactories, mapDispatchToProps, mapDispatchToPropsFactories, mergeProps,
|
2081 |
|
|
mergePropsFactories, and pure args.
|
2082 |
|
|
|
2083 |
|
|
The resulting final props selector is called by the Connect component instance whenever
|
2084 |
|
|
it receives new props or store state.
|
2085 |
|
|
*/
|
2086 |
|
|
|
2087 |
|
|
function match(arg, factories, name) {
|
2088 |
|
|
for (var i = factories.length - 1; i >= 0; i--) {
|
2089 |
|
|
var result = factories[i](arg);
|
2090 |
|
|
if (result) return result;
|
2091 |
|
|
}
|
2092 |
|
|
|
2093 |
|
|
return function (dispatch, options) {
|
2094 |
|
|
throw new Error("Invalid value of type " + typeof arg + " for " + name + " argument when connecting component " + options.wrappedComponentName + ".");
|
2095 |
|
|
};
|
2096 |
|
|
}
|
2097 |
|
|
|
2098 |
|
|
function strictEqual(a, b) {
|
2099 |
|
|
return a === b;
|
2100 |
|
|
} // createConnect with default args builds the 'official' connect behavior. Calling it with
|
2101 |
|
|
// different options opens up some testing and extensibility scenarios
|
2102 |
|
|
|
2103 |
|
|
|
2104 |
|
|
function createConnect(_temp) {
|
2105 |
|
|
var _ref = _temp === void 0 ? {} : _temp,
|
2106 |
|
|
_ref$connectHOC = _ref.connectHOC,
|
2107 |
|
|
connectHOC = _ref$connectHOC === void 0 ? connectAdvanced : _ref$connectHOC,
|
2108 |
|
|
_ref$mapStateToPropsF = _ref.mapStateToPropsFactories,
|
2109 |
|
|
mapStateToPropsFactories = _ref$mapStateToPropsF === void 0 ? defaultMapStateToPropsFactories : _ref$mapStateToPropsF,
|
2110 |
|
|
_ref$mapDispatchToPro = _ref.mapDispatchToPropsFactories,
|
2111 |
|
|
mapDispatchToPropsFactories = _ref$mapDispatchToPro === void 0 ? defaultMapDispatchToPropsFactories : _ref$mapDispatchToPro,
|
2112 |
|
|
_ref$mergePropsFactor = _ref.mergePropsFactories,
|
2113 |
|
|
mergePropsFactories = _ref$mergePropsFactor === void 0 ? defaultMergePropsFactories : _ref$mergePropsFactor,
|
2114 |
|
|
_ref$selectorFactory = _ref.selectorFactory,
|
2115 |
|
|
selectorFactory = _ref$selectorFactory === void 0 ? finalPropsSelectorFactory : _ref$selectorFactory;
|
2116 |
|
|
|
2117 |
|
|
return function connect(mapStateToProps, mapDispatchToProps, mergeProps, _ref2) {
|
2118 |
|
|
if (_ref2 === void 0) {
|
2119 |
|
|
_ref2 = {};
|
2120 |
|
|
}
|
2121 |
|
|
|
2122 |
|
|
var _ref3 = _ref2,
|
2123 |
|
|
_ref3$pure = _ref3.pure,
|
2124 |
|
|
pure = _ref3$pure === void 0 ? true : _ref3$pure,
|
2125 |
|
|
_ref3$areStatesEqual = _ref3.areStatesEqual,
|
2126 |
|
|
areStatesEqual = _ref3$areStatesEqual === void 0 ? strictEqual : _ref3$areStatesEqual,
|
2127 |
|
|
_ref3$areOwnPropsEqua = _ref3.areOwnPropsEqual,
|
2128 |
|
|
areOwnPropsEqual = _ref3$areOwnPropsEqua === void 0 ? shallowEqual : _ref3$areOwnPropsEqua,
|
2129 |
|
|
_ref3$areStatePropsEq = _ref3.areStatePropsEqual,
|
2130 |
|
|
areStatePropsEqual = _ref3$areStatePropsEq === void 0 ? shallowEqual : _ref3$areStatePropsEq,
|
2131 |
|
|
_ref3$areMergedPropsE = _ref3.areMergedPropsEqual,
|
2132 |
|
|
areMergedPropsEqual = _ref3$areMergedPropsE === void 0 ? shallowEqual : _ref3$areMergedPropsE,
|
2133 |
|
|
extraOptions = _objectWithoutPropertiesLoose(_ref3, ["pure", "areStatesEqual", "areOwnPropsEqual", "areStatePropsEqual", "areMergedPropsEqual"]);
|
2134 |
|
|
|
2135 |
|
|
var initMapStateToProps = match(mapStateToProps, mapStateToPropsFactories, 'mapStateToProps');
|
2136 |
|
|
var initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories, 'mapDispatchToProps');
|
2137 |
|
|
var initMergeProps = match(mergeProps, mergePropsFactories, 'mergeProps');
|
2138 |
|
|
return connectHOC(selectorFactory, _extends({
|
2139 |
|
|
// used in error messages
|
2140 |
|
|
methodName: 'connect',
|
2141 |
|
|
// used to compute Connect's displayName from the wrapped component's displayName.
|
2142 |
|
|
getDisplayName: function getDisplayName(name) {
|
2143 |
|
|
return "Connect(" + name + ")";
|
2144 |
|
|
},
|
2145 |
|
|
// if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changes
|
2146 |
|
|
shouldHandleStateChanges: Boolean(mapStateToProps),
|
2147 |
|
|
// passed through to selectorFactory
|
2148 |
|
|
initMapStateToProps: initMapStateToProps,
|
2149 |
|
|
initMapDispatchToProps: initMapDispatchToProps,
|
2150 |
|
|
initMergeProps: initMergeProps,
|
2151 |
|
|
pure: pure,
|
2152 |
|
|
areStatesEqual: areStatesEqual,
|
2153 |
|
|
areOwnPropsEqual: areOwnPropsEqual,
|
2154 |
|
|
areStatePropsEqual: areStatePropsEqual,
|
2155 |
|
|
areMergedPropsEqual: areMergedPropsEqual
|
2156 |
|
|
}, extraOptions));
|
2157 |
|
|
};
|
2158 |
|
|
}
|
2159 |
|
|
var connect = /*#__PURE__*/
|
2160 |
|
|
createConnect();
|
2161 |
|
|
|
2162 |
|
|
/**
|
2163 |
|
|
* A hook to access the value of the `ReactReduxContext`. This is a low-level
|
2164 |
|
|
* hook that you should usually not need to call directly.
|
2165 |
|
|
*
|
2166 |
|
|
* @returns {any} the value of the `ReactReduxContext`
|
2167 |
|
|
*
|
2168 |
|
|
* @example
|
2169 |
|
|
*
|
2170 |
|
|
* import React from 'react'
|
2171 |
|
|
* import { useReduxContext } from 'react-redux'
|
2172 |
|
|
*
|
2173 |
|
|
* export const CounterComponent = ({ value }) => {
|
2174 |
|
|
* const { store } = useReduxContext()
|
2175 |
|
|
* return <div>{store.getState()}</div>
|
2176 |
|
|
* }
|
2177 |
|
|
*/
|
2178 |
|
|
|
2179 |
|
|
function useReduxContext() {
|
2180 |
|
|
var contextValue = React.useContext(ReactReduxContext);
|
2181 |
|
|
|
2182 |
|
|
if ( !contextValue) {
|
2183 |
|
|
throw new Error('could not find react-redux context value; please ensure the component is wrapped in a <Provider>');
|
2184 |
|
|
}
|
2185 |
|
|
|
2186 |
|
|
return contextValue;
|
2187 |
|
|
}
|
2188 |
|
|
|
2189 |
|
|
/**
|
2190 |
|
|
* Hook factory, which creates a `useStore` hook bound to a given context.
|
2191 |
|
|
*
|
2192 |
|
|
* @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
|
2193 |
|
|
* @returns {Function} A `useStore` hook bound to the specified context.
|
2194 |
|
|
*/
|
2195 |
|
|
|
2196 |
|
|
function createStoreHook(context) {
|
2197 |
|
|
if (context === void 0) {
|
2198 |
|
|
context = ReactReduxContext;
|
2199 |
|
|
}
|
2200 |
|
|
|
2201 |
|
|
var useReduxContext$1 = context === ReactReduxContext ? useReduxContext : function () {
|
2202 |
|
|
return React.useContext(context);
|
2203 |
|
|
};
|
2204 |
|
|
return function useStore() {
|
2205 |
|
|
var _useReduxContext = useReduxContext$1(),
|
2206 |
|
|
store = _useReduxContext.store;
|
2207 |
|
|
|
2208 |
|
|
return store;
|
2209 |
|
|
};
|
2210 |
|
|
}
|
2211 |
|
|
/**
|
2212 |
|
|
* A hook to access the redux store.
|
2213 |
|
|
*
|
2214 |
|
|
* @returns {any} the redux store
|
2215 |
|
|
*
|
2216 |
|
|
* @example
|
2217 |
|
|
*
|
2218 |
|
|
* import React from 'react'
|
2219 |
|
|
* import { useStore } from 'react-redux'
|
2220 |
|
|
*
|
2221 |
|
|
* export const ExampleComponent = () => {
|
2222 |
|
|
* const store = useStore()
|
2223 |
|
|
* return <div>{store.getState()}</div>
|
2224 |
|
|
* }
|
2225 |
|
|
*/
|
2226 |
|
|
|
2227 |
|
|
var useStore =
|
2228 |
|
|
/*#__PURE__*/
|
2229 |
|
|
createStoreHook();
|
2230 |
|
|
|
2231 |
|
|
/**
|
2232 |
|
|
* Hook factory, which creates a `useDispatch` hook bound to a given context.
|
2233 |
|
|
*
|
2234 |
|
|
* @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
|
2235 |
|
|
* @returns {Function} A `useDispatch` hook bound to the specified context.
|
2236 |
|
|
*/
|
2237 |
|
|
|
2238 |
|
|
function createDispatchHook(context) {
|
2239 |
|
|
if (context === void 0) {
|
2240 |
|
|
context = ReactReduxContext;
|
2241 |
|
|
}
|
2242 |
|
|
|
2243 |
|
|
var useStore$1 = context === ReactReduxContext ? useStore : createStoreHook(context);
|
2244 |
|
|
return function useDispatch() {
|
2245 |
|
|
var store = useStore$1();
|
2246 |
|
|
return store.dispatch;
|
2247 |
|
|
};
|
2248 |
|
|
}
|
2249 |
|
|
/**
|
2250 |
|
|
* A hook to access the redux `dispatch` function.
|
2251 |
|
|
*
|
2252 |
|
|
* @returns {any|function} redux store's `dispatch` function
|
2253 |
|
|
*
|
2254 |
|
|
* @example
|
2255 |
|
|
*
|
2256 |
|
|
* import React, { useCallback } from 'react'
|
2257 |
|
|
* import { useDispatch } from 'react-redux'
|
2258 |
|
|
*
|
2259 |
|
|
* export const CounterComponent = ({ value }) => {
|
2260 |
|
|
* const dispatch = useDispatch()
|
2261 |
|
|
* const increaseCounter = useCallback(() => dispatch({ type: 'increase-counter' }), [])
|
2262 |
|
|
* return (
|
2263 |
|
|
* <div>
|
2264 |
|
|
* <span>{value}</span>
|
2265 |
|
|
* <button onClick={increaseCounter}>Increase counter</button>
|
2266 |
|
|
* </div>
|
2267 |
|
|
* )
|
2268 |
|
|
* }
|
2269 |
|
|
*/
|
2270 |
|
|
|
2271 |
|
|
var useDispatch =
|
2272 |
|
|
/*#__PURE__*/
|
2273 |
|
|
createDispatchHook();
|
2274 |
|
|
|
2275 |
|
|
var refEquality = function refEquality(a, b) {
|
2276 |
|
|
return a === b;
|
2277 |
|
|
};
|
2278 |
|
|
|
2279 |
|
|
function useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub) {
|
2280 |
|
|
var _useReducer = React.useReducer(function (s) {
|
2281 |
|
|
return s + 1;
|
2282 |
|
|
}, 0),
|
2283 |
|
|
forceRender = _useReducer[1];
|
2284 |
|
|
|
2285 |
|
|
var subscription = React.useMemo(function () {
|
2286 |
|
|
return new Subscription(store, contextSub);
|
2287 |
|
|
}, [store, contextSub]);
|
2288 |
|
|
var latestSubscriptionCallbackError = React.useRef();
|
2289 |
|
|
var latestSelector = React.useRef();
|
2290 |
|
|
var latestSelectedState = React.useRef();
|
2291 |
|
|
var selectedState;
|
2292 |
|
|
|
2293 |
|
|
try {
|
2294 |
|
|
if (selector !== latestSelector.current || latestSubscriptionCallbackError.current) {
|
2295 |
|
|
selectedState = selector(store.getState());
|
2296 |
|
|
} else {
|
2297 |
|
|
selectedState = latestSelectedState.current;
|
2298 |
|
|
}
|
2299 |
|
|
} catch (err) {
|
2300 |
|
|
if (latestSubscriptionCallbackError.current) {
|
2301 |
|
|
err.message += "\nThe error may be correlated with this previous error:\n" + latestSubscriptionCallbackError.current.stack + "\n\n";
|
2302 |
|
|
}
|
2303 |
|
|
|
2304 |
|
|
throw err;
|
2305 |
|
|
}
|
2306 |
|
|
|
2307 |
|
|
useIsomorphicLayoutEffect(function () {
|
2308 |
|
|
latestSelector.current = selector;
|
2309 |
|
|
latestSelectedState.current = selectedState;
|
2310 |
|
|
latestSubscriptionCallbackError.current = undefined;
|
2311 |
|
|
});
|
2312 |
|
|
useIsomorphicLayoutEffect(function () {
|
2313 |
|
|
function checkForUpdates() {
|
2314 |
|
|
try {
|
2315 |
|
|
var newSelectedState = latestSelector.current(store.getState());
|
2316 |
|
|
|
2317 |
|
|
if (equalityFn(newSelectedState, latestSelectedState.current)) {
|
2318 |
|
|
return;
|
2319 |
|
|
}
|
2320 |
|
|
|
2321 |
|
|
latestSelectedState.current = newSelectedState;
|
2322 |
|
|
} catch (err) {
|
2323 |
|
|
// we ignore all errors here, since when the component
|
2324 |
|
|
// is re-rendered, the selectors are called again, and
|
2325 |
|
|
// will throw again, if neither props nor store state
|
2326 |
|
|
// changed
|
2327 |
|
|
latestSubscriptionCallbackError.current = err;
|
2328 |
|
|
}
|
2329 |
|
|
|
2330 |
|
|
forceRender({});
|
2331 |
|
|
}
|
2332 |
|
|
|
2333 |
|
|
subscription.onStateChange = checkForUpdates;
|
2334 |
|
|
subscription.trySubscribe();
|
2335 |
|
|
checkForUpdates();
|
2336 |
|
|
return function () {
|
2337 |
|
|
return subscription.tryUnsubscribe();
|
2338 |
|
|
};
|
2339 |
|
|
}, [store, subscription]);
|
2340 |
|
|
return selectedState;
|
2341 |
|
|
}
|
2342 |
|
|
/**
|
2343 |
|
|
* Hook factory, which creates a `useSelector` hook bound to a given context.
|
2344 |
|
|
*
|
2345 |
|
|
* @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
|
2346 |
|
|
* @returns {Function} A `useSelector` hook bound to the specified context.
|
2347 |
|
|
*/
|
2348 |
|
|
|
2349 |
|
|
|
2350 |
|
|
function createSelectorHook(context) {
|
2351 |
|
|
if (context === void 0) {
|
2352 |
|
|
context = ReactReduxContext;
|
2353 |
|
|
}
|
2354 |
|
|
|
2355 |
|
|
var useReduxContext$1 = context === ReactReduxContext ? useReduxContext : function () {
|
2356 |
|
|
return React.useContext(context);
|
2357 |
|
|
};
|
2358 |
|
|
return function useSelector(selector, equalityFn) {
|
2359 |
|
|
if (equalityFn === void 0) {
|
2360 |
|
|
equalityFn = refEquality;
|
2361 |
|
|
}
|
2362 |
|
|
|
2363 |
|
|
if ( !selector) {
|
2364 |
|
|
throw new Error("You must pass a selector to useSelectors");
|
2365 |
|
|
}
|
2366 |
|
|
|
2367 |
|
|
var _useReduxContext = useReduxContext$1(),
|
2368 |
|
|
store = _useReduxContext.store,
|
2369 |
|
|
contextSub = _useReduxContext.subscription;
|
2370 |
|
|
|
2371 |
|
|
return useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub);
|
2372 |
|
|
};
|
2373 |
|
|
}
|
2374 |
|
|
/**
|
2375 |
|
|
* A hook to access the redux store's state. This hook takes a selector function
|
2376 |
|
|
* as an argument. The selector is called with the store state.
|
2377 |
|
|
*
|
2378 |
|
|
* This hook takes an optional equality comparison function as the second parameter
|
2379 |
|
|
* that allows you to customize the way the selected state is compared to determine
|
2380 |
|
|
* whether the component needs to be re-rendered.
|
2381 |
|
|
*
|
2382 |
|
|
* @param {Function} selector the selector function
|
2383 |
|
|
* @param {Function=} equalityFn the function that will be used to determine equality
|
2384 |
|
|
*
|
2385 |
|
|
* @returns {any} the selected state
|
2386 |
|
|
*
|
2387 |
|
|
* @example
|
2388 |
|
|
*
|
2389 |
|
|
* import React from 'react'
|
2390 |
|
|
* import { useSelector } from 'react-redux'
|
2391 |
|
|
*
|
2392 |
|
|
* export const CounterComponent = () => {
|
2393 |
|
|
* const counter = useSelector(state => state.counter)
|
2394 |
|
|
* return <div>{counter}</div>
|
2395 |
|
|
* }
|
2396 |
|
|
*/
|
2397 |
|
|
|
2398 |
|
|
var useSelector =
|
2399 |
|
|
/*#__PURE__*/
|
2400 |
|
|
createSelectorHook();
|
2401 |
|
|
|
2402 |
|
|
setBatch(reactDom.unstable_batchedUpdates);
|
2403 |
|
|
|
2404 |
|
|
Object.defineProperty(exports, 'batch', {
|
2405 |
|
|
enumerable: true,
|
2406 |
|
|
get: function () {
|
2407 |
|
|
return reactDom.unstable_batchedUpdates;
|
2408 |
|
|
}
|
2409 |
|
|
});
|
2410 |
|
|
exports.Provider = Provider;
|
2411 |
|
|
exports.ReactReduxContext = ReactReduxContext;
|
2412 |
|
|
exports.connect = connect;
|
2413 |
|
|
exports.connectAdvanced = connectAdvanced;
|
2414 |
|
|
exports.createDispatchHook = createDispatchHook;
|
2415 |
|
|
exports.createSelectorHook = createSelectorHook;
|
2416 |
|
|
exports.createStoreHook = createStoreHook;
|
2417 |
|
|
exports.shallowEqual = shallowEqual;
|
2418 |
|
|
exports.useDispatch = useDispatch;
|
2419 |
|
|
exports.useSelector = useSelector;
|
2420 |
|
|
exports.useStore = useStore;
|
2421 |
|
|
|
2422 |
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
2423 |
|
|
|
2424 |
|
|
}));
|