Stores
Writable Store
- js
- ts
src/lib/stores/count.js
import { writable } from 'svelte/store';
export const count = writable(0);
export { count as default };
src/lib/stores/count.ts
import { writable } from 'svelte/store';
export const count = writable<number>(0);
export { count as default };
Derived Store
- js
- ts
src/lib/stores/doubled.js
import { derived } from 'svelte/store';
import count from '$lib/stores/count';
const doubled = derived(count, $count => $count * 2);
export { doubled as default };
src/lib/stores/doubled.ts
import { derived } from 'svelte/store';
import count from '$lib/stores/count';
const doubled = derived(count, $count => $count * 2);
export { doubled as default };
- js
- ts
src/lib/stores/sum.js
import { derived } from 'svelte/store';
import count from '$lib/stores/count';
import count2 from '$lib/stores/count2';
const sum = derived([count, count2], ([$count, $count2]) => $count + $count2);
export { sum as default };
src/lib/stores/sum.ts
import { derived } from 'svelte/store';
import count from '$lib/stores/count';
import count2 from '$lib/stores/count2';
const sum = derived([count, count2], ([$count, $count2]) => $count + $count2);
export { sum as default };