react-redux.js (73747B)
1 /** 2 * react-redux v5.0.7 3 */ 4 5 (function (global, factory) { 6 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require("resource://devtools/client/shared/vendor/react.mjs"), require("resource://devtools/client/shared/vendor/redux.js")) : 7 typeof define === 'function' && define.amd ? define(['exports', 'resource://devtools/client/shared/vendor/react.js', 'resource://devtools/client/shared/vendor/redux.js'], factory) : 8 (factory((global.ReactRedux = {}),global.React,global.Redux)); 9 }(this, (function (exports,react,redux) { 'use strict'; 10 11 var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 12 13 function createCommonjsModule(fn, module) { 14 return module = { exports: {} }, fn(module, module.exports), module.exports; 15 } 16 17 /** 18 * Copyright (c) 2013-present, Facebook, Inc. 19 * 20 * This source code is licensed under the MIT license found in the 21 * LICENSE file in the root directory of this source tree. 22 * 23 * 24 */ 25 26 function makeEmptyFunction(arg) { 27 return function () { 28 return arg; 29 }; 30 } 31 32 /** 33 * This function accepts and discards inputs; it has no side effects. This is 34 * primarily useful idiomatically for overridable function endpoints which 35 * always need to be callable, since JS lacks a null-call idiom ala Cocoa. 36 */ 37 var emptyFunction = function emptyFunction() {}; 38 39 emptyFunction.thatReturns = makeEmptyFunction; 40 emptyFunction.thatReturnsFalse = makeEmptyFunction(false); 41 emptyFunction.thatReturnsTrue = makeEmptyFunction(true); 42 emptyFunction.thatReturnsNull = makeEmptyFunction(null); 43 emptyFunction.thatReturnsThis = function () { 44 return this; 45 }; 46 emptyFunction.thatReturnsArgument = function (arg) { 47 return arg; 48 }; 49 50 var emptyFunction_1 = emptyFunction; 51 52 /** 53 * Copyright (c) 2013-present, Facebook, Inc. 54 * 55 * This source code is licensed under the MIT license found in the 56 * LICENSE file in the root directory of this source tree. 57 * 58 */ 59 60 /** 61 * Use invariant() to assert state which your program assumes to be true. 62 * 63 * Provide sprintf-style format (only %s is supported) and arguments 64 * to provide information about what broke and what you were 65 * expecting. 66 * 67 * The invariant message will be stripped in production, but the invariant 68 * will remain to ensure logic does not differ in production. 69 */ 70 71 var validateFormat = function validateFormat(format) {}; 72 73 { 74 validateFormat = function validateFormat(format) { 75 if (format === undefined) { 76 throw new Error('invariant requires an error message argument'); 77 } 78 }; 79 } 80 81 function invariant(condition, format, a, b, c, d, e, f) { 82 validateFormat(format); 83 84 if (!condition) { 85 var error; 86 if (format === undefined) { 87 error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); 88 } else { 89 var args = [a, b, c, d, e, f]; 90 var argIndex = 0; 91 error = new Error(format.replace(/%s/g, function () { 92 return args[argIndex++]; 93 })); 94 error.name = 'Invariant Violation'; 95 } 96 97 error.framesToPop = 1; // we don't care about invariant's own frame 98 throw error; 99 } 100 } 101 102 var invariant_1 = invariant; 103 104 /** 105 * Similar to invariant but only logs a warning if the condition is not met. 106 * This can be used to log issues in development environments in critical 107 * paths. Removing the logging code for production environments will keep the 108 * same logic and follow the same code paths. 109 */ 110 111 var warning = emptyFunction_1; 112 113 { 114 var printWarning = function printWarning(format) { 115 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 116 args[_key - 1] = arguments[_key]; 117 } 118 119 var argIndex = 0; 120 var message = 'Warning: ' + format.replace(/%s/g, function () { 121 return args[argIndex++]; 122 }); 123 if (typeof console !== 'undefined') { 124 console.error(message); 125 } 126 try { 127 // --- Welcome to debugging React --- 128 // This error was thrown as a convenience so that you can use this stack 129 // to find the callsite that caused this warning to fire. 130 throw new Error(message); 131 } catch (x) {} 132 }; 133 134 warning = function warning(condition, format) { 135 if (format === undefined) { 136 throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); 137 } 138 139 if (format.indexOf('Failed Composite propType: ') === 0) { 140 return; // Ignore CompositeComponent proptype check. 141 } 142 143 if (!condition) { 144 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { 145 args[_key2 - 2] = arguments[_key2]; 146 } 147 148 printWarning.apply(undefined, [format].concat(args)); 149 } 150 }; 151 } 152 153 var warning_1 = warning; 154 155 /* 156 object-assign 157 (c) Sindre Sorhus 158 @license MIT 159 */ 160 /* eslint-disable no-unused-vars */ 161 var getOwnPropertySymbols = Object.getOwnPropertySymbols; 162 var hasOwnProperty = Object.prototype.hasOwnProperty; 163 var propIsEnumerable = Object.prototype.propertyIsEnumerable; 164 165 function toObject(val) { 166 if (val === null || val === undefined) { 167 throw new TypeError('Object.assign cannot be called with null or undefined'); 168 } 169 170 return Object(val); 171 } 172 173 function shouldUseNative() { 174 try { 175 if (!Object.assign) { 176 return false; 177 } 178 179 // Detect buggy property enumeration order in older V8 versions. 180 181 // https://bugs.chromium.org/p/v8/issues/detail?id=4118 182 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers 183 test1[5] = 'de'; 184 if (Object.getOwnPropertyNames(test1)[0] === '5') { 185 return false; 186 } 187 188 // https://bugs.chromium.org/p/v8/issues/detail?id=3056 189 var test2 = {}; 190 for (var i = 0; i < 10; i++) { 191 test2['_' + String.fromCharCode(i)] = i; 192 } 193 var order2 = Object.getOwnPropertyNames(test2).map(function (n) { 194 return test2[n]; 195 }); 196 if (order2.join('') !== '0123456789') { 197 return false; 198 } 199 200 // https://bugs.chromium.org/p/v8/issues/detail?id=3056 201 var test3 = {}; 202 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { 203 test3[letter] = letter; 204 }); 205 if (Object.keys(Object.assign({}, test3)).join('') !== 206 'abcdefghijklmnopqrst') { 207 return false; 208 } 209 210 return true; 211 } catch (err) { 212 // We don't expect any of the above to throw, but better to be safe. 213 return false; 214 } 215 } 216 217 var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { 218 var from; 219 var to = toObject(target); 220 var symbols; 221 222 for (var s = 1; s < arguments.length; s++) { 223 from = Object(arguments[s]); 224 225 for (var key in from) { 226 if (hasOwnProperty.call(from, key)) { 227 to[key] = from[key]; 228 } 229 } 230 231 if (getOwnPropertySymbols) { 232 symbols = getOwnPropertySymbols(from); 233 for (var i = 0; i < symbols.length; i++) { 234 if (propIsEnumerable.call(from, symbols[i])) { 235 to[symbols[i]] = from[symbols[i]]; 236 } 237 } 238 } 239 } 240 241 return to; 242 }; 243 244 /** 245 * Copyright (c) 2013-present, Facebook, Inc. 246 * 247 * This source code is licensed under the MIT license found in the 248 * LICENSE file in the root directory of this source tree. 249 */ 250 251 var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; 252 253 var ReactPropTypesSecret_1 = ReactPropTypesSecret; 254 255 { 256 var invariant$1 = invariant_1; 257 var warning$1 = warning_1; 258 var ReactPropTypesSecret$1 = ReactPropTypesSecret_1; 259 var loggedTypeFailures = {}; 260 } 261 262 /** 263 * Assert that the values match with the type specs. 264 * Error messages are memorized and will only be shown once. 265 * 266 * @param {object} typeSpecs Map of name to a ReactPropType 267 * @param {object} values Runtime values that need to be type-checked 268 * @param {string} location e.g. "prop", "context", "child context" 269 * @param {string} componentName Name of the component for error messages. 270 * @param {?Function} getStack Returns the component stack. 271 * @private 272 */ 273 function checkPropTypes(typeSpecs, values, location, componentName, getStack) { 274 { 275 for (var typeSpecName in typeSpecs) { 276 if (typeSpecs.hasOwnProperty(typeSpecName)) { 277 var error; 278 // Prop type validation may throw. In case they do, we don't want to 279 // fail the render phase where it didn't fail before. So we log it. 280 // After these have been cleaned up, we'll let them throw. 281 try { 282 // This is intentionally an invariant that gets caught. It's the same 283 // behavior as without this statement except with a better message. 284 invariant$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); 285 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1); 286 } catch (ex) { 287 error = ex; 288 } 289 warning$1(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); 290 if (error instanceof Error && !(error.message in loggedTypeFailures)) { 291 // Only monitor this failure once because there tends to be a lot of the 292 // same error. 293 loggedTypeFailures[error.message] = true; 294 295 var stack = getStack ? getStack() : ''; 296 297 warning$1(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); 298 } 299 } 300 } 301 } 302 } 303 304 var checkPropTypes_1 = checkPropTypes; 305 306 var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) { 307 /* global Symbol */ 308 var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; 309 var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. 310 311 /** 312 * Returns the iterator method function contained on the iterable object. 313 * 314 * Be sure to invoke the function with the iterable as context: 315 * 316 * var iteratorFn = getIteratorFn(myIterable); 317 * if (iteratorFn) { 318 * var iterator = iteratorFn.call(myIterable); 319 * ... 320 * } 321 * 322 * @param {?object} maybeIterable 323 * @return {?function} 324 */ 325 function getIteratorFn(maybeIterable) { 326 var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); 327 if (typeof iteratorFn === 'function') { 328 return iteratorFn; 329 } 330 } 331 332 /** 333 * Collection of methods that allow declaration and validation of props that are 334 * supplied to React components. Example usage: 335 * 336 * var Props = require('ReactPropTypes'); 337 * var MyArticle = React.createClass({ 338 * propTypes: { 339 * // An optional string prop named "description". 340 * description: Props.string, 341 * 342 * // A required enum prop named "category". 343 * category: Props.oneOf(['News','Photos']).isRequired, 344 * 345 * // A prop named "dialog" that requires an instance of Dialog. 346 * dialog: Props.instanceOf(Dialog).isRequired 347 * }, 348 * render: function() { ... } 349 * }); 350 * 351 * A more formal specification of how these methods are used: 352 * 353 * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) 354 * decl := ReactPropTypes.{type}(.isRequired)? 355 * 356 * Each and every declaration produces a function with the same signature. This 357 * allows the creation of custom validation functions. For example: 358 * 359 * var MyLink = React.createClass({ 360 * propTypes: { 361 * // An optional string or URI prop named "href". 362 * href: function(props, propName, componentName) { 363 * var propValue = props[propName]; 364 * if (propValue != null && typeof propValue !== 'string' && 365 * !(propValue instanceof URI)) { 366 * return new Error( 367 * 'Expected a string or an URI for ' + propName + ' in ' + 368 * componentName 369 * ); 370 * } 371 * } 372 * }, 373 * render: function() {...} 374 * }); 375 * 376 * @internal 377 */ 378 379 var ANONYMOUS = '<<anonymous>>'; 380 381 // Important! 382 // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. 383 var ReactPropTypes = { 384 array: createPrimitiveTypeChecker('array'), 385 bool: createPrimitiveTypeChecker('boolean'), 386 func: createPrimitiveTypeChecker('function'), 387 number: createPrimitiveTypeChecker('number'), 388 object: createPrimitiveTypeChecker('object'), 389 string: createPrimitiveTypeChecker('string'), 390 symbol: createPrimitiveTypeChecker('symbol'), 391 392 any: createAnyTypeChecker(), 393 arrayOf: createArrayOfTypeChecker, 394 element: createElementTypeChecker(), 395 instanceOf: createInstanceTypeChecker, 396 node: createNodeChecker(), 397 objectOf: createObjectOfTypeChecker, 398 oneOf: createEnumTypeChecker, 399 oneOfType: createUnionTypeChecker, 400 shape: createShapeTypeChecker, 401 exact: createStrictShapeTypeChecker, 402 }; 403 404 /** 405 * inlined Object.is polyfill to avoid requiring consumers ship their own 406 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is 407 */ 408 /*eslint-disable no-self-compare*/ 409 function is(x, y) { 410 // SameValue algorithm 411 if (x === y) { 412 // Steps 1-5, 7-10 413 // Steps 6.b-6.e: +0 != -0 414 return x !== 0 || 1 / x === 1 / y; 415 } else { 416 // Step 6.a: NaN == NaN 417 return x !== x && y !== y; 418 } 419 } 420 /*eslint-enable no-self-compare*/ 421 422 /** 423 * We use an Error-like object for backward compatibility as people may call 424 * PropTypes directly and inspect their output. However, we don't use real 425 * Errors anymore. We don't inspect their stack anyway, and creating them 426 * is prohibitively expensive if they are created too often, such as what 427 * happens in oneOfType() for any type before the one that matched. 428 */ 429 function PropTypeError(message) { 430 this.message = message; 431 this.stack = ''; 432 } 433 // Make `instanceof Error` still work for returned errors. 434 PropTypeError.prototype = Error.prototype; 435 436 function createChainableTypeChecker(validate) { 437 { 438 var manualPropTypeCallCache = {}; 439 var manualPropTypeWarningCount = 0; 440 } 441 function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { 442 componentName = componentName || ANONYMOUS; 443 propFullName = propFullName || propName; 444 445 if (secret !== ReactPropTypesSecret_1) { 446 if (throwOnDirectAccess) { 447 // New behavior only for users of `prop-types` package 448 invariant_1( 449 false, 450 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 451 'Use `PropTypes.checkPropTypes()` to call them. ' + 452 'Read more at http://fb.me/use-check-prop-types' 453 ); 454 } else if ("development" !== 'production' && typeof console !== 'undefined') { 455 // Old behavior for people using React.PropTypes 456 var cacheKey = componentName + ':' + propName; 457 if ( 458 !manualPropTypeCallCache[cacheKey] && 459 // Avoid spamming the console because they are often not actionable except for lib authors 460 manualPropTypeWarningCount < 3 461 ) { 462 warning_1( 463 false, 464 'You are manually calling a React.PropTypes validation ' + 465 'function for the `%s` prop on `%s`. This is deprecated ' + 466 'and will throw in the standalone `prop-types` package. ' + 467 'You may be seeing this warning due to a third-party PropTypes ' + 468 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', 469 propFullName, 470 componentName 471 ); 472 manualPropTypeCallCache[cacheKey] = true; 473 manualPropTypeWarningCount++; 474 } 475 } 476 } 477 if (props[propName] == null) { 478 if (isRequired) { 479 if (props[propName] === null) { 480 return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); 481 } 482 return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); 483 } 484 return null; 485 } else { 486 return validate(props, propName, componentName, location, propFullName); 487 } 488 } 489 490 var chainedCheckType = checkType.bind(null, false); 491 chainedCheckType.isRequired = checkType.bind(null, true); 492 493 return chainedCheckType; 494 } 495 496 function createPrimitiveTypeChecker(expectedType) { 497 function validate(props, propName, componentName, location, propFullName, secret) { 498 var propValue = props[propName]; 499 var propType = getPropType(propValue); 500 if (propType !== expectedType) { 501 // `propValue` being instance of, say, date/regexp, pass the 'object' 502 // check, but we can offer a more precise error message here rather than 503 // 'of type `object`'. 504 var preciseType = getPreciseType(propValue); 505 506 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); 507 } 508 return null; 509 } 510 return createChainableTypeChecker(validate); 511 } 512 513 function createAnyTypeChecker() { 514 return createChainableTypeChecker(emptyFunction_1.thatReturnsNull); 515 } 516 517 function createArrayOfTypeChecker(typeChecker) { 518 function validate(props, propName, componentName, location, propFullName) { 519 if (typeof typeChecker !== 'function') { 520 return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); 521 } 522 var propValue = props[propName]; 523 if (!Array.isArray(propValue)) { 524 var propType = getPropType(propValue); 525 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); 526 } 527 for (var i = 0; i < propValue.length; i++) { 528 var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1); 529 if (error instanceof Error) { 530 return error; 531 } 532 } 533 return null; 534 } 535 return createChainableTypeChecker(validate); 536 } 537 538 function createElementTypeChecker() { 539 function validate(props, propName, componentName, location, propFullName) { 540 var propValue = props[propName]; 541 if (!isValidElement(propValue)) { 542 var propType = getPropType(propValue); 543 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); 544 } 545 return null; 546 } 547 return createChainableTypeChecker(validate); 548 } 549 550 function createInstanceTypeChecker(expectedClass) { 551 function validate(props, propName, componentName, location, propFullName) { 552 if (!(props[propName] instanceof expectedClass)) { 553 var expectedClassName = expectedClass.name || ANONYMOUS; 554 var actualClassName = getClassName(props[propName]); 555 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); 556 } 557 return null; 558 } 559 return createChainableTypeChecker(validate); 560 } 561 562 function createEnumTypeChecker(expectedValues) { 563 if (!Array.isArray(expectedValues)) { 564 warning_1(false, 'Invalid argument supplied to oneOf, expected an instance of array.'); 565 return emptyFunction_1.thatReturnsNull; 566 } 567 568 function validate(props, propName, componentName, location, propFullName) { 569 var propValue = props[propName]; 570 for (var i = 0; i < expectedValues.length; i++) { 571 if (is(propValue, expectedValues[i])) { 572 return null; 573 } 574 } 575 576 var valuesString = JSON.stringify(expectedValues); 577 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); 578 } 579 return createChainableTypeChecker(validate); 580 } 581 582 function createObjectOfTypeChecker(typeChecker) { 583 function validate(props, propName, componentName, location, propFullName) { 584 if (typeof typeChecker !== 'function') { 585 return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); 586 } 587 var propValue = props[propName]; 588 var propType = getPropType(propValue); 589 if (propType !== 'object') { 590 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); 591 } 592 for (var key in propValue) { 593 if (propValue.hasOwnProperty(key)) { 594 var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); 595 if (error instanceof Error) { 596 return error; 597 } 598 } 599 } 600 return null; 601 } 602 return createChainableTypeChecker(validate); 603 } 604 605 function createUnionTypeChecker(arrayOfTypeCheckers) { 606 if (!Array.isArray(arrayOfTypeCheckers)) { 607 warning_1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.'); 608 return emptyFunction_1.thatReturnsNull; 609 } 610 611 for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 612 var checker = arrayOfTypeCheckers[i]; 613 if (typeof checker !== 'function') { 614 warning_1( 615 false, 616 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 617 'received %s at index %s.', 618 getPostfixForTypeWarning(checker), 619 i 620 ); 621 return emptyFunction_1.thatReturnsNull; 622 } 623 } 624 625 function validate(props, propName, componentName, location, propFullName) { 626 for (var i = 0; i < arrayOfTypeCheckers.length; i++) { 627 var checker = arrayOfTypeCheckers[i]; 628 if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) { 629 return null; 630 } 631 } 632 633 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); 634 } 635 return createChainableTypeChecker(validate); 636 } 637 638 function createNodeChecker() { 639 function validate(props, propName, componentName, location, propFullName) { 640 if (!isNode(props[propName])) { 641 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); 642 } 643 return null; 644 } 645 return createChainableTypeChecker(validate); 646 } 647 648 function createShapeTypeChecker(shapeTypes) { 649 function validate(props, propName, componentName, location, propFullName) { 650 var propValue = props[propName]; 651 var propType = getPropType(propValue); 652 if (propType !== 'object') { 653 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 654 } 655 for (var key in shapeTypes) { 656 var checker = shapeTypes[key]; 657 if (!checker) { 658 continue; 659 } 660 var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); 661 if (error) { 662 return error; 663 } 664 } 665 return null; 666 } 667 return createChainableTypeChecker(validate); 668 } 669 670 function createStrictShapeTypeChecker(shapeTypes) { 671 function validate(props, propName, componentName, location, propFullName) { 672 var propValue = props[propName]; 673 var propType = getPropType(propValue); 674 if (propType !== 'object') { 675 return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); 676 } 677 // We need to check all keys in case some are required but missing from 678 // props. 679 var allKeys = objectAssign({}, props[propName], shapeTypes); 680 for (var key in allKeys) { 681 var checker = shapeTypes[key]; 682 if (!checker) { 683 return new PropTypeError( 684 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + 685 '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + 686 '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') 687 ); 688 } 689 var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); 690 if (error) { 691 return error; 692 } 693 } 694 return null; 695 } 696 697 return createChainableTypeChecker(validate); 698 } 699 700 function isNode(propValue) { 701 switch (typeof propValue) { 702 case 'number': 703 case 'string': 704 case 'undefined': 705 return true; 706 case 'boolean': 707 return !propValue; 708 case 'object': 709 if (Array.isArray(propValue)) { 710 return propValue.every(isNode); 711 } 712 if (propValue === null || isValidElement(propValue)) { 713 return true; 714 } 715 716 var iteratorFn = getIteratorFn(propValue); 717 if (iteratorFn) { 718 var iterator = iteratorFn.call(propValue); 719 var step; 720 if (iteratorFn !== propValue.entries) { 721 while (!(step = iterator.next()).done) { 722 if (!isNode(step.value)) { 723 return false; 724 } 725 } 726 } else { 727 // Iterator will provide entry [k,v] tuples rather than values. 728 while (!(step = iterator.next()).done) { 729 var entry = step.value; 730 if (entry) { 731 if (!isNode(entry[1])) { 732 return false; 733 } 734 } 735 } 736 } 737 } else { 738 return false; 739 } 740 741 return true; 742 default: 743 return false; 744 } 745 } 746 747 function isSymbol(propType, propValue) { 748 // Native Symbol. 749 if (propType === 'symbol') { 750 return true; 751 } 752 753 // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' 754 if (propValue['@@toStringTag'] === 'Symbol') { 755 return true; 756 } 757 758 // Fallback for non-spec compliant Symbols which are polyfilled. 759 if (typeof Symbol === 'function' && propValue instanceof Symbol) { 760 return true; 761 } 762 763 return false; 764 } 765 766 // Equivalent of `typeof` but with special handling for array and regexp. 767 function getPropType(propValue) { 768 var propType = typeof propValue; 769 if (Array.isArray(propValue)) { 770 return 'array'; 771 } 772 if (propValue instanceof RegExp) { 773 // Old webkits (at least until Android 4.0) return 'function' rather than 774 // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ 775 // passes PropTypes.object. 776 return 'object'; 777 } 778 if (isSymbol(propType, propValue)) { 779 return 'symbol'; 780 } 781 return propType; 782 } 783 784 // This handles more types than `getPropType`. Only used for error messages. 785 // See `createPrimitiveTypeChecker`. 786 function getPreciseType(propValue) { 787 if (typeof propValue === 'undefined' || propValue === null) { 788 return '' + propValue; 789 } 790 var propType = getPropType(propValue); 791 if (propType === 'object') { 792 if (propValue instanceof Date) { 793 return 'date'; 794 } else if (propValue instanceof RegExp) { 795 return 'regexp'; 796 } 797 } 798 return propType; 799 } 800 801 // Returns a string that is postfixed to a warning about an invalid type. 802 // For example, "undefined" or "of type array" 803 function getPostfixForTypeWarning(value) { 804 var type = getPreciseType(value); 805 switch (type) { 806 case 'array': 807 case 'object': 808 return 'an ' + type; 809 case 'boolean': 810 case 'date': 811 case 'regexp': 812 return 'a ' + type; 813 default: 814 return type; 815 } 816 } 817 818 // Returns class name of the object, if any. 819 function getClassName(propValue) { 820 if (!propValue.constructor || !propValue.constructor.name) { 821 return ANONYMOUS; 822 } 823 return propValue.constructor.name; 824 } 825 826 ReactPropTypes.checkPropTypes = checkPropTypes_1; 827 ReactPropTypes.PropTypes = ReactPropTypes; 828 829 return ReactPropTypes; 830 }; 831 832 var propTypes = createCommonjsModule(function (module) { 833 /** 834 * Copyright (c) 2013-present, Facebook, Inc. 835 * 836 * This source code is licensed under the MIT license found in the 837 * LICENSE file in the root directory of this source tree. 838 */ 839 840 { 841 var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && 842 Symbol.for && 843 Symbol.for('react.element')) || 844 0xeac7; 845 846 var isValidElement = function(object) { 847 return typeof object === 'object' && 848 object !== null && 849 object.$$typeof === REACT_ELEMENT_TYPE; 850 }; 851 852 // By explicitly using `prop-types` you are opting into new development behavior. 853 // http://fb.me/prop-types-in-prod 854 var throwOnDirectAccess = true; 855 module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess); 856 } 857 }); 858 859 var subscriptionShape = propTypes.shape({ 860 trySubscribe: propTypes.func.isRequired, 861 tryUnsubscribe: propTypes.func.isRequired, 862 notifyNestedSubs: propTypes.func.isRequired, 863 isSubscribed: propTypes.func.isRequired 864 }); 865 866 var storeShape = propTypes.shape({ 867 subscribe: propTypes.func.isRequired, 868 dispatch: propTypes.func.isRequired, 869 getState: propTypes.func.isRequired 870 }); 871 872 /** 873 * Prints a warning in the console if it exists. 874 * 875 * @param {String} message The warning message. 876 * @returns {void} 877 */ 878 function warning$2(message) { 879 /* eslint-disable no-console */ 880 if (typeof console !== 'undefined' && typeof console.error === 'function') { 881 console.error(message); 882 } 883 /* eslint-enable no-console */ 884 try { 885 // This error was thrown as a convenience so that if you enable 886 // "break on all exceptions" in your console, 887 // it would pause the execution at this line. 888 throw new Error(message); 889 /* eslint-disable no-empty */ 890 } catch (e) {} 891 /* eslint-enable no-empty */ 892 } 893 894 var classCallCheck = function (instance, Constructor) { 895 if (!(instance instanceof Constructor)) { 896 throw new TypeError("Cannot call a class as a function"); 897 } 898 }; 899 900 var _extends = Object.assign || function (target) { 901 for (var i = 1; i < arguments.length; i++) { 902 var source = arguments[i]; 903 904 for (var key in source) { 905 if (Object.prototype.hasOwnProperty.call(source, key)) { 906 target[key] = source[key]; 907 } 908 } 909 } 910 911 return target; 912 }; 913 914 var inherits = function (subClass, superClass) { 915 if (typeof superClass !== "function" && superClass !== null) { 916 throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); 917 } 918 919 subClass.prototype = Object.create(superClass && superClass.prototype, { 920 constructor: { 921 value: subClass, 922 enumerable: false, 923 writable: true, 924 configurable: true 925 } 926 }); 927 if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; 928 }; 929 930 var objectWithoutProperties = function (obj, keys) { 931 var target = {}; 932 933 for (var i in obj) { 934 if (keys.indexOf(i) >= 0) continue; 935 if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; 936 target[i] = obj[i]; 937 } 938 939 return target; 940 }; 941 942 var possibleConstructorReturn = function (self, call) { 943 if (!self) { 944 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 945 } 946 947 return call && (typeof call === "object" || typeof call === "function") ? call : self; 948 }; 949 950 var didWarnAboutReceivingStore = false; 951 function warnAboutReceivingStore() { 952 if (didWarnAboutReceivingStore) { 953 return; 954 } 955 didWarnAboutReceivingStore = true; 956 957 warning$2('<Provider> does not support changing `store` on the fly. ' + 'It is most likely that you see this error because you updated to ' + 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + 'automatically. See https://github.com/reactjs/react-redux/releases/' + 'tag/v2.0.0 for the migration instructions.'); 958 } 959 960 function createProvider() { 961 var _Provider$childContex; 962 963 var storeKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'store'; 964 var subKey = arguments[1]; 965 966 var subscriptionKey = subKey || storeKey + 'Subscription'; 967 968 var Provider = function (_Component) { 969 inherits(Provider, _Component); 970 971 Provider.prototype.getChildContext = function getChildContext() { 972 var _ref; 973 974 return _ref = {}, _ref[storeKey] = this[storeKey], _ref[subscriptionKey] = null, _ref; 975 }; 976 977 function Provider(props, context) { 978 classCallCheck(this, Provider); 979 980 var _this = possibleConstructorReturn(this, _Component.call(this, props, context)); 981 982 _this[storeKey] = props.store; 983 return _this; 984 } 985 986 Provider.prototype.render = function render() { 987 return react.Children.only(this.props.children); 988 }; 989 990 return Provider; 991 }(react.Component); 992 993 { 994 Provider.prototype.componentWillReceiveProps = function (nextProps) { 995 if (this[storeKey] !== nextProps.store) { 996 warnAboutReceivingStore(); 997 } 998 }; 999 } 1000 1001 Provider.propTypes = { 1002 store: storeShape.isRequired, 1003 children: propTypes.element.isRequired 1004 }; 1005 Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[storeKey] = storeShape.isRequired, _Provider$childContex[subscriptionKey] = subscriptionShape, _Provider$childContex); 1006 1007 return Provider; 1008 } 1009 1010 var Provider = createProvider(); 1011 1012 var hoistNonReactStatics = createCommonjsModule(function (module, exports) { 1013 /** 1014 * Copyright 2015, Yahoo! Inc. 1015 * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. 1016 */ 1017 (function (global, factory) { 1018 module.exports = factory(); 1019 }(commonjsGlobal, (function () { 1020 1021 var REACT_STATICS = { 1022 childContextTypes: true, 1023 contextTypes: true, 1024 defaultProps: true, 1025 displayName: true, 1026 getDefaultProps: true, 1027 getDerivedStateFromProps: true, 1028 mixins: true, 1029 propTypes: true, 1030 type: true 1031 }; 1032 1033 var KNOWN_STATICS = { 1034 name: true, 1035 length: true, 1036 prototype: true, 1037 caller: true, 1038 callee: true, 1039 arguments: true, 1040 arity: true 1041 }; 1042 1043 var defineProperty = Object.defineProperty; 1044 var getOwnPropertyNames = Object.getOwnPropertyNames; 1045 var getOwnPropertySymbols = Object.getOwnPropertySymbols; 1046 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; 1047 var getPrototypeOf = Object.getPrototypeOf; 1048 var objectPrototype = getPrototypeOf && getPrototypeOf(Object); 1049 1050 return function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) { 1051 if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components 1052 1053 if (objectPrototype) { 1054 var inheritedComponent = getPrototypeOf(sourceComponent); 1055 if (inheritedComponent && inheritedComponent !== objectPrototype) { 1056 hoistNonReactStatics(targetComponent, inheritedComponent, blacklist); 1057 } 1058 } 1059 1060 var keys = getOwnPropertyNames(sourceComponent); 1061 1062 if (getOwnPropertySymbols) { 1063 keys = keys.concat(getOwnPropertySymbols(sourceComponent)); 1064 } 1065 1066 for (var i = 0; i < keys.length; ++i) { 1067 var key = keys[i]; 1068 if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) { 1069 var descriptor = getOwnPropertyDescriptor(sourceComponent, key); 1070 try { // Avoid failures from read-only properties 1071 defineProperty(targetComponent, key, descriptor); 1072 } catch (e) {} 1073 } 1074 } 1075 1076 return targetComponent; 1077 } 1078 1079 return targetComponent; 1080 }; 1081 }))); 1082 }); 1083 1084 /** 1085 * Copyright 2013-2015, Facebook, Inc. 1086 * All rights reserved. 1087 * 1088 * This source code is licensed under the BSD-style license found in the 1089 * LICENSE file in the root directory of this source tree. An additional grant 1090 * of patent rights can be found in the PATENTS file in the same directory. 1091 */ 1092 1093 /** 1094 * Use invariant() to assert state which your program assumes to be true. 1095 * 1096 * Provide sprintf-style format (only %s is supported) and arguments 1097 * to provide information about what broke and what you were 1098 * expecting. 1099 * 1100 * The invariant message will be stripped in production, but the invariant 1101 * will remain to ensure logic does not differ in production. 1102 */ 1103 1104 var NODE_ENV = "development"; 1105 1106 var invariant$2 = function(condition, format, a, b, c, d, e, f) { 1107 if (NODE_ENV !== 'production') { 1108 if (format === undefined) { 1109 throw new Error('invariant requires an error message argument'); 1110 } 1111 } 1112 1113 if (!condition) { 1114 var error; 1115 if (format === undefined) { 1116 error = new Error( 1117 'Minified exception occurred; use the non-minified dev environment ' + 1118 'for the full error message and additional helpful warnings.' 1119 ); 1120 } else { 1121 var args = [a, b, c, d, e, f]; 1122 var argIndex = 0; 1123 error = new Error( 1124 format.replace(/%s/g, function() { return args[argIndex++]; }) 1125 ); 1126 error.name = 'Invariant Violation'; 1127 } 1128 1129 error.framesToPop = 1; // we don't care about invariant's own frame 1130 throw error; 1131 } 1132 }; 1133 1134 var invariant_1$2 = invariant$2; 1135 1136 // encapsulates the subscription logic for connecting a component to the redux store, as 1137 // well as nesting subscriptions of descendant components, so that we can ensure the 1138 // ancestor components re-render before descendants 1139 1140 var CLEARED = null; 1141 var nullListeners = { 1142 notify: function notify() {} 1143 }; 1144 1145 function createListenerCollection() { 1146 // the current/next pattern is copied from redux's createStore code. 1147 // TODO: refactor+expose that code to be reusable here? 1148 var current = []; 1149 var next = []; 1150 1151 return { 1152 clear: function clear() { 1153 next = CLEARED; 1154 current = CLEARED; 1155 }, 1156 notify: function notify() { 1157 var listeners = current = next; 1158 for (var i = 0; i < listeners.length; i++) { 1159 listeners[i](); 1160 } 1161 }, 1162 get: function get$$1() { 1163 return next; 1164 }, 1165 subscribe: function subscribe(listener) { 1166 var isSubscribed = true; 1167 if (next === current) next = current.slice(); 1168 next.push(listener); 1169 1170 return function unsubscribe() { 1171 if (!isSubscribed || current === CLEARED) return; 1172 isSubscribed = false; 1173 1174 if (next === current) next = current.slice(); 1175 next.splice(next.indexOf(listener), 1); 1176 }; 1177 } 1178 }; 1179 } 1180 1181 var Subscription = function () { 1182 function Subscription(store, parentSub, onStateChange) { 1183 classCallCheck(this, Subscription); 1184 1185 this.store = store; 1186 this.parentSub = parentSub; 1187 this.onStateChange = onStateChange; 1188 this.unsubscribe = null; 1189 this.listeners = nullListeners; 1190 } 1191 1192 Subscription.prototype.addNestedSub = function addNestedSub(listener) { 1193 this.trySubscribe(); 1194 return this.listeners.subscribe(listener); 1195 }; 1196 1197 Subscription.prototype.notifyNestedSubs = function notifyNestedSubs() { 1198 this.listeners.notify(); 1199 }; 1200 1201 Subscription.prototype.isSubscribed = function isSubscribed() { 1202 return Boolean(this.unsubscribe); 1203 }; 1204 1205 Subscription.prototype.trySubscribe = function trySubscribe() { 1206 if (!this.unsubscribe) { 1207 this.unsubscribe = this.parentSub ? this.parentSub.addNestedSub(this.onStateChange) : this.store.subscribe(this.onStateChange); 1208 1209 this.listeners = createListenerCollection(); 1210 } 1211 }; 1212 1213 Subscription.prototype.tryUnsubscribe = function tryUnsubscribe() { 1214 if (this.unsubscribe) { 1215 this.unsubscribe(); 1216 this.unsubscribe = null; 1217 this.listeners.clear(); 1218 this.listeners = nullListeners; 1219 } 1220 }; 1221 1222 return Subscription; 1223 }(); 1224 1225 var hotReloadingVersion = 0; 1226 var dummyState = {}; 1227 function noop() {} 1228 function makeSelectorStateful(sourceSelector, store) { 1229 // wrap the selector in an object that tracks its results between runs. 1230 var selector = { 1231 run: function runComponentSelector(props) { 1232 try { 1233 var nextProps = sourceSelector(store.getState(), props); 1234 if (nextProps !== selector.props || selector.error) { 1235 selector.shouldComponentUpdate = true; 1236 selector.props = nextProps; 1237 selector.error = null; 1238 } 1239 } catch (error) { 1240 selector.shouldComponentUpdate = true; 1241 selector.error = error; 1242 } 1243 } 1244 }; 1245 1246 return selector; 1247 } 1248 1249 function connectAdvanced( 1250 /* 1251 selectorFactory is a func that is responsible for returning the selector function used to 1252 compute new props from state, props, and dispatch. For example: 1253 export default connectAdvanced((dispatch, options) => (state, props) => ({ 1254 thing: state.things[props.thingId], 1255 saveThing: fields => dispatch(actionCreators.saveThing(props.thingId, fields)), 1256 }))(YourComponent) 1257 Access to dispatch is provided to the factory so selectorFactories can bind actionCreators 1258 outside of their selector as an optimization. Options passed to connectAdvanced are passed to 1259 the selectorFactory, along with displayName and WrappedComponent, as the second argument. 1260 Note that selectorFactory is responsible for all caching/memoization of inbound and outbound 1261 props. Do not use connectAdvanced directly without memoizing results between calls to your 1262 selector, otherwise the Connect component will re-render on every state or props change. 1263 */ 1264 selectorFactory) { 1265 var _contextTypes, _childContextTypes; 1266 1267 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, 1268 _ref$getDisplayName = _ref.getDisplayName, 1269 getDisplayName = _ref$getDisplayName === undefined ? function (name) { 1270 return 'ConnectAdvanced(' + name + ')'; 1271 } : _ref$getDisplayName, 1272 _ref$methodName = _ref.methodName, 1273 methodName = _ref$methodName === undefined ? 'connectAdvanced' : _ref$methodName, 1274 _ref$renderCountProp = _ref.renderCountProp, 1275 renderCountProp = _ref$renderCountProp === undefined ? undefined : _ref$renderCountProp, 1276 _ref$shouldHandleStat = _ref.shouldHandleStateChanges, 1277 shouldHandleStateChanges = _ref$shouldHandleStat === undefined ? true : _ref$shouldHandleStat, 1278 _ref$storeKey = _ref.storeKey, 1279 storeKey = _ref$storeKey === undefined ? 'store' : _ref$storeKey, 1280 _ref$withRef = _ref.withRef, 1281 withRef = _ref$withRef === undefined ? false : _ref$withRef, 1282 connectOptions = objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef']); 1283 1284 var subscriptionKey = storeKey + 'Subscription'; 1285 var version = hotReloadingVersion++; 1286 1287 var contextTypes = (_contextTypes = {}, _contextTypes[storeKey] = storeShape, _contextTypes[subscriptionKey] = subscriptionShape, _contextTypes); 1288 var childContextTypes = (_childContextTypes = {}, _childContextTypes[subscriptionKey] = subscriptionShape, _childContextTypes); 1289 1290 return function wrapWithConnect(WrappedComponent) { 1291 invariant_1$2(typeof WrappedComponent == 'function', 'You must pass a component to the function returned by ' + (methodName + '. Instead received ' + JSON.stringify(WrappedComponent))); 1292 1293 var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component'; 1294 1295 var displayName = getDisplayName(wrappedComponentName); 1296 1297 var selectorFactoryOptions = _extends({}, connectOptions, { 1298 getDisplayName: getDisplayName, 1299 methodName: methodName, 1300 renderCountProp: renderCountProp, 1301 shouldHandleStateChanges: shouldHandleStateChanges, 1302 storeKey: storeKey, 1303 withRef: withRef, 1304 displayName: displayName, 1305 wrappedComponentName: wrappedComponentName, 1306 WrappedComponent: WrappedComponent 1307 }); 1308 1309 var Connect = function (_Component) { 1310 inherits(Connect, _Component); 1311 1312 function Connect(props, context) { 1313 classCallCheck(this, Connect); 1314 1315 var _this = possibleConstructorReturn(this, _Component.call(this, props, context)); 1316 1317 _this.version = version; 1318 _this.state = {}; 1319 _this.renderCount = 0; 1320 _this.store = props[storeKey] || context[storeKey]; 1321 _this.propsMode = Boolean(props[storeKey]); 1322 _this.setWrappedInstance = _this.setWrappedInstance.bind(_this); 1323 1324 invariant_1$2(_this.store, 'Could not find "' + storeKey + '" in either the context or props of ' + ('"' + displayName + '". Either wrap the root component in a <Provider>, ') + ('or explicitly pass "' + storeKey + '" as a prop to "' + displayName + '".')); 1325 1326 _this.initSelector(); 1327 _this.initSubscription(); 1328 return _this; 1329 } 1330 1331 Connect.prototype.getChildContext = function getChildContext() { 1332 var _ref2; 1333 1334 // If this component received store from props, its subscription should be transparent 1335 // to any descendants receiving store+subscription from context; it passes along 1336 // subscription passed to it. Otherwise, it shadows the parent subscription, which allows 1337 // Connect to control ordering of notifications to flow top-down. 1338 var subscription = this.propsMode ? null : this.subscription; 1339 return _ref2 = {}, _ref2[subscriptionKey] = subscription || this.context[subscriptionKey], _ref2; 1340 }; 1341 1342 Connect.prototype.componentDidMount = function componentDidMount() { 1343 if (!shouldHandleStateChanges) return; 1344 1345 // componentWillMount fires during server side rendering, but componentDidMount and 1346 // componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount. 1347 // Otherwise, unsubscription would never take place during SSR, causing a memory leak. 1348 // To handle the case where a child component may have triggered a state change by 1349 // dispatching an action in its componentWillMount, we have to re-run the select and maybe 1350 // re-render. 1351 this.subscription.trySubscribe(); 1352 this.selector.run(this.props); 1353 if (this.selector.shouldComponentUpdate) this.forceUpdate(); 1354 }; 1355 1356 Connect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { 1357 this.selector.run(nextProps); 1358 }; 1359 1360 Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate() { 1361 return this.selector.shouldComponentUpdate; 1362 }; 1363 1364 Connect.prototype.componentWillUnmount = function componentWillUnmount() { 1365 if (this.subscription) this.subscription.tryUnsubscribe(); 1366 this.subscription = null; 1367 this.notifyNestedSubs = noop; 1368 this.store = null; 1369 this.selector.run = noop; 1370 this.selector.shouldComponentUpdate = false; 1371 }; 1372 1373 Connect.prototype.getWrappedInstance = function getWrappedInstance() { 1374 invariant_1$2(withRef, 'To access the wrapped instance, you need to specify ' + ('{ withRef: true } in the options argument of the ' + methodName + '() call.')); 1375 return this.wrappedInstance; 1376 }; 1377 1378 Connect.prototype.setWrappedInstance = function setWrappedInstance(ref) { 1379 this.wrappedInstance = ref; 1380 }; 1381 1382 Connect.prototype.initSelector = function initSelector() { 1383 var sourceSelector = selectorFactory(this.store.dispatch, selectorFactoryOptions); 1384 this.selector = makeSelectorStateful(sourceSelector, this.store); 1385 this.selector.run(this.props); 1386 }; 1387 1388 Connect.prototype.initSubscription = function initSubscription() { 1389 if (!shouldHandleStateChanges) return; 1390 1391 // parentSub's source should match where store came from: props vs. context. A component 1392 // connected to the store via props shouldn't use subscription from context, or vice versa. 1393 var parentSub = (this.propsMode ? this.props : this.context)[subscriptionKey]; 1394 this.subscription = new Subscription(this.store, parentSub, this.onStateChange.bind(this)); 1395 1396 // `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in 1397 // the middle of the notification loop, where `this.subscription` will then be null. An 1398 // extra null check every change can be avoided by copying the method onto `this` and then 1399 // replacing it with a no-op on unmount. This can probably be avoided if Subscription's 1400 // listeners logic is changed to not call listeners that have been unsubscribed in the 1401 // middle of the notification loop. 1402 this.notifyNestedSubs = this.subscription.notifyNestedSubs.bind(this.subscription); 1403 }; 1404 1405 Connect.prototype.onStateChange = function onStateChange() { 1406 this.selector.run(this.props); 1407 1408 if (!this.selector.shouldComponentUpdate) { 1409 this.notifyNestedSubs(); 1410 } else { 1411 this.componentDidUpdate = this.notifyNestedSubsOnComponentDidUpdate; 1412 this.setState(dummyState); 1413 } 1414 }; 1415 1416 Connect.prototype.notifyNestedSubsOnComponentDidUpdate = function notifyNestedSubsOnComponentDidUpdate() { 1417 // `componentDidUpdate` is conditionally implemented when `onStateChange` determines it 1418 // needs to notify nested subs. Once called, it unimplements itself until further state 1419 // changes occur. Doing it this way vs having a permanent `componentDidUpdate` that does 1420 // a boolean check every time avoids an extra method call most of the time, resulting 1421 // in some perf boost. 1422 this.componentDidUpdate = undefined; 1423 this.notifyNestedSubs(); 1424 }; 1425 1426 Connect.prototype.isSubscribed = function isSubscribed() { 1427 return Boolean(this.subscription) && this.subscription.isSubscribed(); 1428 }; 1429 1430 Connect.prototype.addExtraProps = function addExtraProps(props) { 1431 if (!withRef && !renderCountProp && !(this.propsMode && this.subscription)) return props; 1432 // make a shallow copy so that fields added don't leak to the original selector. 1433 // this is especially important for 'ref' since that's a reference back to the component 1434 // instance. a singleton memoized selector would then be holding a reference to the 1435 // instance, preventing the instance from being garbage collected, and that would be bad 1436 var withExtras = _extends({}, props); 1437 if (withRef) withExtras.ref = this.setWrappedInstance; 1438 if (renderCountProp) withExtras[renderCountProp] = this.renderCount++; 1439 if (this.propsMode && this.subscription) withExtras[subscriptionKey] = this.subscription; 1440 return withExtras; 1441 }; 1442 1443 Connect.prototype.render = function render() { 1444 var selector = this.selector; 1445 selector.shouldComponentUpdate = false; 1446 1447 if (selector.error) { 1448 throw selector.error; 1449 } else { 1450 return react.createElement(WrappedComponent, this.addExtraProps(selector.props)); 1451 } 1452 }; 1453 1454 return Connect; 1455 }(react.Component); 1456 1457 Connect.WrappedComponent = WrappedComponent; 1458 Connect.displayName = displayName; 1459 Connect.childContextTypes = childContextTypes; 1460 Connect.contextTypes = contextTypes; 1461 Connect.propTypes = contextTypes; 1462 1463 { 1464 Connect.prototype.componentWillUpdate = function componentWillUpdate() { 1465 var _this2 = this; 1466 1467 // We are hot reloading! 1468 if (this.version !== version) { 1469 this.version = version; 1470 this.initSelector(); 1471 1472 // If any connected descendants don't hot reload (and resubscribe in the process), their 1473 // listeners will be lost when we unsubscribe. Unfortunately, by copying over all 1474 // listeners, this does mean that the old versions of connected descendants will still be 1475 // notified of state changes; however, their onStateChange function is a no-op so this 1476 // isn't a huge deal. 1477 var oldListeners = []; 1478 1479 if (this.subscription) { 1480 oldListeners = this.subscription.listeners.get(); 1481 this.subscription.tryUnsubscribe(); 1482 } 1483 this.initSubscription(); 1484 if (shouldHandleStateChanges) { 1485 this.subscription.trySubscribe(); 1486 oldListeners.forEach(function (listener) { 1487 return _this2.subscription.listeners.subscribe(listener); 1488 }); 1489 } 1490 } 1491 }; 1492 } 1493 1494 return hoistNonReactStatics(Connect, WrappedComponent); 1495 }; 1496 } 1497 1498 var hasOwn = Object.prototype.hasOwnProperty; 1499 1500 function is(x, y) { 1501 if (x === y) { 1502 return x !== 0 || y !== 0 || 1 / x === 1 / y; 1503 } else { 1504 return x !== x && y !== y; 1505 } 1506 } 1507 1508 function shallowEqual(objA, objB) { 1509 if (is(objA, objB)) return true; 1510 1511 if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { 1512 return false; 1513 } 1514 1515 var keysA = Object.keys(objA); 1516 var keysB = Object.keys(objB); 1517 1518 if (keysA.length !== keysB.length) return false; 1519 1520 for (var i = 0; i < keysA.length; i++) { 1521 if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { 1522 return false; 1523 } 1524 } 1525 1526 return true; 1527 } 1528 1529 /** Detect free variable `global` from Node.js. */ 1530 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; 1531 1532 /** Detect free variable `self`. */ 1533 var freeSelf = typeof self == 'object' && self && self.Object === Object && self; 1534 1535 /** Used as a reference to the global object. */ 1536 var root = freeGlobal || freeSelf || globalThis; 1537 1538 /** Built-in value references. */ 1539 var Symbol$1 = root.Symbol; 1540 1541 /** Used for built-in method references. */ 1542 var objectProto = Object.prototype; 1543 1544 /** Used to check objects for own properties. */ 1545 var hasOwnProperty$1 = objectProto.hasOwnProperty; 1546 1547 /** 1548 * Used to resolve the 1549 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) 1550 * of values. 1551 */ 1552 var nativeObjectToString = objectProto.toString; 1553 1554 /** Built-in value references. */ 1555 var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined; 1556 1557 /** 1558 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. 1559 * 1560 * @private 1561 * @param {*} value The value to query. 1562 * @returns {string} Returns the raw `toStringTag`. 1563 */ 1564 function getRawTag(value) { 1565 var isOwn = hasOwnProperty$1.call(value, symToStringTag), 1566 tag = value[symToStringTag]; 1567 1568 try { 1569 value[symToStringTag] = undefined; 1570 var unmasked = true; 1571 } catch (e) {} 1572 1573 var result = nativeObjectToString.call(value); 1574 if (unmasked) { 1575 if (isOwn) { 1576 value[symToStringTag] = tag; 1577 } else { 1578 delete value[symToStringTag]; 1579 } 1580 } 1581 return result; 1582 } 1583 1584 /** Used for built-in method references. */ 1585 var objectProto$1 = Object.prototype; 1586 1587 /** 1588 * Used to resolve the 1589 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) 1590 * of values. 1591 */ 1592 var nativeObjectToString$1 = objectProto$1.toString; 1593 1594 /** 1595 * Converts `value` to a string using `Object.prototype.toString`. 1596 * 1597 * @private 1598 * @param {*} value The value to convert. 1599 * @returns {string} Returns the converted string. 1600 */ 1601 function objectToString(value) { 1602 return nativeObjectToString$1.call(value); 1603 } 1604 1605 /** `Object#toString` result references. */ 1606 var nullTag = '[object Null]', 1607 undefinedTag = '[object Undefined]'; 1608 1609 /** Built-in value references. */ 1610 var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined; 1611 1612 /** 1613 * The base implementation of `getTag` without fallbacks for buggy environments. 1614 * 1615 * @private 1616 * @param {*} value The value to query. 1617 * @returns {string} Returns the `toStringTag`. 1618 */ 1619 function baseGetTag(value) { 1620 if (value == null) { 1621 return value === undefined ? undefinedTag : nullTag; 1622 } 1623 return (symToStringTag$1 && symToStringTag$1 in Object(value)) 1624 ? getRawTag(value) 1625 : objectToString(value); 1626 } 1627 1628 /** 1629 * Creates a unary function that invokes `func` with its argument transformed. 1630 * 1631 * @private 1632 * @param {Function} func The function to wrap. 1633 * @param {Function} transform The argument transform. 1634 * @returns {Function} Returns the new function. 1635 */ 1636 function overArg(func, transform) { 1637 return function(arg) { 1638 return func(transform(arg)); 1639 }; 1640 } 1641 1642 /** Built-in value references. */ 1643 var getPrototype = overArg(Object.getPrototypeOf, Object); 1644 1645 /** 1646 * Checks if `value` is object-like. A value is object-like if it's not `null` 1647 * and has a `typeof` result of "object". 1648 * 1649 * @static 1650 * @memberOf _ 1651 * @since 4.0.0 1652 * @category Lang 1653 * @param {*} value The value to check. 1654 * @returns {boolean} Returns `true` if `value` is object-like, else `false`. 1655 * @example 1656 * 1657 * _.isObjectLike({}); 1658 * // => true 1659 * 1660 * _.isObjectLike([1, 2, 3]); 1661 * // => true 1662 * 1663 * _.isObjectLike(_.noop); 1664 * // => false 1665 * 1666 * _.isObjectLike(null); 1667 * // => false 1668 */ 1669 function isObjectLike(value) { 1670 return value != null && typeof value == 'object'; 1671 } 1672 1673 /** `Object#toString` result references. */ 1674 var objectTag = '[object Object]'; 1675 1676 /** Used for built-in method references. */ 1677 var funcProto = Function.prototype, 1678 objectProto$2 = Object.prototype; 1679 1680 /** Used to resolve the decompiled source of functions. */ 1681 var funcToString = funcProto.toString; 1682 1683 /** Used to check objects for own properties. */ 1684 var hasOwnProperty$2 = objectProto$2.hasOwnProperty; 1685 1686 /** Used to infer the `Object` constructor. */ 1687 var objectCtorString = funcToString.call(Object); 1688 1689 /** 1690 * Checks if `value` is a plain object, that is, an object created by the 1691 * `Object` constructor or one with a `[[Prototype]]` of `null`. 1692 * 1693 * @static 1694 * @memberOf _ 1695 * @since 0.8.0 1696 * @category Lang 1697 * @param {*} value The value to check. 1698 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. 1699 * @example 1700 * 1701 * function Foo() { 1702 * this.a = 1; 1703 * } 1704 * 1705 * _.isPlainObject(new Foo); 1706 * // => false 1707 * 1708 * _.isPlainObject([1, 2, 3]); 1709 * // => false 1710 * 1711 * _.isPlainObject({ 'x': 0, 'y': 0 }); 1712 * // => true 1713 * 1714 * _.isPlainObject(Object.create(null)); 1715 * // => true 1716 */ 1717 function isPlainObject(value) { 1718 if (!isObjectLike(value) || baseGetTag(value) != objectTag) { 1719 return false; 1720 } 1721 var proto = getPrototype(value); 1722 if (proto === null) { 1723 return true; 1724 } 1725 var Ctor = hasOwnProperty$2.call(proto, 'constructor') && proto.constructor; 1726 return typeof Ctor == 'function' && Ctor instanceof Ctor && 1727 funcToString.call(Ctor) == objectCtorString; 1728 } 1729 1730 function verifyPlainObject(value, displayName, methodName) { 1731 if (!isPlainObject(value)) { 1732 warning$2(methodName + '() in ' + displayName + ' must return a plain object. Instead received ' + value + '.'); 1733 } 1734 } 1735 1736 function wrapMapToPropsConstant(getConstant) { 1737 return function initConstantSelector(dispatch, options) { 1738 var constant = getConstant(dispatch, options); 1739 1740 function constantSelector() { 1741 return constant; 1742 } 1743 constantSelector.dependsOnOwnProps = false; 1744 return constantSelector; 1745 }; 1746 } 1747 1748 // dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args 1749 // to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine 1750 // whether mapToProps needs to be invoked when props have changed. 1751 // 1752 // A length of one signals that mapToProps does not depend on props from the parent component. 1753 // A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and 1754 // therefore not reporting its length accurately.. 1755 function getDependsOnOwnProps(mapToProps) { 1756 return mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1; 1757 } 1758 1759 // Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction, 1760 // this function wraps mapToProps in a proxy function which does several things: 1761 // 1762 // * Detects whether the mapToProps function being called depends on props, which 1763 // is used by selectorFactory to decide if it should reinvoke on props changes. 1764 // 1765 // * On first call, handles mapToProps if returns another function, and treats that 1766 // new function as the true mapToProps for subsequent calls. 1767 // 1768 // * On first call, verifies the first result is a plain object, in order to warn 1769 // the developer that their mapToProps function is not returning a valid result. 1770 // 1771 function wrapMapToPropsFunc(mapToProps, methodName) { 1772 return function initProxySelector(dispatch, _ref) { 1773 var displayName = _ref.displayName; 1774 1775 var proxy = function mapToPropsProxy(stateOrDispatch, ownProps) { 1776 return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch); 1777 }; 1778 1779 // allow detectFactoryAndVerify to get ownProps 1780 proxy.dependsOnOwnProps = true; 1781 1782 proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) { 1783 proxy.mapToProps = mapToProps; 1784 proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps); 1785 var props = proxy(stateOrDispatch, ownProps); 1786 1787 if (typeof props === 'function') { 1788 proxy.mapToProps = props; 1789 proxy.dependsOnOwnProps = getDependsOnOwnProps(props); 1790 props = proxy(stateOrDispatch, ownProps); 1791 } 1792 1793 verifyPlainObject(props, displayName, methodName); 1794 1795 return props; 1796 }; 1797 1798 return proxy; 1799 }; 1800 } 1801 1802 function whenMapDispatchToPropsIsFunction(mapDispatchToProps) { 1803 return typeof mapDispatchToProps === 'function' ? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') : undefined; 1804 } 1805 1806 function whenMapDispatchToPropsIsMissing(mapDispatchToProps) { 1807 return !mapDispatchToProps ? wrapMapToPropsConstant(function (dispatch) { 1808 return { dispatch: dispatch }; 1809 }) : undefined; 1810 } 1811 1812 function whenMapDispatchToPropsIsObject(mapDispatchToProps) { 1813 return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(function (dispatch) { 1814 return redux.bindActionCreators(mapDispatchToProps, dispatch); 1815 }) : undefined; 1816 } 1817 1818 var defaultMapDispatchToPropsFactories = [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject]; 1819 1820 function whenMapStateToPropsIsFunction(mapStateToProps) { 1821 return typeof mapStateToProps === 'function' ? wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') : undefined; 1822 } 1823 1824 function whenMapStateToPropsIsMissing(mapStateToProps) { 1825 return !mapStateToProps ? wrapMapToPropsConstant(function () { 1826 return {}; 1827 }) : undefined; 1828 } 1829 1830 var defaultMapStateToPropsFactories = [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing]; 1831 1832 function defaultMergeProps(stateProps, dispatchProps, ownProps) { 1833 return _extends({}, ownProps, stateProps, dispatchProps); 1834 } 1835 1836 function wrapMergePropsFunc(mergeProps) { 1837 return function initMergePropsProxy(dispatch, _ref) { 1838 var displayName = _ref.displayName, 1839 pure = _ref.pure, 1840 areMergedPropsEqual = _ref.areMergedPropsEqual; 1841 1842 var hasRunOnce = false; 1843 var mergedProps = void 0; 1844 1845 return function mergePropsProxy(stateProps, dispatchProps, ownProps) { 1846 var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps); 1847 1848 if (hasRunOnce) { 1849 if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps; 1850 } else { 1851 hasRunOnce = true; 1852 mergedProps = nextMergedProps; 1853 1854 verifyPlainObject(mergedProps, displayName, 'mergeProps'); 1855 } 1856 1857 return mergedProps; 1858 }; 1859 }; 1860 } 1861 1862 function whenMergePropsIsFunction(mergeProps) { 1863 return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined; 1864 } 1865 1866 function whenMergePropsIsOmitted(mergeProps) { 1867 return !mergeProps ? function () { 1868 return defaultMergeProps; 1869 } : undefined; 1870 } 1871 1872 var defaultMergePropsFactories = [whenMergePropsIsFunction, whenMergePropsIsOmitted]; 1873 1874 function verify(selector, methodName, displayName) { 1875 if (!selector) { 1876 throw new Error('Unexpected value for ' + methodName + ' in ' + displayName + '.'); 1877 } else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') { 1878 if (!selector.hasOwnProperty('dependsOnOwnProps')) { 1879 warning$2('The selector for ' + methodName + ' of ' + displayName + ' did not specify a value for dependsOnOwnProps.'); 1880 } 1881 } 1882 } 1883 1884 function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) { 1885 verify(mapStateToProps, 'mapStateToProps', displayName); 1886 verify(mapDispatchToProps, 'mapDispatchToProps', displayName); 1887 verify(mergeProps, 'mergeProps', displayName); 1888 } 1889 1890 function impureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch) { 1891 return function impureFinalPropsSelector(state, ownProps) { 1892 return mergeProps(mapStateToProps(state, ownProps), mapDispatchToProps(dispatch, ownProps), ownProps); 1893 }; 1894 } 1895 1896 function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, _ref) { 1897 var areStatesEqual = _ref.areStatesEqual, 1898 areOwnPropsEqual = _ref.areOwnPropsEqual, 1899 areStatePropsEqual = _ref.areStatePropsEqual; 1900 1901 var hasRunAtLeastOnce = false; 1902 var state = void 0; 1903 var ownProps = void 0; 1904 var stateProps = void 0; 1905 var dispatchProps = void 0; 1906 var mergedProps = void 0; 1907 1908 function handleFirstCall(firstState, firstOwnProps) { 1909 state = firstState; 1910 ownProps = firstOwnProps; 1911 stateProps = mapStateToProps(state, ownProps); 1912 dispatchProps = mapDispatchToProps(dispatch, ownProps); 1913 mergedProps = mergeProps(stateProps, dispatchProps, ownProps); 1914 hasRunAtLeastOnce = true; 1915 return mergedProps; 1916 } 1917 1918 function handleNewPropsAndNewState() { 1919 stateProps = mapStateToProps(state, ownProps); 1920 1921 if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); 1922 1923 mergedProps = mergeProps(stateProps, dispatchProps, ownProps); 1924 return mergedProps; 1925 } 1926 1927 function handleNewProps() { 1928 if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps); 1929 1930 if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); 1931 1932 mergedProps = mergeProps(stateProps, dispatchProps, ownProps); 1933 return mergedProps; 1934 } 1935 1936 function handleNewState() { 1937 var nextStateProps = mapStateToProps(state, ownProps); 1938 var statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); 1939 stateProps = nextStateProps; 1940 1941 if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps); 1942 1943 return mergedProps; 1944 } 1945 1946 function handleSubsequentCalls(nextState, nextOwnProps) { 1947 var propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps); 1948 var stateChanged = !areStatesEqual(nextState, state); 1949 state = nextState; 1950 ownProps = nextOwnProps; 1951 1952 if (propsChanged && stateChanged) return handleNewPropsAndNewState(); 1953 if (propsChanged) return handleNewProps(); 1954 if (stateChanged) return handleNewState(); 1955 return mergedProps; 1956 } 1957 1958 return function pureFinalPropsSelector(nextState, nextOwnProps) { 1959 return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps); 1960 }; 1961 } 1962 1963 // TODO: Add more comments 1964 1965 // If pure is true, the selector returned by selectorFactory will memoize its results, 1966 // allowing connectAdvanced's shouldComponentUpdate to return false if final 1967 // props have not changed. If false, the selector will always return a new 1968 // object and shouldComponentUpdate will always return true. 1969 1970 function finalPropsSelectorFactory(dispatch, _ref2) { 1971 var initMapStateToProps = _ref2.initMapStateToProps, 1972 initMapDispatchToProps = _ref2.initMapDispatchToProps, 1973 initMergeProps = _ref2.initMergeProps, 1974 options = objectWithoutProperties(_ref2, ['initMapStateToProps', 'initMapDispatchToProps', 'initMergeProps']); 1975 1976 var mapStateToProps = initMapStateToProps(dispatch, options); 1977 var mapDispatchToProps = initMapDispatchToProps(dispatch, options); 1978 var mergeProps = initMergeProps(dispatch, options); 1979 1980 { 1981 verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName); 1982 } 1983 1984 var selectorFactory = options.pure ? pureFinalPropsSelectorFactory : impureFinalPropsSelectorFactory; 1985 1986 return selectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options); 1987 } 1988 1989 /* 1990 connect is a facade over connectAdvanced. It turns its args into a compatible 1991 selectorFactory, which has the signature: 1992 1993 (dispatch, options) => (nextState, nextOwnProps) => nextFinalProps 1994 1995 connect passes its args to connectAdvanced as options, which will in turn pass them to 1996 selectorFactory each time a Connect component instance is instantiated or hot reloaded. 1997 1998 selectorFactory returns a final props selector from its mapStateToProps, 1999 mapStateToPropsFactories, mapDispatchToProps, mapDispatchToPropsFactories, mergeProps, 2000 mergePropsFactories, and pure args. 2001 2002 The resulting final props selector is called by the Connect component instance whenever 2003 it receives new props or store state. 2004 */ 2005 2006 function match(arg, factories, name) { 2007 for (var i = factories.length - 1; i >= 0; i--) { 2008 var result = factories[i](arg); 2009 if (result) return result; 2010 } 2011 2012 return function (dispatch, options) { 2013 throw new Error('Invalid value of type ' + typeof arg + ' for ' + name + ' argument when connecting component ' + options.wrappedComponentName + '.'); 2014 }; 2015 } 2016 2017 function strictEqual(a, b) { 2018 return a === b; 2019 } 2020 2021 // createConnect with default args builds the 'official' connect behavior. Calling it with 2022 // different options opens up some testing and extensibility scenarios 2023 function createConnect() { 2024 var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, 2025 _ref$connectHOC = _ref.connectHOC, 2026 connectHOC = _ref$connectHOC === undefined ? connectAdvanced : _ref$connectHOC, 2027 _ref$mapStateToPropsF = _ref.mapStateToPropsFactories, 2028 mapStateToPropsFactories = _ref$mapStateToPropsF === undefined ? defaultMapStateToPropsFactories : _ref$mapStateToPropsF, 2029 _ref$mapDispatchToPro = _ref.mapDispatchToPropsFactories, 2030 mapDispatchToPropsFactories = _ref$mapDispatchToPro === undefined ? defaultMapDispatchToPropsFactories : _ref$mapDispatchToPro, 2031 _ref$mergePropsFactor = _ref.mergePropsFactories, 2032 mergePropsFactories = _ref$mergePropsFactor === undefined ? defaultMergePropsFactories : _ref$mergePropsFactor, 2033 _ref$selectorFactory = _ref.selectorFactory, 2034 selectorFactory = _ref$selectorFactory === undefined ? finalPropsSelectorFactory : _ref$selectorFactory; 2035 2036 return function connect(mapStateToProps, mapDispatchToProps, mergeProps) { 2037 var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, 2038 _ref2$pure = _ref2.pure, 2039 pure = _ref2$pure === undefined ? true : _ref2$pure, 2040 _ref2$areStatesEqual = _ref2.areStatesEqual, 2041 areStatesEqual = _ref2$areStatesEqual === undefined ? strictEqual : _ref2$areStatesEqual, 2042 _ref2$areOwnPropsEqua = _ref2.areOwnPropsEqual, 2043 areOwnPropsEqual = _ref2$areOwnPropsEqua === undefined ? shallowEqual : _ref2$areOwnPropsEqua, 2044 _ref2$areStatePropsEq = _ref2.areStatePropsEqual, 2045 areStatePropsEqual = _ref2$areStatePropsEq === undefined ? shallowEqual : _ref2$areStatePropsEq, 2046 _ref2$areMergedPropsE = _ref2.areMergedPropsEqual, 2047 areMergedPropsEqual = _ref2$areMergedPropsE === undefined ? shallowEqual : _ref2$areMergedPropsE, 2048 extraOptions = objectWithoutProperties(_ref2, ['pure', 'areStatesEqual', 'areOwnPropsEqual', 'areStatePropsEqual', 'areMergedPropsEqual']); 2049 2050 var initMapStateToProps = match(mapStateToProps, mapStateToPropsFactories, 'mapStateToProps'); 2051 var initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories, 'mapDispatchToProps'); 2052 var initMergeProps = match(mergeProps, mergePropsFactories, 'mergeProps'); 2053 2054 return connectHOC(selectorFactory, _extends({ 2055 // used in error messages 2056 methodName: 'connect', 2057 2058 // used to compute Connect's displayName from the wrapped component's displayName. 2059 getDisplayName: function getDisplayName(name) { 2060 return 'Connect(' + name + ')'; 2061 }, 2062 2063 // if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changes 2064 shouldHandleStateChanges: Boolean(mapStateToProps), 2065 2066 // passed through to selectorFactory 2067 initMapStateToProps: initMapStateToProps, 2068 initMapDispatchToProps: initMapDispatchToProps, 2069 initMergeProps: initMergeProps, 2070 pure: pure, 2071 areStatesEqual: areStatesEqual, 2072 areOwnPropsEqual: areOwnPropsEqual, 2073 areStatePropsEqual: areStatePropsEqual, 2074 areMergedPropsEqual: areMergedPropsEqual 2075 2076 }, extraOptions)); 2077 }; 2078 } 2079 2080 var connect = createConnect(); 2081 2082 exports.Provider = Provider; 2083 exports.createProvider = createProvider; 2084 exports.connectAdvanced = connectAdvanced; 2085 exports.connect = connect; 2086 2087 Object.defineProperty(exports, '__esModule', { value: true }); 2088 2089 })));