diff options
author | 2019-04-13 20:58:37 +0200 | |
---|---|---|
committer | 2019-04-13 20:58:37 +0200 | |
commit | 8e623e84cf21068561217a509c0761d524dfbc29 (patch) | |
tree | a83f307c3ce087169e3a1d55418fa78a71b7b4dc /src/stores/lib | |
parent | Use store reactions (diff) | |
parent | Merge branch 'feature/announcements' into develop (diff) | |
download | ferdium-app-8e623e84cf21068561217a509c0761d524dfbc29.tar.gz ferdium-app-8e623e84cf21068561217a509c0761d524dfbc29.tar.zst ferdium-app-8e623e84cf21068561217a509c0761d524dfbc29.zip |
Merge branch 'develop' into chore/streamline-dashboard
Diffstat (limited to 'src/stores/lib')
-rw-r--r-- | src/stores/lib/Reaction.js | 19 |
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 | ||
2 | import { autorun } from 'mobx'; | 1 | import { autorun } from 'mobx'; |
3 | 2 | ||
4 | export default class Reaction { | 3 | export 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 | |||
29 | export const createReactions = reactions => ( | ||
30 | reactions.map(r => new Reaction(r)) | ||
31 | ); | ||