UNPKG

@txdfe/at

Version:

一个设计体系组件库

112 lines (95 loc) 4.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _util = require("../../../util"); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } 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; } var ServiceQueue = /*#__PURE__*/function () { function ServiceQueue() { _classCallCheck(this, ServiceQueue); this.innerQueue = []; this.innerSubscribers = []; } _createClass(ServiceQueue, [{ key: "queue", get: function get() { return this.innerQueue; }, set: function set(value) { this.innerQueue = value; this.publish(); } }, { key: "subscribers", get: function get() { return this.innerSubscribers; }, set: function set(value) { this.innerSubscribers = value; this.publish(); } }, { key: "add", value: function add(value) { this.queue = [].concat(_toConsumableArray(this.queue), [value]); return value; } }, { key: "delete", value: function _delete(key) { this.queue = this.queue.filter(function (stack) { return stack.key !== key; }); } }, { key: "deleteAll", value: function deleteAll() { this.queue = []; } }, { key: "subscribe", value: function subscribe(next) { var key = (0, _util.guid)(); var nextSubscriber = { key: key, next: next }; this.subscribers = [].concat(_toConsumableArray(this.subscribers), [nextSubscriber]); return key; } }, { key: "unsubscribe", value: function unsubscribe(key) { this.subscribers = this.subscribers.filter(function (subscriber) { return subscriber.key !== key; }); } }, { key: "unsubscribeAll", value: function unsubscribeAll() { this.subscribers = []; } }, { key: "publish", value: function publish() { var _this = this; if (this.subscribers.length !== 0) { this.subscribers.forEach(function (subscriber) { var next = subscriber.next; next(_this.queue); }); } } }]); return ServiceQueue; }(); exports["default"] = ServiceQueue;