UNPKG

react-query

Version:

Hooks for managing, caching and syncing asynchronous and remote data in React

37 lines (28 loc) 792 B
export var Subscribable = /*#__PURE__*/function () { function Subscribable() { this.listeners = []; } var _proto = Subscribable.prototype; _proto.subscribe = function subscribe(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(); }; }; _proto.hasListeners = function hasListeners() { return this.listeners.length > 0; }; _proto.onSubscribe = function onSubscribe() {// Do nothing }; _proto.onUnsubscribe = function onUnsubscribe() {// Do nothing }; return Subscribable; }();