Adding custom game store.

This commit is contained in:
Bradley Shellnut 2022-07-12 16:49:24 -07:00
parent d54b9a1877
commit 7491c001da

View file

@ -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();