1234567891011121314151617181920212223242526272829303132 |
- class Subscribable {
- constructor() {
- this.listeners = new Set();
- this.subscribe = this.subscribe.bind(this);
- }
- subscribe(listener) {
- const identity = {
- listener
- };
- this.listeners.add(identity);
- this.onSubscribe();
- return () => {
- this.listeners.delete(identity);
- this.onUnsubscribe();
- };
- }
- hasListeners() {
- return this.listeners.size > 0;
- }
- onSubscribe() {// Do nothing
- }
- onUnsubscribe() {// Do nothing
- }
- }
- export { Subscribable };
- //# sourceMappingURL=subscribable.mjs.map
|