react.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.PersistGate = void 0;
  4. var _react = _interopRequireWildcard(require("react"));
  5. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  6. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  12. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  15. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  16. var PersistGate =
  17. /*#__PURE__*/
  18. function (_PureComponent) {
  19. _inherits(PersistGate, _PureComponent);
  20. function PersistGate() {
  21. var _getPrototypeOf2;
  22. var _this;
  23. _classCallCheck(this, PersistGate);
  24. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  25. args[_key] = arguments[_key];
  26. }
  27. _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(PersistGate)).call.apply(_getPrototypeOf2, [this].concat(args)));
  28. _defineProperty(_assertThisInitialized(_this), "state", {
  29. bootstrapped: false
  30. });
  31. _defineProperty(_assertThisInitialized(_this), "_unsubscribe", void 0);
  32. _defineProperty(_assertThisInitialized(_this), "handlePersistorState", function () {
  33. var persistor = _this.props.persistor;
  34. var _persistor$getState = persistor.getState(),
  35. bootstrapped = _persistor$getState.bootstrapped;
  36. if (bootstrapped) {
  37. if (_this.props.onBeforeLift) {
  38. Promise.resolve(_this.props.onBeforeLift()).finally(function () {
  39. return _this.setState({
  40. bootstrapped: true
  41. });
  42. });
  43. } else {
  44. _this.setState({
  45. bootstrapped: true
  46. });
  47. }
  48. _this._unsubscribe && _this._unsubscribe();
  49. }
  50. });
  51. return _this;
  52. }
  53. _createClass(PersistGate, [{
  54. key: "componentDidMount",
  55. value: function componentDidMount() {
  56. this._unsubscribe = this.props.persistor.subscribe(this.handlePersistorState);
  57. this.handlePersistorState();
  58. }
  59. }, {
  60. key: "componentWillUnmount",
  61. value: function componentWillUnmount() {
  62. this._unsubscribe && this._unsubscribe();
  63. }
  64. }, {
  65. key: "render",
  66. value: function render() {
  67. if (process.env.NODE_ENV !== 'production') {
  68. if (typeof this.props.children === 'function' && this.props.loading) console.error('redux-persist: PersistGate expects either a function child or loading prop, but not both. The loading prop will be ignored.');
  69. }
  70. if (typeof this.props.children === 'function') {
  71. return this.props.children(this.state.bootstrapped);
  72. }
  73. return this.state.bootstrapped ? this.props.children : this.props.loading;
  74. }
  75. }]);
  76. return PersistGate;
  77. }(_react.PureComponent);
  78. exports.PersistGate = PersistGate;
  79. _defineProperty(PersistGate, "defaultProps", {
  80. children: null,
  81. loading: null
  82. });