Skip to content

Commit

Permalink
Patch es6 iterators not having Symbol.iterator function
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah authored and tonsky committed Oct 14, 2024
1 parent c6216fb commit 71a4502
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/datascript/impl/entity.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
[a (multival->js v)]
[a v]))))

#?(:cljs
(unchecked-set (.-prototype ES6Iterator) cljs.core/ITER_SYMBOL
(fn []
(this-as this# this#))))

#?(:cljs
(unchecked-set (.-prototype ES6EntriesIterator) cljs.core/ITER_SYMBOL
(fn []
(this-as this# this#))))

(deftype Entity [db eid touched cache]
#?@(:cljs
[Object
Expand Down
17 changes: 17 additions & 0 deletions test/js/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ function test_entity_refs() {
assert_eq_refs([1], e(100).get("_children")[0].get("_children"));
}

function test_entity_iterators() {
var schema = {"aka": {":db/cardinality": ":db.cardinality/many"}};
var db = d.db_with(d.empty_db(schema),
[{":db/id": 1,
"name": "Ivan",
"aka": ["X", "Y"]},
{":db/id": 2}]);
var e = d.entity(db, 1);
var keys = [...e.keys()];
assert_eq_set(["name", "aka"], keys);
var values = [...e.values()];
assert_eq_set(["Ivan", ["X", "Y"]], values);
var entries = [...e.entries()];
assert_eq_set([["name", "Ivan"], ["aka", ["X", "Y"]]], entries);
}

function test_pull() {
var schema = {"father": {":db/valueType": ":db.type/ref"},
"children": {":db/valueType": ":db.type/ref",
Expand Down Expand Up @@ -547,6 +563,7 @@ function test_datascript_js() {
test_conn,
test_entity,
test_entity_refs,
test_entity_iterators,
test_pull,
test_lookup_refs,
test_resolve_current_tx,
Expand Down

0 comments on commit 71a4502

Please sign in to comment.