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.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/stores/lib/Reaction.js b/src/stores/lib/Reaction.js
index 46aa4dae6..f2642908f 100644
--- a/src/stores/lib/Reaction.js
+++ b/src/stores/lib/Reaction.js
@@ -1,24 +1,31 @@
1// @flow
2import { autorun } from 'mobx'; 1import { autorun } from 'mobx';
3 2
4export default class Reaction { 3export default class Reaction {
5 reaction; 4 reaction;
6 5
7 hasBeenStarted; 6 isRunning = false;
8 7
9 dispose; 8 dispose;
10 9
11 constructor(reaction) { 10 constructor(reaction) {
12 this.reaction = reaction; 11 this.reaction = reaction;
13 this.hasBeenStarted = false;
14 } 12 }
15 13
16 start() { 14 start() {
17 this.dispose = autorun(() => this.reaction()); 15 if (!this.isRunning) {
18 this.hasBeenStarted = true; 16 this.dispose = autorun(() => this.reaction());
17 this.isActive = true;
18 }
19 } 19 }
20 20
21 stop() { 21 stop() {
22 if (this.hasBeenStarted) this.dispose(); 22 if (this.isRunning) {
23 this.dispose();
24 this.isActive = false;
25 }
23 } 26 }
24} 27}
28
29export const createReactions = reactions => (
30 reactions.map(r => new Reaction(r))
31);