์ค์์ ์ ์ฅ์๋ฅผ ๋๊ณ ๋ถ๋ชจ-์์ ๊ด๊ณ or ์ฐ๊ด๊ด๊ณ๋ฅผ ๊ฐ์ง์ง ์์ ์ปดํฌ๋ํธ์์ ์ํ์ ์ ๊ทผ & ๊ณต์
import {writable} from 'svelte/store';
const storeObject = writable(value: any);
//
Object
set: ฦ (new_value)
subscribe: ฦ subscribe(run, invalidate = noop)
update: ฦ update(fn)
[[Prototype]]: Object
//
import {writable} from 'svelte/store';
const count = writable(0); // 0
count.set(1); // 1
$count = 2; // 2
store = { subscribe: (subscription: (value: any) => void) => (() => void), set?: value: any) => void }
์ธ๋ถ์์ ๋ณ๊ฒฝํ ์ ์๋ ์ํ๊ฐ์ฒด
store = readable(value: any, (set: (value: any) => void) => () => void)
import {readable} from 'svelte/store';
const name = readable('yeon');
const age = readable(26, (set) => {
//
});
ํ์ ์คํ ์ด๋ ์ํ๊ฐ์ฒด ๋ฐํ
store = derived(a, callback: (a: any) => any)
import {writable, derived} from 'svelte/store';
const count = writable(100); // 100
const doubleCount = derived(count, $count => $count*2); // 200
์ํ๊ฐ์ฒด์์ ์ํ๊ฐ์ ๊ฐ์ ธ์ด
import {writable, get} from 'svelte/store';
const count = writable(10);
const getCount = get(count); // 10
// count๊ฐ์ ๋ฐ๊ฟ๋ getCount๊ฐ์๋ ์ด์ ๊ฐ