simponic.xyz/godel/js/observable.js
2023-11-16 14:56:56 -07:00

15 lines
297 B
JavaScript

class Observable {
constructor() {
this.observers = [];
}
subscribe(f) {
this.observers.push(f);
}
unsubscribe(f) {
this.observers = this.observers.filter((subscriber) => subscriber !== f);
}
notify(data) {
this.observers.forEach((observer) => observer(data));
}
}