|
|
@ -28,6 +28,11 @@ export interface Readable<T> {
|
|
|
|
|
|
|
|
|
|
|
|
/** Writable interface for both updating and subscribing. */
|
|
|
|
/** Writable interface for both updating and subscribing. */
|
|
|
|
export interface Writable<T> extends Readable<T> {
|
|
|
|
export interface Writable<T> extends Readable<T> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get value.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
get(): T;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set value and inform subscribers.
|
|
|
|
* Set value and inform subscribers.
|
|
|
|
* @param value to set
|
|
|
|
* @param value to set
|
|
|
@ -64,6 +69,10 @@ export function writable<T>(value: T, start: StartStopNotifier<T> = noop): Writa
|
|
|
|
let stop: Unsubscriber;
|
|
|
|
let stop: Unsubscriber;
|
|
|
|
const subscribers: Array<SubscribeInvalidateTuple<T>> = [];
|
|
|
|
const subscribers: Array<SubscribeInvalidateTuple<T>> = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get(): T {
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function set(new_value: T): void {
|
|
|
|
function set(new_value: T): void {
|
|
|
|
if (safe_not_equal(value, new_value)) {
|
|
|
|
if (safe_not_equal(value, new_value)) {
|
|
|
|
value = new_value;
|
|
|
|
value = new_value;
|
|
|
@ -99,7 +108,7 @@ export function writable<T>(value: T, start: StartStopNotifier<T> = noop): Writa
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { set, update, subscribe };
|
|
|
|
return { get, set, update, subscribe };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** One or more `Readable`s. */
|
|
|
|
/** One or more `Readable`s. */
|
|
|
|