I don't have an answer to this question. I was facing the same problem and did a bit of digging and thought I can share it here to help whoever is looking at this. I found that this issue is associated with creating cljs.core/PersistentVector
. Here are my examples:
(require '[cljs.core.async :refer [go <! chan put!]])
(def c (chan))
(put! c {:hi "here"})
;; This fails
(go
(let [{:keys [new] :as msg} (<! c)]
(js/console.log [:msg-received msg])))
;; ioc_helpers.cljs:50 Uncaught TypeError: inst_25288.call is not a function
;; at switch__20329__auto__ (eval at figwheel$repl$eval_javascript_STAR__STAR_ (repl.cljc:364), <anonymous>:86:29)
;; at eval (eval at figwheel$repl$eval_javascript_STAR__STAR_ (repl.cljc:364), <anonymous>:166:51)
;; at mini_reframe$app$state_machine__20330__auto____1 (eval at figwheel$repl$eval_javascript_STAR__STAR_ (repl.cljc:364), <anonymous>:188:4)
;; at mini_reframe$app$state_machine__20330__auto__ (eval at figwheel$repl$eval_javascript_STAR__STAR_ (repl.cljc:364), <anonymous>:204:57)
;; at cljs$core$async$impl$ioc_helpers$run_state_machine (ioc_helpers.cljs:43)
;; at cljs$core$async$impl$ioc_helpers$run_state_machine_wrapped (ioc_helpers.cljs:47)
;; at eval (eval at figwheel$repl$eval_javascript_STAR__STAR_ (repl.cljc:364), <anonymous>:218:67)
;; at cljs$core$async$impl$dispatch$process_messages (dispatch.cljs:27)
;; at MessagePort.channel.port1.onmessage (nexttick.js:218)
(put! c {:hi "here"})
;; All the below cases work
(go
(let [{:keys [a] :as msg} (<! c)]
(js/console.log [:msg-received msg])))
;; [:msg-received {:hi "here"}]
(put! c {:hi "here"})
(go
(let [msg (<! c)]
(js/console.log [:msg-received msg])))
;; [:msg-received {:hi "here"}]
(put! c {:hi "here"})
(go
(let [{:keys [new] :as msg} (<! c)]
(js/console.log msg)))
;; {:hi "here"}
(put! c {:hi "here"})
(defn receive-msg [msg]
(js/console.log [:msg-received msg]))
(go
(let [{:keys [new] :as msg} (<! c)]
(receive-msg msg)))
;; [:msg-received {:hi "here"}]
When I compare at the macroexpand-1
results, I found that in the failure case, the let-binding for new
seems to be shadowing the JS new
keyword, see the inst_23688
symbol before cljs.core/PersistentVector
:
(macroexpand-1
'(go
(let [{:keys [new] :as msg} (<! c)]
(js/console.log [:msg-received msg]))))
=> ...
(clojure.core/let
[inst_23687
(clojure.core/aget state_23694 2)
inst_23688
(cljs.core/get inst_23687 :new)
inst_23689
(. cljs.core/PersistentVector -EMPTY-NODE)
inst_23690
(js* "[~{},~{}]" :msg-received inst_23687)
inst_23691
(inst_23688
cljs.core/PersistentVector
nil
2
5
inst_23689
inst_23690
nil)
inst_23692
(js/console.log inst_23691)
state_23694
state_23694]
(cljs.core.async.impl.ioc-helpers/return-chan
state_23694
inst_23692))
Whereas in the successful case, there's the plain new
JS keyword before the cljs.core/PersistentVector
:
(macroexpand-1
'(go
(let [{:keys [a] :as msg} (<! c)]
(js/console.log [:msg-received msg]))))
=> ...
(clojure.core/let
[inst_24256
(clojure.core/aget state_24263 2)
inst_24257
(cljs.core/get inst_24256 :a)
inst_24258
(. cljs.core/PersistentVector -EMPTY-NODE)
inst_24259
(js* "[~{},~{}]" :msg-received inst_24256)
inst_24260
(new cljs.core/PersistentVector nil 2 5 inst_24258 inst_24259 nil)
inst_24261
(js/console.log inst_24260)
state_24263
(cljs.core.async.impl.ioc-macros/aset-all!
state_24263
8
inst_24257)]
(cljs.core.async.impl.ioc-helpers/return-chan
state_24263
inst_24261))