UNPKG

react-query

Version:

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

44 lines (32 loc) 897 B
"use strict"; exports.__esModule = true; exports.Subscribable = void 0; 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; }(); exports.Subscribable = Subscribable;