diff --git a/src/lib/stores/gameSearchStore.ts b/src/lib/stores/gameSearchStore.ts new file mode 100644 index 0000000..55a337e --- /dev/null +++ b/src/lib/stores/gameSearchStore.ts @@ -0,0 +1,32 @@ +import { writable } from 'svelte/store'; +import type { GameType } from '$lib/types'; + +// Custom store +const newGameStore = () => { + const { subscribe, update } = writable([]); + + function add(game: GameType) { + update((store) => [...store, game]); + } + + function addAll(games: GameType[]) { + update((store) => [...store, ...games]); + } + + function remove(id: string) { + update((store) => { + const newStore = store.filter((item: GameType) => item.id !== id); + return [...newStore]; + }); + } + + function removeAll() { + update(() => { + return []; + }); + } + + return { subscribe, add, addAll, remove, removeAll }; +}; + +export const gameStore = newGameStore();