disposable.js 289 Bytes
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
export default class Disposable {
  constructor() {
    this.disposers = new Set();
  }

  add(...disposers) {
    disposers.forEach(disposer => this.disposers.add(disposer));
  }

  dispose() {
    this.disposers.forEach(disposer => disposer.dispose());
    this.disposers.clear();
  }
}