DictionaryStoreclass

new DictionaryStore<T>(value: PossibleDictionary<T> = EMPTY_DICTIONARY)
ParamType
valuePossibleDictionary<T>
The initial dictionary value (defaults to an empty dictionary). Defaults to EMPTY_DICTIONARY
Return
DictionaryStore<T>
Store a dictionary object (string-keyed map of values), with helpers to read and mutate its entries.
PropertyType
.countnumber
Get the number of entries in the current value of this store. required readonly

Store a dictionary object (string-keyed map of values), with helpers to read and mutate its entries.

A Store for a string-keyed object (a dictionary). DictionaryStore<T> defaults to an empty object and adds entry-level helpers — each mutation produces a new object so consumers see a genuine change.

Usage

ts
import { DictionaryStore } from "shelving/store";

const prices = new DictionaryStore<number>({ apple: 1 });

prices.set("banana", 2);          // { apple: 1, banana: 2 }
prices.update({ apple: 3 });      // { apple: 3, banana: 2 }
prices.delete("banana");          // { apple: 3 }

console.log(prices.get("apple")); // 3
console.log(prices.count);        // 1

for (const [key, value] of prices) console.log(key, value); // iterable over entries

Examples

const store = new DictionaryStore<number>({ a: 1, b: 2 });
store.set("c", 3);
store.get("a"); // 1

Methods

Go

DictionaryStore.update()method

Update several entries in this dictionary.

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

DictionaryStore.deleteItems()method

Remove one or more named entries from this dictionary.

deleteItems(...keys: string[]): void
Go

DictionaryStore.get()method

Get a single named item from this dictionary, or undefined if it is not set.

get(name: string): T | undefined
Go

DictionaryStore.set()method

Set a single named item in this dictionary.

set(name: string, value: T): void
Go

DictionaryStore.delete()method

Delete one or more named items from this dictionary.

delete(name: string, ...names: string[]): void