simponic.xyz/turing-machine/js/observable.js

15 lines
297 B
JavaScript
Raw Normal View History

2023-10-25 00:28:40 -04:00
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));
}
}