DictionaryStore.update()method
Update several entries in this dictionary.
update(updates: Updates<ImmutableDictionary<T>>): void
new DictionaryStore<T>(value: PossibleDictionary<T> = EMPTY_DICTIONARY)
| Param | Type | |
|---|---|---|
value | PossibleDictionary<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. |
| Property | Type | |
|---|---|---|
.count | number | 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.
PossibleDictionary<T> as input and normalises it to an ImmutableDictionary<T>.[key, value] entry tuples.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.
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 entriesconst store = new DictionaryStore<number>({ a: 1, b: 2 });
store.set("c", 3);
store.get("a"); // 1Update several entries in this dictionary.
update(updates: Updates<ImmutableDictionary<T>>): void
Remove one or more named entries from this dictionary.
deleteItems(...keys: string[]): void
Get a single named item from this dictionary, or undefined if it is not set.
get(name: string): T | undefined
Set a single named item in this dictionary.
set(name: string, value: T): void
Delete one or more named items from this dictionary.
delete(name: string, ...names: string[]): void