Fork me on GitHub
#clojurescript
<
2017-09-20
>
baptiste-from-paris06:09:18

Hello friends, I have to build a Lumo script @work (something that I never did) and I have a few questions for those who have answers : 1. Is there a “clojure” way to use promise/async/await (I am using puppeteer with headless chrome 2. Do you have some feedbacks on running nodejs generated with cljs script in Lambda ?

gklijs09:09:48

@baptiste-from-paris there is core.async for cljs, you can have go loops with a wait and some conditions

baptiste-from-paris09:09:34

you mean wrapping wait/async calls into core.async ?

dominicm09:09:31

@baptiste-from-paris there's no cljs syntax for async/wait, I think there's a neat hack that was come up with in #lumo

dominicm09:09:48

(defn x [] (js/Promise. (fn [resolve reject] (resolve 42))))
(js* "(async () => ~{}(await ~{}))();" js/console.log (x))
(Note, this uses internals of cljs) This could be wrapped into an async macro 🙂

fbielejec13:09:36

How can I access process.env variables from a cljs app running on node.js?

(ns app.core
  (:require [cljs.nodejs :as nodejs]))

(nodejs/enable-util-print!)

(defn -main [& _]
  (println "your var: " (aget js/process.env "MYVAR") ))

(set! *main-cli-fn* -main)
then (core.js is figwheel compiled app:)
node app/core.js MYVAR=foo
Prints:
Your var:  nil

darwin13:09:06

what about MYVAR=foo node app/core.js ?

fbielejec13:09:23

Damn it 🙂

darwin13:09:16

this is not ruby's rake, you have to use your bash-fu 🙂

fbielejec14:09:48

and the process.env is a JSON object? Can I js/JSON.parse it and access all the keys?

darwin14:09:11

@fbielejec no, it is just a JS object, AFAIK

mfikes14:09:01

@fbielejec If you want all the keys, (js-keys js/process.env)

fbielejec14:09:07

thanks @mfikes , (.keys js/Object js/process.env) also works

fbielejec14:09:53

(because its probably the exact same thing)

mfikes14:09:11

@fbielejec You can do (source js-keys) at a REPL to see how it works. FWIW, there is a ticket (CLJS-2340) that may result in js-keys simply delegating to goog.object/getKeys

conaw22:09:10

This might be a beginner question, but I have a large json data file that want to have access to as a clojure map for a static site I’m developing (no backend, just cljs), can I just use :require?

conaw22:09:06

I figure I’ll use either transit/read, edn/read or just JSON/parse, but curious how I can require the JSON in the first place

johnj22:09:14

ajax the data

noisesmith22:09:40

@conaw how will the data be deployed?

noisesmith22:09:00

you can't require json, since json doesn't have namespaces for starters

madstap22:09:34

@conaw You could slurp it at compile time with a macro, if you're not using bootstrapped cljs.