Skip to content

Commit 71a4502

Browse files
kasbahtonsky
authored andcommitted
Patch es6 iterators not having Symbol.iterator function
1 parent c6216fb commit 71a4502

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/datascript/impl/entity.cljc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@
4545
[a (multival->js v)]
4646
[a v]))))
4747

48+
#?(:cljs
49+
(unchecked-set (.-prototype ES6Iterator) cljs.core/ITER_SYMBOL
50+
(fn []
51+
(this-as this# this#))))
52+
53+
#?(:cljs
54+
(unchecked-set (.-prototype ES6EntriesIterator) cljs.core/ITER_SYMBOL
55+
(fn []
56+
(this-as this# this#))))
57+
4858
(deftype Entity [db eid touched cache]
4959
#?@(:cljs
5060
[Object

test/js/tests.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,22 @@ function test_entity_refs() {
304304
assert_eq_refs([1], e(100).get("_children")[0].get("_children"));
305305
}
306306

307+
function test_entity_iterators() {
308+
var schema = {"aka": {":db/cardinality": ":db.cardinality/many"}};
309+
var db = d.db_with(d.empty_db(schema),
310+
[{":db/id": 1,
311+
"name": "Ivan",
312+
"aka": ["X", "Y"]},
313+
{":db/id": 2}]);
314+
var e = d.entity(db, 1);
315+
var keys = [...e.keys()];
316+
assert_eq_set(["name", "aka"], keys);
317+
var values = [...e.values()];
318+
assert_eq_set(["Ivan", ["X", "Y"]], values);
319+
var entries = [...e.entries()];
320+
assert_eq_set([["name", "Ivan"], ["aka", ["X", "Y"]]], entries);
321+
}
322+
307323
function test_pull() {
308324
var schema = {"father": {":db/valueType": ":db.type/ref"},
309325
"children": {":db/valueType": ":db.type/ref",
@@ -547,6 +563,7 @@ function test_datascript_js() {
547563
test_conn,
548564
test_entity,
549565
test_entity_refs,
566+
test_entity_iterators,
550567
test_pull,
551568
test_lookup_refs,
552569
test_resolve_current_tx,

0 commit comments

Comments
 (0)