aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/lib/Reaction.js
blob: e9bc26d81cd0fa85e76a0212ee31372e90f8c3e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// @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();
  }
}