diff options
author | Joris | 2025-04-19 12:36:38 +0200 |
---|---|---|
committer | Joris | 2025-04-19 12:38:24 +0200 |
commit | 632eef6424d8dc8d40c2906177892697679e7b85 (patch) | |
tree | 48d9cd60e9e96eab810b5f7bb3c7b1fa79e0438f /src/state.ts | |
parent | 063d8ef9eaf874a941f4459e831057dd0a1b7ddd (diff) |
Add ZIG server
Diffstat (limited to 'src/state.ts')
-rw-r--r-- | src/state.ts | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/src/state.ts b/src/state.ts deleted file mode 100644 index 634319a..0000000 --- a/src/state.ts +++ /dev/null @@ -1,65 +0,0 @@ -import * as Serialization from 'serialization' - -const L = window.L - -// State - -var nextIndex: Index = 0 - -export type State = Marker[] -export type Index = number - -var state: State = [] - -export interface Marker { - pos: L.Pos, - name: string, - color: string, - icon: string, - radius: number, -} - -export function reset(s: State) { - state = s - nextIndex = s.length -} - -// CRUD - -export function add(marker: Marker): Index { - const index = nextIndex - state[index] = marker - nextIndex += 1 - pushState() - return index -} - -export function update(index: Index, marker: Marker) { - state[index] = marker - pushState() -} - -export function remove(index: Index) { - delete state[index] - pushState() -} - -// History - -function pushState() { - const encoded = Serialization.encode(Object.values(state)) - history.pushState('', '', `#${encoded}`) -} - -// Inspection - -export function colors() { - return [...new Set(Object.values(state).map(({ color }) => color))] -} - -export function last(): Marker | undefined { - const nonempty = Object.values(state) - return nonempty.length > 0 - ? nonempty.slice(-1)[0] - : undefined -} |