aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/lib/Reaction.ts
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-10-14 09:32:20 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-14 13:02:20 +0530
commit52211095aab71f8b59b093b19ae34c222be9f390 (patch)
tree28f24a9be5ee5577667cdd396fb3fc64fc861e65 /src/stores/lib/Reaction.ts
parentchore: convert class components to functional (#2065) (diff)
downloadferdium-app-52211095aab71f8b59b093b19ae34c222be9f390.tar.gz
ferdium-app-52211095aab71f8b59b093b19ae34c222be9f390.tar.zst
ferdium-app-52211095aab71f8b59b093b19ae34c222be9f390.zip
chore: convert various JS to TS (#2062)
Diffstat (limited to 'src/stores/lib/Reaction.ts')
-rw-r--r--src/stores/lib/Reaction.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/stores/lib/Reaction.ts b/src/stores/lib/Reaction.ts
new file mode 100644
index 000000000..0ca24a6fa
--- /dev/null
+++ b/src/stores/lib/Reaction.ts
@@ -0,0 +1,29 @@
1import { autorun } from 'mobx';
2
3export default class Reaction {
4 reaction;
5
6 isRunning = false;
7
8 dispose;
9
10 constructor(reaction) {
11 this.reaction = reaction;
12 }
13
14 start() {
15 if (!this.isRunning) {
16 this.dispose = autorun(this.reaction);
17 this.isRunning = true;
18 }
19 }
20
21 stop() {
22 if (this.isRunning) {
23 this.dispose?.();
24 this.isRunning = false;
25 }
26 }
27}
28
29export const createReactions = reactions => reactions.map(r => new Reaction(r));