add delete to admin panel
All checks were successful
deploy / build-and-deploy (push) Successful in 21s
All checks were successful
deploy / build-and-deploy (push) Successful in 21s
This commit is contained in:
24
src/util/state.ts
Normal file
24
src/util/state.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import type { Writable } from 'svelte/store';
|
||||
|
||||
export function addToWritableArray<T>(writable: Writable<T[]>, t: T) {
|
||||
writable.update((old) => {
|
||||
old.push(t);
|
||||
return old;
|
||||
});
|
||||
}
|
||||
|
||||
export function updateWritableArray<T>(writable: Writable<T[]>, t: T, cmp: (t: T) => boolean) {
|
||||
writable.update((old) => {
|
||||
const index = old.findIndex(cmp);
|
||||
old[index] = t;
|
||||
return old;
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteFromWritableArray<T>(writable: Writable<T[]>, cmp: (t: T) => boolean) {
|
||||
writable.update((old) => {
|
||||
const index = old.findIndex(cmp);
|
||||
old.splice(index, 1);
|
||||
return old;
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user