Fork me on GitHub
#clojurescript
<
2018-06-03
>
lilactown01:06:26

hm that might have been a red herring. I’m also using shadow-cljs, which treats npm deps way differently than cljsbuild

thheller07:06:00

@lilactown if you need to emit #js ... from a macro you must emit ~(cljs.tagged-literals/JSValue. {:hello "world"}) directly. since the reader is already done you cannot do this via manipulating that. your macro must emit the correct value. the above is equivalent to #js {:hello "world"} when written in CLJS.

thheller07:06:10

(js-obj :hello "world") also works though

jerger_at_dda11:06:24

Hi, any idea how to slurp files from jar file / classpath? ATM my code reads from file system with http://lumo.io/slurp - in clojure I would use (slurp ( "mytemplate")) - how I can do this in cljs ?

mfikes12:06:02

@jerger I've implemented this in Planck (which is self-hosted, like Lumo), so you could copy the relevant bits of Plank's implementation.

jerger_at_dda12:06:14

after reading some source I found the answer 🙂 ( ( "mytemplate"))

mfikes12:06:32

Ahh cool. Nice to see that works.

jerger_at_dda12:06:44

@mfikes do u have a github url?

mfikes12:06:55

@jerger_at_dda Planck pulls it off by implementing the IOFactory stuff that is in Clojure, so a lot of it is in here https://github.com/planck-repl/planck/blob/master/planck-cljs/src/planck/io.cljs

jerger_at_dda12:06:25

okay ... understand ... planck provides a c function, PLANCK_LOAD_FROM_JAR wraps it and io.cljs uses it ... Is there some kind of RFC how planck or lumo extract jars to be able to read resources or does every implementation its own handling?

mfikes12:06:33

Well, since there is no slurp or io/resource in ClojureScript, it is up to each implementation to roll its own solution.

roti14:06:03

has anyone worked with closure's promises? i can't find a method to resolve them... 😞

pesterhazy14:06:51

@roti, are they better than native promises in any way? or why are you interested in them?

roti14:06:06

i don't know much about native promises, but I guess the google ones are more browser independent. apparently there's also a performance factor involved: http://funcool.github.io/promesa/latest/#why-bluebird-instead-of-es6-promise

pesterhazy14:06:41

I don't think browser independent is much of a concern anymore (plus you can use shims if necessary)

pesterhazy14:06:57

if you're writing new code, I'd stick to es6 promises

pesterhazy14:06:19

Promises are actually quite pleasant to use from Cljs IMO: (-> (promise-returning-fn) (.then ...) (.then ...))

metacritical16:06:06

@mfikes I think it would be great if clojurescript had a slurp it can work with fs on backend and in browser using xhr atleast this is how it works in clojure. so that one can do (slurp “)

lilactown16:06:28

the issue is that xhr is async, while slurp is typically sync

lilactown16:06:57

fs has sync options in node but web does not

metacritical16:06:29

Yeah that is a big problem.

metacritical16:06:10

May be a (slurp "/some/path" #(callback-function)) can work.

richiardiandrea16:06:44

Check out abio 😄

metacritical16:06:27

Haha interesting! 😃

lilactown16:06:16

for JS interop - is it not suggested to use (.foo obj ) (.-bar obj) at all?

lilactown16:06:58

and other associated macros

justinlee16:06:03

it’s perfectly fine (and necessary) to use that notation

justinlee16:06:31

oh, sorry, actually, I should say, if you are using shadow-cljs it’s fine because it infers externs

justinlee16:06:45

i’m not sure how good externs inference is on the mainline compiler now. before I moved to shadow i used cljs-oops to do js interop access to avoid the externs issue.

metacritical16:06:41

Both (.-some)and (aget coll 'key') can be used.

lilactown16:06:09

I’ll have to experiment with how good shadow-cljs externs inference is

justinlee16:06:24

well the official take on aget is that we’re not supposed to use it for property accessors anymore

darwin16:06:00

and it spits warnings in recent cljs releases

darwin16:06:45

actually that flag is not on by default

justinlee16:06:52

@lilactown it works great. you do have to do some light type hinting sometimes, but the compiler will warn you if it can’t figure it out so that you don’t miss any: (defn [^js obj] (.-foo obj)

darwin16:06:54

but library writers should be aware of that

justinlee16:06:12

in shadow, the warnings are on by default i believe

lilactown16:06:22

like e.g. I have (.. this -state -baz) where state is JS and baz is defined by userland

jsa-aerial18:06:56

Would the facilities described here https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules be able to pull in https://nodejs.org/api/stream.html in a browser setting? Or is that strictly only going to work when targeting nodejs?

justinlee18:06:37

@jsa-aerial the reverse actually: it is intended to bring npm modules into the closure compiler and ship them to the browser. note, that the feature describes is really quite experimental. if you want a robust and reliable way of using npm modules on the browser, use shadow-cljs for your build tool

justinlee18:06:04

sorry actually ignore what i just said

justinlee18:06:33

you’re asking a more specific question about stream. no you cannot use the stream api on the browser using any tool because the browser won’t allow you to

lilactown19:06:59

@jsa-aerial that’s a native Node.js API, it does not work in the browser. you could possibly find a JS library that implements something similar that works in the browser

lilactown19:06:27

if it is distributed via NPM, then the link you posted is relevant

jsa-aerial19:06:47

@lilactown @lee.justin.m That's what I was afraid of. I think this http://highlandjs.org/ would work as replacement ...

lilactown19:06:45

@jsa-aerial what are you trying to do exactly? I don’t think highland is really related to Node.js streams

lilactown19:06:24

highland is more like a cross between clojure.core sequences and core.async

jsa-aerial19:06:35

@lilactown It's just the stream part of nodejs streams - actually just the Transform part of that. It is used in cljs-msgpack-lite. So, to start I think the idea is to split off the stream stuff from the basic msgpack stuff, then redo the stream Transform stuff with highland (which seems to have basically the same capability, but runs in both node and browser)