diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/stores/lib/Reaction.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
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 | } | ||