UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

37 lines (36 loc) 1.57 kB
import type { Data, DataKey } from "../util/data.js"; import type { AnyCaller } from "../util/function.js"; import type { Updates } from "../util/update.js"; import { Store } from "./Store.js"; /** Store a data object. */ export declare class DataStore<T extends Data> extends Store<T> { /** Get the data of this store. */ get data(): T; /** Set the data of this store. */ set data(data: T); /** Update several props in this data. */ update(updates: Updates<T>): void; /** Update a single named prop in this data. */ get<K extends DataKey<T>>(name: K): T[K]; /** Update a single named prop in this data. */ set<K extends DataKey<T>>(name: K, value: T[K]): void; } /** Store an optional data object. */ export declare class OptionalDataStore<T extends Data> extends Store<T | undefined> { /** Get current data value of this store (or throw `Promise` that resolves to the next required value). */ get data(): T; /** Set the data of this store. */ set data(data: T); /** Does the data exist or not? */ get exists(): boolean; /** Require the data for this data store, or throw `RequiredError` if it is not set. */ require(caller?: AnyCaller): T; /** Update several props in this data. */ update(updates: Updates<T>): void; /** Update a single named prop in this data. */ get<K extends DataKey<T>>(name: K): T[K]; /** Update a single named prop in this data. */ set<K extends DataKey<T>>(name: K, value: T[K]): void; /** Set the data to `undefined`. */ delete(): void; }