diff options
Diffstat (limited to 'src/stores/lib/Reaction.js')
-rw-r--r-- | src/stores/lib/Reaction.js | 22 |
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 | ||
2 | import { autorun } from 'mobx'; | ||
3 | |||
4 | export 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 | } | ||