summaryrefslogtreecommitdiff
path: root/godel/js/observable.js
blob: 1299fc60a1be7669e76b25ce9d1db4dd473b8cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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));
  }
}