Fork me on GitHub
#clojurescript
<
2021-01-03
>
denik19:01:31

Is there a way to inline the result of a clojure expression in clojurescript? for example:

(into [:div] (map (fn [db-value] [:div db-value])) (clj-inline (db-get :foo)))
the result of the into should be the same in CLJ and CLJS

p-himik02:01:55

If some of the values are available only in run time then the answer is no - you will have to set up a proper data transfer. But if all of the values are available during the CLJS compile time, then you can use macros.

dazld22:01:00

Possibly a silly question, but why doesn’t

(-> (js/Promise.resolve {:foo :bar})
    (.then :foo)
    (.then prn))
..output :bar ?

dazld22:01:18

(.then #(:foo %)) works fine, but isn’t this equivalent?

lilactown23:01:09

.then expects a JS function, but you are passing a keyword

👍 3
lilactown23:01:20

Keywords implement the IFn protocol, which make them callable when used in a ClojureScript context, but passing them as values to JS constructs like .then on promises, or .map on arrays, the JS constructs don’t know how to properly invoke a non-function

☝️ 4
valtteri07:01:07

cljs.user> (goog/typeOf #(:a %))
"function"
cljs.user> (goog/typeOf :a)
"object"

👍 3