From fa4c684475a365055c2aacdf712c7903c9a5f2f2 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Mon, 22 Aug 2022 21:58:13 +0200 Subject: create editor store --- web/pw-server/src/lib/stores/editor_state.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 web/pw-server/src/lib/stores/editor_state.ts (limited to 'web/pw-server/src/lib/stores/editor_state.ts') diff --git a/web/pw-server/src/lib/stores/editor_state.ts b/web/pw-server/src/lib/stores/editor_state.ts new file mode 100644 index 0000000..641994b --- /dev/null +++ b/web/pw-server/src/lib/stores/editor_state.ts @@ -0,0 +1,26 @@ +import { writable } from "svelte/store"; + +const MAX_MATCHES = 100; + +function createMatchHistory() { + const { subscribe, update } = writable([]); + + function pushMatch(match: object) { + update((matches) => { + if (matches.length == MAX_MATCHES) { + matches.pop(); + } + matches.unshift(match); + + return matches; + }); + } + + return { + subscribe, + pushMatch, + }; +} + +export const matchHistory = createMatchHistory(); +export const selectedOpponent = writable(null); -- cgit v1.2.3