From a05aef260fb67c12595952e1ee84016f02b14762 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 4 Sep 2024 13:43:56 +0200 Subject: [PATCH] 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. --- packages/lib/src/datastore.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/lib/src/datastore.ts b/packages/lib/src/datastore.ts index 42bc4303..20c38683 100644 --- a/packages/lib/src/datastore.ts +++ b/packages/lib/src/datastore.ts @@ -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]> { + return this.data.entries(); + } + // Returns all values in the datastore values() { return this.data.values() as IterableIterator>;