@lvxiaowu/antd4
Version:
antd4-components
125 lines (98 loc) • 4.2 kB
JavaScript
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
import { observable, action, makeObservable, runInAction } from 'mobx';
import { overrideStore, DRAWER_STORE, resetStore } from '../utils';
import { DataType } from '@lvxiaowu/utils';
var DrawerStore = /*#__PURE__*/_createClass(function DrawerStore(overrides) {
var _this = this;
_classCallCheck(this, DrawerStore);
this.$storeName = DRAWER_STORE;
this.visible = false;
this.openValues = void 0;
this.onOpen = function () {
return _this.openValues;
};
this.open = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
var _data;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!_this.onOpen) {
_context.next = 7;
break;
}
_data = DataType.isEvent(data) ? undefined : data;
_this.openValues = _data;
if (!_this.onOpen) {
_context.next = 7;
break;
}
_context.next = 6;
return _this.onOpen(_data);
case 6:
_this.openValues = _context.sent;
case 7:
runInAction(function () {
_this.visible = true;
});
case 8:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
this.close = function () {
_this.visible = false;
};
this.loading = false;
this.handleOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
var back;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
back = _this.onOk(_this.openValues);
if (DataType.isPromise(back)) {
_this.loading = true;
back.finally(function () {
runInAction(function () {
_this.loading = false;
});
});
}
case 2:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
this.onOk = function () {
_this.close();
return null;
};
this.resetStore = function () {
resetStore(_this, DrawerStore);
};
overrideStore(this, overrides);
makeObservable(this, {
visible: observable,
loading: observable,
open: action,
onOpen: action,
close: action,
handleOk: action,
onOk: action
});
});
export { DrawerStore as default };