about summary refs log tree commit diff
path: root/assets/src/stores
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-02-17 22:26:29 +0100
committerMel <einebeere@gmail.com>2022-02-17 22:27:55 +0100
commit50d3d4080a5b8bf0819e168aa2301e3124a55300 (patch)
tree630c5d9908fba0902e93ef3ee9e123f31cef5fc3 /assets/src/stores
parente303a189749fe2fdfcb76bd752655de8bf4c7430 (diff)
downloadrook-50d3d4080a5b8bf0819e168aa2301e3124a55300.tar.zst
rook-50d3d4080a5b8bf0819e168aa2301e3124a55300.zip
Set concrete client type during initialization.
Diffstat (limited to 'assets/src/stores')
-rw-r--r--assets/src/stores/constant_state.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/assets/src/stores/constant_state.ts b/assets/src/stores/constant_state.ts
new file mode 100644
index 0000000..aeda86e
--- /dev/null
+++ b/assets/src/stores/constant_state.ts
@@ -0,0 +1,33 @@
+// Cannot be changed after being set.
+
+import { RookType } from "../models/rook_type";
+
+let clientType: RookType = null;
+
+export function setClientType(type: RookType) {
+    if (clientType !== null) {
+        clientType = type;
+    } else {
+        throw new Error("Tried changing client type after initialization.");
+    }
+}
+
+export function isClientShare() {
+    if (clientType === null) {
+        throw new Error(
+            "Tried accessing client type before initialization was completed."
+        );
+    }
+
+    return clientType === RookType.SHARE;
+}
+
+export function isClientRequest() {
+    if (clientType === null) {
+        throw new Error(
+            "Tried accessing client type before initialization was completed."
+        );
+    }
+
+    return clientType === RookType.REQUEST;
+}