Fork me on GitHub
#clj-kondo
<
2023-01-28
>
lilactown19:01:20

I'm trying to write a hook for a macro that acts a lot like try / catch, but instead uses async & fallback. here's my first pass:

(defn async
  [{:keys [node]}]
  (let [body (:children node)
        fallback (last body)
        body (rest (drop-last body))]
    (if (= 'fallback (first (api/sexpr fallback)))
      (doto (with-meta
              (api/list-node
               `(try
                  ~@body
                  ~(api/list-node
                    `(catch js/Promise p#
                       ~@(rest (:children fallback))))))
              (meta node))
        prn)
      (throw (ex-info "Last expr in async must be fallback" {:node node})))))
however, using it like
(async "foo" "bar" (fallback "loading ..."))
still emits an error src/town/lilac/dom.cljs:231:8: error: Unresolved symbol: fallback

lilactown19:01:53

the prn in that hook logs

<list: (try "foo" "bar" (catch js/Promise p__844__auto__ "loading ..."))> 

borkdude20:01:23

You need to return the new node with {:node node}

lilactown20:01:11

ack!!! that fixed it. thanks facepalm

borkdude21:01:35

no problem :)