vue-use-query
Version:
vue use query
31 lines (30 loc) • 949 B
JavaScript
/**
* 事件的订阅处理中心
*/
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;
}());
export { Subscribable };