Fork me on GitHub
#clojurescript
<
2017-06-13
>
hlolli12:06:01

Someone here posted few days ago a compilation of cljs code to js string, should have copied that snippet, but what am I missing

(cljs.compiler.api/compile-file (cljs.analyzer.api/empty-state) "(reduce + [0 1 2 3])" "" {:optimizations :none})
=> FileNotFoundException The file (reduce + [0 1 2 3]) does not exist. 

nha14:06:50

I seem to recall that the google closure compiler assumes it compiles everything on a given page, making it impossible to have different .js files compiled by the closure compiler on the same page. But I can’t find a source for it, does anyone know if that assumption is correct?

manu14:06:08

Hi all! anyone knows how to do a line break into the art text component?

manu14:06:36

I tried in this way, but it doesn't work

thheller15:06:28

@nha yes its not safe to have different files unless you use :output-wrapper and :externs or course

nha15:06:18

Ah, I was not aware of :output-wrapper. Interesting thanks 🙂

nha15:06:54

Just out of curiosity, do you know what happens if I have a compiled module already ( for instance like https://www.npmjs.com/package/transit-js (I know there is a .cljs version, this is just an example)). Can I use it as “plain” javascript and pass it through the cljs compiler again along other cljs/js code?

thheller15:06:01

I don’t understand the question?

dnolen15:06:18

@nha you can since transit-js exports the API, but not recommended at all

dnolen15:06:54

@nha in general your initial assumption is correct - separately compiled Closure generated JS is not a good idea

nha15:06:33

That makes sense, thanks @thheller @dnolen 🙂

joshkh15:06:21

just to ask my dumb question of the day, there's no way to use advanced compilation to make a bundle per namespace (to be loaded asynchronously), correct? you can only bundle shared code across namespaces?

joshkh15:06:22

i have some hefty parts of my app that aren't frequently used and i'd prefer not to force people to download the whole thing if need be

thheller15:06:53

I need still need to write a proper guide for all of it but the basics are there. it lets you async load stuff on demand

thheller15:06:13

with :modules for code splitting

joshkh15:06:17

are those modules the same as :modules found in cljs compiler?

joshkh15:06:41

@thheller this looks fantastic, thank you

thheller15:06:31

sort of yes but quite a few differences compared to the cljs.closure impl

dnolen15:06:49

@joshkh also the work is in flight to make this “easier” in ClojureScript.

Pablo Fernandez16:06:05

How do I get "bar" from #js {:foo "bar"} without doing js->clj? I thought .-foo would do it, but it doesn't.

joshkh16:06:24

good to know, dnolen

mfikes16:06:27

@pupeno That works, if you ignore the munging effects of :advanced

Pablo Fernandez16:06:07

I'm getting nil.

mfikes16:06:21

(.-foo #js {:foo "bar"}) yields nil?

devth16:06:25

is https://github.com/clojure/core.incubator available for clojurescript somewhere? not seeing it, but this post http://blog.wjlr.org.uk/2015/01/17/fast-string-interpolation-cljs.html makes it sound like it should be :thinking_face:

devth16:06:51

specifically looking for clojure.core.strint

Pablo Fernandez16:06:12

Actually, no, but (.-foo-bar #js {:foo bar "foo bar"}) does yield nil.

captainlexington16:06:19

Sorry if this off-topic, but what is the use-case of strint? Why not just str things together? Is it a performance issue?

mfikes16:06:17

Hah, munging converts (.-foo-bar #js {:foo-bar "foo bar"}) to this JavaScript: ({"foo-bar": "foo bar"}).foo_bar

Pablo Fernandez16:06:24

So, is it possible to access it?

mfikes16:06:27

Damned minus operator

mfikes16:06:42

Sure, aget would probably do it

anmonteiro16:06:58

goog.object/get

mfikes16:06:23

Even better ^

dnolen16:06:07

@devth not ported as far as I know

devth16:06:25

@dnolen ok thanks. apparently not ported but i was able to use it via :require-macros

dnolen16:06:59

right if the implementation is clean and it’s a macro, it should work

misha20:06:37

how can I avoid such compilation warnings in figwheel?

misha20:06:28

everything is ok right after page refresh, but after any hot-reload I get this warning (note clojure vs. cljs):

clojure.core/format
^--- Use of undeclared Var cljs.core/format
(it is in .cljc file)

dnolen20:06:04

@misha it’s doesn’t exist in ClojureScript you cannot use it

dnolen20:06:12

wrap in a reader conditional

misha20:06:41

ah. it was removed

misha20:06:12

I did exactly that: used goog.string/format thanks David

misha20:06:14

... which is missing not-sure-fry

misha20:06:23

(:require
    #?@(:cljs [[goog.string :as gstring]
               [goog.string.format]])))  ;;<--- extra touch
;; then:
(gstring/format ...)

akond20:06:12

is there a macro or anything that allows me to write instead of this (fs.readFile "file" callback) that (??? (fs.readFile "file") callback)? and therefore would save me of all the troubles of callback hell?

moxaj20:06:36

(defmacro foo [expr callback]
  (concat expr [callback]))
@akond ?

akond20:06:15

what about callback2 that is inside callback?

akond20:06:32

i am looking for something similar to -> or ..

captainlexington20:06:42

@akond If I understand you correctly, this is more or less what core.async is about. I haven't used it very much, but what I did do precisely alleviated my callback hell problems. Have you checked out any core.async tutorials?

akond20:06:10

it's just core.async api is not very simple

akond20:06:04

you think i should use manifold library or something similar?

captainlexington21:06:06

I haven't used manifold. I agree that core.async has a strange API, but I think once you get over the initial learning curve it really pays off in the long run

akond21:06:01

i've seen what @tbaldridge has to say about core.async

akond21:06:42

so i should be very careful about how i use core.async

noisesmith21:06:18

some of those concerns are specifically about core.async on the jvm - it’s less complex in js

akond21:06:10

but still, core.async is not as neat as ->

captainlexington21:06:57

I think this couldn't be done unless, in addition to a macro for chaining the callbacks, the callbacks themselves were defined using some kind of defcallback macro that hooked them into a callback manager behind the scenes

akond21:06:24

i've been dreading this

seylerius21:06:32

Is there a way to have a node lib on my dev machine, use it in a script, and have the script compile to JS that includes it, such that I don't need to install that lib on five to fifty target machines?

seylerius21:06:42

Kinda similar to an uberjar?

ag21:06:14

has anyone successfully applied sourcemaps with advanced optimization and served them from uberjar? can someone point to some blogs and whatnot where I can learn how to get it right? Thanks!