Add Nowstore

This commit is contained in:
2024-08-19 11:19:07 +02:00
parent 69eee93cff
commit 5b00b68a88
2 changed files with 47 additions and 8 deletions

View File

@@ -0,0 +1,24 @@
import { type Writable, writable } from "svelte/store";
async function createStore(): Promise<Writable<Date> & { next: Function; prev: Function }> {
const { subscribe, update, set } = writable(new Date());
return {
subscribe,
update,
set,
next: () => {
update((now: Date) => {
now.setMonth(now.getMonth() + 1);
return now
});
},
prev: () => {
update((now: Date) => {
now.setMonth(now.getMonth() - 1);
return now
});
},
};
}
export const nowStore = await createStore();