OptionalDataStoreclass

new OptionalDataStore<T>()
Return
OptionalDataStore<T>
Store a data object that may be undefined (e.g. a document that may not exist).
PropertyType
.dataT
Get the current data of this store, or throw if it is not set.
- Supports suspense-like reads: throws a Promise while loading or the error reason on failure (inherited from Store.value). required
.existsboolean
Whether the data currently exists (is not undefined). required readonly

Store a data object that may be undefined (e.g. a document that may not exist).

  • Reading data or calling require() throws RequiredError when the value is undefined.
  • delete() sets the value back to undefined.

Examples

const store = new OptionalDataStore<{ name: string }>(undefined);
store.exists; // false
store.data = { name: "Dave" };
store.delete(); // back to undefined

Methods

Go

OptionalDataStore.require()method

Require the data of this store, or throw RequiredError if it is not set.

require(caller: AnyCaller = this.require): T
Go

OptionalDataStore.update()method

Update several props in this data.

update(updates: Updates<T>): void
Go

OptionalDataStore.get()method

Get a single named prop from this data.

get(name: K): T[K]
Go

OptionalDataStore.set()method

Set a single named prop in this data.

set(name: K, value: T[K]): void
Go

OptionalDataStore.delete()method

Set the data to undefined.

delete(): void