From 50d3d4080a5b8bf0819e168aa2301e3124a55300 Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 17 Feb 2022 22:26:29 +0100 Subject: Set concrete client type during initialization. --- assets/src/stores/constant_state.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 assets/src/stores/constant_state.ts (limited to 'assets/src/stores') 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; +} -- cgit 1.4.1