@txdfe/at
Version:
一个设计体系组件库
105 lines (85 loc) • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _reactDom = require("react-dom");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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 _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; }
var ServiceManager = /*#__PURE__*/function () {
function ServiceManager(queue) {
var _this = this;
var tag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'span';
_classCallCheck(this, ServiceManager);
_defineProperty(this, "handleClose", function (key) {
_this.queue["delete"](key);
});
this.queue = queue;
this.tag = tag;
}
_createClass(ServiceManager, [{
key: "close",
value: function close(key) {
this.handleClose(key);
}
}, {
key: "destroy",
value: function destroy() {
this.queue.deleteAll();
if (this.el) {
(0, _reactDom.unmountComponentAtNode)(this.el);
document.body.removeChild(this.el);
this.el = null;
}
}
}, {
key: "mountNode",
get: function get() {
if (this.el) {
return this.el;
}
var node = this.createMountNode(this.tag);
this.el = node;
return node;
}
}, {
key: "createSlice",
value: function createSlice(key, duration) {
var _this2 = this;
var timeoutKey;
var startTimeout = function startTimeout() {
if (typeof duration === 'number' && duration !== 0) {
timeoutKey = window.setTimeout(function () {
_this2.handleClose(key);
}, duration);
}
};
var clearTimeout = function clearTimeout() {
if (timeoutKey) {
window.clearTimeout(timeoutKey);
}
};
startTimeout();
return {
clearTimeout: clearTimeout,
startTimeout: startTimeout
};
}
}, {
key: "createMountNode",
value: function createMountNode(tag) {
var el = document.createElement(tag);
document.body.appendChild(el);
return el;
}
}, {
key: "flush",
value: function flush(component, callback) {
(0, _reactDom.render)(component, this.mountNode, callback);
}
}]);
return ServiceManager;
}();
exports["default"] = ServiceManager;