aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/lib/Reaction.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/lib/Reaction.js')
-rw-r--r--src/stores/lib/Reaction.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/stores/lib/Reaction.js b/src/stores/lib/Reaction.js
new file mode 100644
index 000000000..e9bc26d81
--- /dev/null
+++ b/src/stores/lib/Reaction.js
@@ -0,0 +1,22 @@
1// @flow
2import { autorun } from 'mobx';
3
4export default class Reaction {
5 reaction;
6 hasBeenStarted;
7 dispose;
8
9 constructor(reaction) {
10 this.reaction = reaction;
11 this.hasBeenStarted = false;
12 }
13
14 start() {
15 this.dispose = autorun(() => this.reaction());
16 this.hasBeenStarted = true;
17 }
18
19 stop() {
20 if (this.hasBeenStarted) this.dispose();
21 }
22}