datascript icon indicating copy to clipboard operation
datascript copied to clipboard

JS Iterator protocol for entries

Open CMCDragonkai opened this issue 7 years ago • 3 comments

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.

CMCDragonkai avatar Jan 31 '18 13:01 CMCDragonkai

thanks for reporting!

tonsky avatar Jan 31 '18 14:01 tonsky

FYI This is super easy with just adding a: (es6-iterable TheType) under the type you want to make iterable.

rauhs avatar Mar 15 '18 16:03 rauhs

great! I’ll look into it

tonsky avatar Mar 15 '18 16:03 tonsky