clojurescript 2024-12-25

How do you deal with AsyncIterable? Three years ago, the https://ask.clojure.org/index.php/10896/how-to-work-with-asynciterable-interface-in-cljs came up, resulting in a https://clojure.atlassian.net/browse/ASYNC-239 which doesn't seem to have moved since then. Any new insights, maybe? For context: The values() method of the FileSystemDirectoryHandle interface returns a new asynchronous iterator for the iteration of the value of the entries within the FileSystemDirectoryHandle on which this method is called.

As I mentioned - it loses ^js and any other type hints. Not sure about other metadata. IIRC, depending on how you use it, it might also end up generating a lot of code that, if rewritten with plain promises, could be a fraction of that.

I'd just use the macros from that answer.

👍 1

Fair enough.

Oh, more likely - I'd write that bit in JS and use it from CLJS. Similar to how you might do some things in Java and then use them in CLJ.

Just curious: you avoid core.async at all cost?

In CLJS - yes. Well, "at all costs" sounds rough but it actually isn't a big deal because there's not that much incentive in the first place.

the incentive is elegant code, which is subjective, granted.

(defn iter->seq [iter] (go-loop [acc []] (let [el ( (if (.-done el) acc (recur (conj acc (.-value el))))))) (defn list-opfs [dir] (go (let [root-storage ( sub-dir ( values (.values sub-dir)] (async/take! (iter->seq values) #(doseq [v %] (.dir js/console v))))))

Indeed. For me, "elegance" and "adding a problematic impossible-to-debug dependency" are at odds with each other.

How do I create custom js/Error class in clojurescript?

class MyError extends Error {
  constructor(message, options) {
    // Need to pass `options` as the second parameter to install the "cause" property.
    super(message, options);
  }
}

If you use shadow-cljs, there's [shadow.cljs.modern :refer [defclass]]. If not, then you can create classes in JS without using class or extends: https://playfulprogramming.com/posts/js-classes-without-keyword#Extend-a-functional-class-using-Objectcreate

❤️ 1