Fork me on GitHub
#clojurescript
<
2018-08-10
>
michael.heuberger00:08:02

there is https://github.com/sergeybekrin/cljs-babel but not sure if there are better solutions out there

Jordan Yee01:08:41

Does anyone know a good way to add a version number to the output files of compiled cljs? Instead of always outputting myproj.js, I'm trying to get something like myproj.js?v=1234 to prevent caching errors. Ideally the version number would be changed each time the file is re-compiled.

Oliver George05:08:53

Can someone recommend a way to avoid my different build profiles becoming a mess please. There are three variables involved: platform (ios or android), optimisation (none or simple) and system (dev, test or prod).

nenadalm16:08:23

Since project.clj is clojure - I suppose you could write code to generate these profiles?

Oliver George05:08:11

The system matters because it requires some :closure-defines to configure services.

Oliver George05:08:55

Figwheel has limited awareness of lein profiles so I'd need 6 profiles each with two builds (ios and android).

Oliver George05:08:14

I'd be happy to ditch lein in favour of clj and deps.edn. That would require a build script which generates the build configuration which is a little messy but works. I'm a bit muddled about how cljs.build.api/build works with source paths (it takes nil or one path but I have many source paths). My source paths differ for development (none) and production (simple) builds - perhaps I should be using a deps.edn aliases to control source paths.

Oliver George07:08:54

The deps.edn approach is looking pretty good. I can mix and match with -co like this:

clj -A:dev -m cljs.main -co compiler/ios-none.edn -co compiler/testserver.edn -c

Oliver George07:08:12

Sounds like clj -m figwheel.main is a thing too. Would be nice if it slotted in without too much additional baggage.

bhauman12:08:37

@olivergeorge figwheel.main can help you with this

Karol Wójcik13:08:50

Hi guys. Got some macro which uses the module imported to file in which that macro exists. The problem is that the macro instead of using the module from the macro file uses the module from the file in which is used.

