aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/lib/Reaction.js
blob: 46aa4dae6c474137d7b2c55c46d0868307d26822 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// @flow
import { autorun } from 'mobx';

export default class Reaction {
  reaction;

  hasBeenStarted;

  dispose;

  constructor(reaction) {
    this.reaction = reaction;
    this.hasBeenStarted = false;
  }

  start() {
    this.dispose = autorun(() => this.reaction());
    this.hasBeenStarted = true;
  }

  stop() {
    if (this.hasBeenStarted) this.dispose();
  }
}