aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/utils
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-09-04 20:44:39 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-09-06 01:05:23 +0200
commit29919c02d86da10acf2b902fb9cab9998bb731a6 (patch)
treee4ac7dc9bc035327c720514363edee938248c14a /subprojects/frontend/src/utils
parentrefactor(frontend): add eslint-plugin-mobx (diff)
downloadrefinery-29919c02d86da10acf2b902fb9cab9998bb731a6.tar.gz
refinery-29919c02d86da10acf2b902fb9cab9998bb731a6.tar.zst
refinery-29919c02d86da10acf2b902fb9cab9998bb731a6.zip
feat(frontend): XState statecharts
Expressing logic in statecharts for complex stateful behaviours should improve maintainability We use @xstate/cli to statically analyze statcharts before typechecking
Diffstat (limited to 'subprojects/frontend/src/utils')
-rw-r--r--subprojects/frontend/src/utils/CancelledError.ts4
-rw-r--r--subprojects/frontend/src/utils/Timer.ts33
2 files changed, 2 insertions, 35 deletions
diff --git a/subprojects/frontend/src/utils/CancelledError.ts b/subprojects/frontend/src/utils/CancelledError.ts
index 8d3e55d8..ee23676f 100644
--- a/subprojects/frontend/src/utils/CancelledError.ts
+++ b/subprojects/frontend/src/utils/CancelledError.ts
@@ -1,5 +1,5 @@
1export default class CancelledError extends Error { 1export default class CancelledError extends Error {
2 constructor() { 2 constructor(message = 'Operation cancelled') {
3 super('Operation cancelled'); 3 super(message);
4 } 4 }
5} 5}
diff --git a/subprojects/frontend/src/utils/Timer.ts b/subprojects/frontend/src/utils/Timer.ts
deleted file mode 100644
index 4bb1bb9c..00000000
--- a/subprojects/frontend/src/utils/Timer.ts
+++ /dev/null
@@ -1,33 +0,0 @@
1export default class Timer {
2 private readonly callback: () => void;
3
4 private readonly defaultTimeout: number;
5
6 private timeout: number | undefined;
7
8 constructor(callback: () => void, defaultTimeout = 0) {
9 this.callback = () => {
10 this.timeout = undefined;
11 callback();
12 };
13 this.defaultTimeout = defaultTimeout;
14 }
15
16 schedule(timeout?: number | undefined): void {
17 if (this.timeout === undefined) {
18 this.timeout = setTimeout(this.callback, timeout ?? this.defaultTimeout);
19 }
20 }
21
22 reschedule(timeout?: number | undefined): void {
23 this.cancel();
24 this.schedule(timeout);
25 }
26
27 cancel(): void {
28 if (this.timeout !== undefined) {
29 clearTimeout(this.timeout);
30 this.timeout = undefined;
31 }
32 }
33}