(defmacro with-memory-monitor
  [filename body]
  `(let [should-close# (tools/register-close)
         writable-stream# (.createWriteStream nm/fs ~filename (cljs.core/clj->js {:encoding "utf-8"}))]

     ~body

     (.setInterval nm/timers
                   (fn []
                     (if-not @should-close#
                       (.write writable-stream# (str (.-heapUsed (.memoryUsage js/process))))
                       (.end writable-stream#)))
                   1000)))
For instance nm and tools should be taken from the file in which macro is defined

Karol Wójcik13:08:10

How can I achieve that?

kennytilton17:08:49

It seems to me you should be able to unescape those bits and then they will be resolved in the macro-defining namespace.

kennytilton17:08:26

Wait, that makes no sense. 😞

bhauman13:08:51

@kwcharllie379 you should make it and arg to the macro

bhauman13:08:36

to be clear I'm saying not nm but rather the nm/timers should be an arg

Karol Wójcik13:08:51

ok so the macro is unable to use the modules imported in macro file

bhauman13:08:25

in the file where it is used

mfikes13:08:27

I’ve been meaning to write a post on a pattern for getting macros to use runtime functions defined in “their namespace”. So far I only have a simple repo that illustrates the idea: https://github.com/mfikes/sucnm

bhauman14:08:11

@mfikes the link doesn't work

mfikes14:08:59

Thanks. Fixed. (It was private.)

Karol Wójcik14:08:38

Well that's not a problem to use the module from the file in which the macro is imported to. The problem is to use the some moduleA in a file in which macro is defined.

mfikes14:08:41

@kwcharllie379 In the example linked above, the producer.core/reverse-lookup macro uses producer.core/inverse*. Does that fall into your moduleA category?

bhauman14:08:41

yeah, mistated that

Karol Wójcik14:08:50

Yes. OK I think I get this. It's possible here because you got two files named core 😜

mfikes14:08:29

Right, the entire pattern is based on implicit macro loading (per (doc ns)), but you can see that producer.core/reverse-lookup' uses a function from an entirely different namespace as well

mfikes14:08:35

TL;DR: The producer.core/reverse-lookup' macro illustrates how you can arrange to use code from a 3rd namespace. (In the example that namespace is clojure.set)

mfikes14:08:24

I suspect you’d like with-memory-monitor to use stuff from the nm and tools namespaces. To do that their references would be qualified and the *.cljs file associated with with-memory-monitor would be the one to :require them.

scknkkrer14:08:53

I wanted to give something back to you all. Thank you. All comments are welcome. https://github.com/LeaveNhA/suluk

john14:08:55

ooh, I like that handler chain parameter idea

john14:08:20

different sort of ergonomic their

scknkkrer16:08:34

Thank you! 😇

scknkkrer16:08:11

Do you have any suggestion for it ?

john18:08:29

Haven't looked into it much. But any reason not to just let that fn take a variable number of args and just add each extra are to a chain internally? Or were you planning to extend the signature with other things?

scknkkrer13:08:20

Yeah. I have so many ideas but I need feedback. I want to work on this library. It looks so simple when you look at it first, but it has an important domain. This community helped me so much, I owe you guys.

chrisps14:08:12

is there a way to represent ##NaN as a literal in clojurescript?

bronsa14:08:36

##NaN is a literal

mfikes14:08:40

That’s the usual way… but what do you really mean?

Karol Wójcik14:08:49

Yes so basically I would have to create macros.cljs in which I import this nm and tools and everything should work.

Karol Wójcik14:08:56

Thank you very much @mfikes

mfikes14:08:26

Yeah, and be sure to qualify things (presuming nm and tools might be aliases given they are single-segment symbols)

❤️ 4
chrisps14:08:35

oh, yes it is

chrisps14:08:03

so (js/isNaN ##NaN) should work?

👍 8
chrisps14:08:00

never mind

chrisps14:08:55

just stale buffers

Karol Wójcik15:08:08

It works! thank you @mfikes you’re Clojure/script magician

idiomancy15:08:14

so, in garden

(ns css-playground.styles
  (:require [garden.def :refer [defstyles defcssfn]]
            [garden.units :refer [px em]]))

...
:padding [(em 5.625) (em 12.5) (em 12.5) 0]
...

compiles to
...
padding: 5.625em, 12.5em, 12.5em, 0;
...
is there any way (other than just doing a string instead of data) to specify something that compiles to padding: 5.625em 12.5em 12.5em 0;?

idiomancy15:08:33

the commas are screwin me

benzap16:08:19

you wrap it in another list

benzap16:08:36

:padding [[(em 5.625) (em 12.5) (em 12.5) 0]]

benzap16:08:55

lol yeah, untested, I think that's how

idiomancy16:08:04

where'd you find that trick?? 😂 it totally works!

benzap16:08:13

I ran into the same issue a long time ago 😛

idiomancy16:08:51

hahaha, that's awesome. there is so much undocumented magic in garden its crazy

idiomancy01:08:22

oooh, you got me... I didn't read that whole page 😅

idiomancy01:08:33

thanks, aisamu!

🙂 4
🤓 4
idiomancy16:08:57

thank god for clojurians

benzap16:08:54

Agreed, I feel like a good blog post, or maybe some more stuff added to the wiki would help a lot

idiomancy16:08:56

much gratitude, benzap

kennytilton17:08:03

In this space recently, hearty skepticism was expressed as to whether I might have anything new to offer on Web app development. Very understandable. I have done my best to write it up, and would be interested in critical feedback. https://github.com/kennytilton/mxtodomvc/blob/master/README.md

👍 4
leonoel16:08:40

You should start with a rationale. That would help readers to understand what problem you're trying to solve and what is your value proposition compared to other cell-based dataflow engines.

leonoel16:08:37

also, you should define what HLL is

leonoel16:08:08

the code snippet in paragraph A tells B is weird

kennytilton17:08:50

That is part one. It links to a denser part two on which I am still hacking. Beware. 😱

benzap18:08:28

Neat, i'll give it a read

kurt-o-sys19:08:27

I have an app in cljs which compiled within a few dozens of seconds, which is fine. However, now, it takes a very long time, if it ever succeeds. Even after reverting my last changes, compilation seems to take forever. Is there a way to 'debug'/profile compilation?

dnolen19:08:05

:verbose true :compiler-stats true

kurt-o-sys19:08:45

shadow-cljs watch app
[...]shadow-cljs - config: [...]/shadow-cljs.edn  cli version: 2.4.
28  node: v8.11.3                                                                                                                                                                                                                            
shadow-cljs - running: lein run -m shadow.cljs.devtools.cli --npm watch app
Aug 10, 2018 9:24:23 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.8.Final
Aug 10, 2018 9:24:23 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.8.Final
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.xnio.nio.NioXnio$2 (file:/home/storage/mvn/repository/org/jboss/xnio/xnio-nio/3.3.8.Final/xnio-nio-3.3.8.Final.jar) to constructor sun.nio.ch.EPollSelectorProvider()
WARNING: Please consider reporting this to the maintainers of org.xnio.nio.NioXnio$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Aug 10, 2018 9:24:23 PM shadow.build.classpath invoke
INFO: duplicate resource day8/re_frame/tracing.cljc on classpath, using jar:file:/home/storage/mvn/repository/day8/re-frame/tracing/0.5.1/tracing-0.5.1.jar!/day8/re_frame/tracing.cljc over jar:file:/home/storage/mvn/repository/day8/re-fra
me/tracing-stubs/0.5.1/tracing-stubs-0.5.1.jar!/day8/re_frame/tracing.cljc                                                                                                                                                                   
shadow-cljs - HTTP server for :app available at 
shadow-cljs - server version: 2.4.28
shadow-cljs - server running at 
shadow-cljs - socket REPL running on port 35966
shadow-cljs - nREPL server started on port 3333
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
Aug 10, 2018 9:24:29 PM com.google.javascript.jscomp.PhaseOptimizer$NamedPass process
WARNING: Skipping pass rewriteGoogJsImports
Aug 10, 2018 9:24:29 PM com.google.javascript.jscomp.PhaseOptimizer$NamedPass process
INFO: pass supports: [ES3 keywords as identifiers, getters, reserved words as properties, setters, string continuation, trailing comma, array pattern rest, arrow function, binary literal, block-scoped function declaration, class, computed
 property, [...] operator (**), async function, trailing comma in param list]                                                                                                                              
current AST contains: [ES3 keywords as identifiers, getters, [...] new.target, octal literal, RegExp flag 'u', RegExp flag 'y', rest parameter, spread exp
ression, super, template literal, modules, exponent operator (**), async function, trailing comma in param list, object literals with spread, object pattern rest]                                                                           
Aug 10, 2018 9:24:41 PM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: node_modules/highlight.js/lib/languages/tp.js:14: WARNING - String continuations are not recommended. See 
    begin: '(AR|P|PAYLOAD|PR|R|SR|RSR|LBL|VR|UALM|MESSAGE|UTOOL|UFRAME|TIMER|\
           ^

Aug 10, 2018 9:24:41 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 0 error(s), 1 warning(s)
the warnings are there already quite some time. They don't seem to be harmful.

dnolen19:08:29

@kurt-o-sys oh shadow, you probably want to ask in the #shadow-cljs channel

kurt-o-sys19:08:47

right, thx...

pvillegas1219:08:52

@dnolen what’s the current state of om-next?

kennytilton21:08:14

Thanks, @benzap. And thanks to @mikethompson for the pep talk as I waded into the task. I even learned I could embed raw HTML in readmes from his doc. 🙂

dnolen21:08:38

@pvillegas12 it exists and works in it’s current form but I don’t really have much time these days to steward it - ClojureScript demands and all

dnolen21:08:53

@pvillegas12 there’s also pretty nifty alternatives - Fulcro

dnolen22:08:08

and of course the idea is bigger than the lib - you can adopt the patterns a la carte

pvillegas1222:08:55

Are there any big departures between fulcro and om-next? I’m evaluating between using either for a new project

dnolen22:08:29

fulcro I think is more flexible / dynamic now - I didn’t have time to sort that out in om-next

👍 4