Why aren't NodeList / HtmlCollection seqable?
Asked Answered
B

3

19

As a newcomer to Clojurescript it appears to me that every Clojurescript project will have some snippet of code like this:

(extend-type js/NodeList
  ISeqable
  (-seq [array] (array-seq array 0)))

Why isn't this part of the core library?

Barby answered 12/5, 2014 at 18:16 Comment(2)
As @Joaquin comments, this is a platform specific adapter issue. Are you familiar with extend-type meanings clojuredocs.org/clojure_core/clojure.core/extend-type ?Vaporous
@expez: I share your surprise that NodeList and HTMLCollection are not automatically usable by standard Clojurescript iterators. Everyone learning Clojurescript should not have to stumble over this, hunt for the answer, and them re-implement boiler plate solution code.Josiah
F
13

You have to think that clojurescript is a compiler to javascript as a language, not only browser JavaScript. You can also use it in other platforms like nodejs or with the QT library where NodeList does not exist (because it is part of the Dom api and not the standard language).

Forman answered 13/5, 2014 at 6:52 Comment(0)
B
3

If you are looking for a way to create a sequence from a NodeList there is array-seq function.

(array-seq (js/document.querySelectorAll "div"))
Bother answered 20/8, 2019 at 11:46 Comment(0)
G
3

With a patch for https://clojure.atlassian.net/browse/CLJS-3199 applied in ClojureScript 1.10.741 (seq (js/document.querySelectorAll "div")) now actually works out of the box.

Golden answered 19/7, 2021 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.