diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-22 21:58:13 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-22 21:58:13 +0200 |
commit | fa4c684475a365055c2aacdf712c7903c9a5f2f2 (patch) | |
tree | e42460b2c920dcf31e758757d34dbaba0c8d9051 /web/pw-server/src/lib/stores/editor_state.ts | |
parent | 82ab9cef78020361d556f4208c57ecd9259d51ea (diff) | |
download | planetwars.dev-fa4c684475a365055c2aacdf712c7903c9a5f2f2.tar.xz planetwars.dev-fa4c684475a365055c2aacdf712c7903c9a5f2f2.zip |
create editor store
Diffstat (limited to 'web/pw-server/src/lib/stores/editor_state.ts')
-rw-r--r-- | web/pw-server/src/lib/stores/editor_state.ts | 26 |
1 files changed, 26 insertions, 0 deletions
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); |