This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/src/observable/BaseObservableCollection.js

33 lines
675 B
JavaScript

export default class BaseObservableCollection {
constructor() {
this._handlers = new Set();
}
onSubscribeFirst() {
}
onUnsubscribeLast() {
}
subscribe(handler) {
this._handlers.add(handler);
if (this._handlers.size === 1) {
this.onSubscribeFirst();
}
return () => {
if (handler) {
this._handlers.delete(this._handler);
if (this._handlers.size === 0) {
this.onUnsubscribeLast();
}
handler = null;
}
return null;
};
}
// Add iterator over handlers here
}