datascript
datascript copied to clipboard
JS Iterator protocol for entries
The README indicates that entity implements the ES6 Map interface. However it's not actually iterable because it doesn't implement the iterable protocol. To do so, an entity must also have the method Symbol.iterator as a computed method.
For example, using the node repl, you can test this:
e = d.entity(db, 1);
[...e.keys()] // TypeError: e.keys(...) is not iterable
[...e.values()] // TypeError: e.values(...) is not iterable
[...e] // TypeError: e is not iterable
Basically this function is missing:
e[Symbol.iterator]
And for each of the objects returned by keys, or values or entries.
thanks for reporting!
FYI This is super easy with just adding a: (es6-iterable TheType) under the type you want to make iterable.
great! I’ll look into it