vue-use-query
Version:
vue use query
34 lines (33 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Subscribable = void 0;
/**
* 事件的订阅处理中心
*/
var Subscribable = /** @class */ (function () {
function Subscribable() {
this.listeners = [];
}
Subscribable.prototype.subscribe = function (listener) {
var _this = this;
var callback = listener || (function () { return undefined; });
this.listeners.push(callback);
this.onSubscribe();
return function () {
_this.listeners = _this.listeners.filter(function (x) { return x !== callback; });
_this.onUnsubscribe();
};
};
Subscribable.prototype.hasListeners = function () {
return this.listeners.length > 0;
};
//#region 生命周期函数
Subscribable.prototype.onSubscribe = function () {
// Do nothing
};
Subscribable.prototype.onUnsubscribe = function () {
// Do nothing
};
return Subscribable;
}());
exports.Subscribable = Subscribable;