Allow iterating through datastores like a Map

Support the for (const [k, v] of datastore) syntax which is commonly
used with maps by adding a Symbol.iterator function returning the
appropriate iterator.
This commit is contained in:
Hornwitser committed 2024-09-04 13:43:56 +02:00
1 parent 7547a48fd6
commit a05aef260f
1 file changed
+5
+5
View File
@@ -184,6 +184,11 @@ export abstract class Datastore<
return this.data.get(key);
}
// Allow iterating through the datastore like a Map.
[Symbol.iterator](): IterableIterator<[K, Readonly<V>]> {
return this.data.entries();
}
// Returns all values in the datastore
values() {
return this.data.values() as IterableIterator<Readonly<V>>;