svelte/store
import {
function derived<S extends Stores, T>(stores: S, fn: (values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void, initial_value?: T | undefined): Readable<T> (+1 overload)
Derived value store by synchronizing one or more readable stores and
applying an aggregation function over its input values.
derived,
function fromStore<V>(store: Writable<V>): {
current: V;
} (+1 overload)
fromStore,
function get<T>(store: Readable<T>): T
Get the current value from a store by subscribing and immediately unsubscribing.
get,
function readable<T>(value?: T | undefined, start?: StartStopNotifier<T> | undefined): Readable<T>
Creates a Readable
store that allows reading by subscription.
readable,
function readonly<T>(store: Readable<T>): Readable<T>
Takes a store and returns a new one derived from the old one that is readable.
readonly,
function toStore<V>(get: () => V, set: (v: V) => void): Writable<V> (+1 overload)
toStore,
function writable<T>(value?: T | undefined, start?: StartStopNotifier<T> | undefined): Writable<T>
Create a Writable
store that allows both updating and reading by subscription.
writable
} from 'svelte/store';
derived
1つ以上のreadableストアを同期し、その入力値に集約関数を適用することで派生値ストアを作成します。
function derived<S extends Stores, T>(
stores: S,
fn: (
values: StoresValues<S>,
set: (value: T) => void,
update: (fn: Updater<T>) => void
) => Unsubscriber | void,
initial_value?: T | undefined
): Readable<T>;
function derived<S extends Stores, T>(
stores: S,
fn: (values: StoresValues<S>) => T,
initial_value?: T | undefined
): Readable<T>;
fromStore
function fromStore<V>(store: Writable<V>): {
current: V;
};
function fromStore<V>(store: Readable<V>): {
readonly current: V;
};
get
ストアを購読し、すぐに購読解除することで現在の値を取得します。
function get<T>(store: Readable<T>): T;
readable
購読による読み取りを許可するReadable
ストアを作成します。
function readable<T>(
value?: T | undefined,
start?: StartStopNotifier<T> | undefined
): Readable<T>;
readonly
ストアを受け取り、読み取り可能な古いストアから派生した新しいストアを返します。
function readonly<T>(store: Readable<T>): Readable<T>;
toStore
function toStore<V>(
get: () => V,
set: (v: V) => void
): Writable<V>;
function toStore<V>(get: () => V): Readable<V>;
writable
購読による更新と読み取りの両方を許可するWritable
ストアを作成します。
function writable<T>(
value?: T | undefined,
start?: StartStopNotifier<T> | undefined
): Writable<T>;
Readable
購読のためのReadableインターフェース。
interface Readable<T> {…}
subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber;
run
購読コールバックinvalidate
クリーンアップコールバック
値の変更を購読します。
StartStopNotifier
通知コールバックの開始と停止。 この関数は、最初の購読者が購読したときに呼び出されます。
type StartStopNotifier<T> = (
set: (value: T) => void,
update: (fn: Updater<T>) => void
) => void | (() => void);
Subscriber
値の更新を通知するためのコールバック。
type Subscriber<T> = (value: T) => void;
Unsubscriber
値の更新の購読を解除します。
type Unsubscriber = () => void;
Updater
値を更新するためのコールバック。
type Updater<T> = (value: T) => T;
Writable
更新と購読の両方のためのWritableインターフェース。
interface Writable<T> extends Readable<T> {…}
set(this: void, value: T): void;
- 設定する
value
値を設定し、購読者に通知します。
update(this: void, updater: Updater<T>): void;
updater
コールバック
コールバックを使用して値を更新し、購読者に通知します。