mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Adding custom game store.
This commit is contained in:
parent
d54b9a1877
commit
7491c001da
1 changed files with 32 additions and 0 deletions
32
src/lib/stores/gameSearchStore.ts
Normal file
32
src/lib/stores/gameSearchStore.ts
Normal 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();
|
||||
Loading…
Reference in a new issue