mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
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:
1 parent
7547a48fd6
commit
a05aef260f
1 file changed
+5
@@ -184,6 +184,11 @@ export abstract class Datastore<
|
|||||||
return this.data.get(key);
|
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
|
// Returns all values in the datastore
|
||||||
values() {
|
values() {
|
||||||
return this.data.values() as IterableIterator<Readonly<V>>;
|
return this.data.values() as IterableIterator<Readonly<V>>;
|
||||||
|
|||||||
Reference in new issue
Block a user