Fork me on GitHub
#clojurescript
<
2017-05-12
>
qqq00:05:54

I have a cljs codebase. It's 1200 lines. It takes 54 seconds on :optimizations :advanced, and 47 (from cold start, not incremental) on :optimizations :none ?

souenzzo01:05:04

qqq: looks the same here

qqq19:05:08

@U2J4FRT2T : thanks for verifying

souenzzo20:05:26

qqq: ps: I'm on i3 notebook/8Gb/SSD

qqq21:05:08

I'm on an 8-core server with 32GB RAM

qqq21:05:16

maybe mine should be slightly faster

qqq00:05:56

Is this normal?

tbaldridge02:05:39

@qqq maybe for a "from scratch" compile, but most of that time would be in spinning up the compiler and analyzer. In my codebases (well over 10k lines) I could get much faster compilations with incremental compiles

tbaldridge02:05:10

e.g. a "rebuild all" in figwheel maybe took 1 min, but a simple saving of a file and it getting pushed to the browser via figwheel took less than a second

john03:05:19

Anyone care for a thenable atom?

(defn watch-cycle [a]
  (let [k (gensym)]
    (add-watch a k
      (fn []
        (remove-watch a k)
        (reduce #(%2 %1) @a (:q (meta a)))
        (alter-meta! a update :q #(vec (rest %)))))))

(defn aswap [a afn]
  (alter-meta! a assoc :q [])
  (watch-cycle a)
  (js/setTimeout #(swap! a afn) 1)
  a)

(defn then [a afn]
  (alter-meta! a update :q conj afn)
  a)
then...
dev:user=> (def t (atom 1))
dev:user=> (-> (aswap t inc) (then #(inc %)) (then #(println "result:" %)))
#object [cljs.core.Atom {:val 1}]
dev:user=> result: 3
dev:user=> @t 
2

john03:05:00

Yeah, I know, bad use of meta. I just haven't mastered extend-type yet. (don't do that at home)

john03:05:14

Then chaining is just a simple (defn chain [a & fns] (reduce then a fns)) with (chain (aswap t inc) #(inc %) #(println "result:" %))

Geoffrey Gaillard03:05:16

Hi everybody ! I'm trying to separate a cljs build in 3 closure modules: common.js, outer-pages.js and inner-pages.js. But my inner-pages.js and outer-pages.js files are always empty. I suspect code motion to be responsible and I'd like to force the compiler to not move everything to common. Is it possible ?

thheller07:05:59

consider using this for :modules, lets just say the CLJS version of :modules has "issues".

thheller07:05:21

but if the files are empty they might just be removed as dead code? do the entries contain any ^:export or code that runs?

Geoffrey Gaillard08:05:10

Hi @thheller, I tried it but I got some issues with shadow-devtools. An error saying that Prone (a library) tried to provide cljs.core, if I understood well

[:dev] Build started.
-> Finding resources in classpath
Ignoring bad file, it attempted to provide cljs.core
jar:file:/Users/geoffrey/Documents/GitHub/bf/bf.front/local-m2/prone/prone/1.1.4/prone-1.1.4.jar!/prone/generated/prone.js
<- Finding resources in classpath (4201 ms)
FIXME: error format for clojure.lang.ExceptionInfo <:tag missing>===
So I removed Prone and still got the <:tag missing>=== error …

Geoffrey Gaillard08:05:16

You might be right about DCE, the namespaces I'm trying to modularize are all only implementing a multimethod. I have this architecture : app.dispatcher is a namespace defining a get-view multimethod. app.core is requiring app.dispatcher and app.pages. app.pages require all the app.pages.<page-name> namespaces. Every app.pages.<page-name> require app.dispatcher and add a multimethod implementation to it. If I compile the whole thing in :advanced mode without modules I get everything working, so I guess DCE is not removing app.pages.<page-name> namespaces

Geoffrey Gaillard08:05:59

I'm trying to find what is causing the :tag missing exception

thheller08:05:20

defmethod is never removed by GCL so it isn't that.

thheller08:05:54

the good old prone issue, I though that was fixed

thheller08:05:56

let me check

thheller08:05:19

supposedly that is fixed

thheller08:05:13

sorry for the FIXME, I try to now show JVM exception traces whenever possible

thheller08:05:27

the :tag missing is my bad. nothing in your code

magnars09:05:08

The problem with excess files in the Prone jar was fixed in the 1.0 release. Is that not the case for you?

thheller09:05:31

.m2/repository/prone/prone/1.1.4/prone-1.1.4.jar!/prone/generated/prone.js

thheller09:05:37

still seems to be in there

magnars09:05:19

That's not in excess tho, that's needed to run the prone client.

magnars09:05:53

There used to be hundreds of files in there, IIRC.

thheller09:05:57

any reason that isn't optimized?

thheller09:05:06

:simple or :advanced or even :whitespace?

thheller09:05:23

nope, optimized builds do not contain any goog.provide goog.require

thheller09:05:44

@U07FCNURX not a problem really. you should probably switch to at least :simple though. 2.1mb JS seems excessive for what you are doing

thheller09:05:16

@U2DART3HA the issue is somewhere else, I can work with prone just fine. do you have more errors after the missing tag? there should be a trace no?

thheller09:05:01

did you use [thheller/shadow-devtools "1.0.20170503"]?

Geoffrey Gaillard09:05:08

Effectively, I had [thheller/shadow-devtools "0.1.20170408"], my bad 😕 . I first pulled the lastest clojars version, but by trying different configurations from exemples I must have copied this version. Updating did indeed fix the <:tag missing> message. But I got an exception with goog dependencies

ExceptionInfo ns "goog.i18n.NumberFormatSymbols_fr_FR" not available, required by bf/front/core.cljs 

Geoffrey Gaillard09:05:16

by the way I got no traces for these errors

thheller09:05:17

yeah I try to hide them on purpose, since they just confuse the issue

thheller09:05:20

the error is all I need, there should only be traces for errors I didn't make "pretty" yet.

thheller09:05:39

so goog.i18n.NumberFormatSymbols_fr_FR does not exist, only goog.i18n.NumberFormatSymbols_fr

thheller09:05:01

are you possibly on an older version of CLJS before shadow-devtools?

thheller09:05:27

looks like you have an older closure library version which maybe had this?

thheller09:05:10

but btw you should not need to directly access those

thheller09:05:43

just import goog.i18n.NumberFormatSymbols and set :closure-defines {goog.LOCALE "fr"} in the build config

Geoffrey Gaillard09:05:17

I had retrocompatibility issues preventing me to update, but since shadowbuild bring a new version on the closure library I have to adapt my code. I will do it now.

Geoffrey Gaillard09:05:14

I have a lot of things to fix but it's going way better ! I'm really sorry I took your time with these issues 😕

thheller09:05:11

nonsense, thank you for sticking with it. I need people that run into issues when compiling, only way to fix it.

thheller09:05:43

please let me know if you run into any other rough edges, I want to clear them up. even if it just a better warning/error

Geoffrey Gaillard10:05:46

I keep having these errors

NS:figwheel.client.file-reloading has duplicate require/use for goog.string
I removed duplicates from my code and made a pull request to fix one in Re-Frame, but I can't do it for every libraries, is there a way to disable these checks ?

thheller11:05:28

uhm figwheel won't work with this. shadow-devtools has its own REPL/file-reloading that you don't need to configure

thheller11:05:51

I will see if I can be less strict about duplicate requires. I always considered these to be errors but it should probably just warn

thheller11:05:26

just pushed version 1.0.20170512-13 which removes that check. turns out clojure allows this as well, so not actually an error. my bad.

thheller12:05:28

just wrote an extra section about live-reloading, wasn't documented that well before

Geoffrey Gaillard15:05:52

@thheller I managed to make it work ! But I have still problems with cross module code motion … Don't think it's a shadow-build problem, more the way I configure it. I have the same behaviour with the classic cljsbuild. I'll ask on #clojurescript, I must have missed something.

slester05:05:20

Is there a good way to implement (format "%.1f" s) so that it works in both Clojure and ClojureScript? It looks like it was removed at some point as a wrapper for goog.string.format, but I'm using this in a shared file. 😞

qqq05:05:34

(def my-format #?(:clj format :cljs goog.string/format)) ? / ducks

qqq05:05:45

I'm into the same prolblem and seriously considering the above myself.

noisesmith05:05:47

that's pretty much what I do in namespaces where I need to format in cljc, yes

kauko10:05:29

Has there been any talk about when the next version of clojurescript will be released? I'd love to get the clojure.spec.alpha naming changes https://github.com/clojure/clojurescript/compare/r1.9.521...master

dnolen12:05:44

@kauko probably today

dnolen12:05:24

@qqq well you need to factor in your deps of course - and whether you using a 3rd party tooling (Boot/Lein) to kick of that process

martinklepsch14:05:33

If you always get confused about requiring namespaces, constructors and whatnot from Closure Library this one is for you https://twitter.com/martinklepsch/status/863043601760112640 💝

thheller15:05:28

@martinklepsch strictly speaking shortcut/EventType.SHORTCUT_TRIGGERED is not allowed. it should be :import the EventType and then (.. EventType -SHORTCUT_TRIGGERED)

martinklepsch15:05:43

currentoor: welcome! 🙂

martinklepsch15:05:24

@thheller ah, really? I saw the issue with EventType shadowing each other and thought it might be better to describe the way that cannot suffer from this issue

martinklepsch15:05:38

@thheller in what way could/would it break?

martinklepsch15:05:25

Do you mean strictly as in it’s not proper cljs syntax?

thheller15:05:18

@martinklepsch @dnolen any official word on whether shortcut/EventType.SHORTCUT_TRIGGERED is allowed? (the property access) clojure doesn't allow it so I assumed it only worked accidentally in CLJS (or something limited to js/)

thheller15:05:13

@martinklepsch to be honest I'm surprised that even works 😛

martinklepsch15:05:18

I found import weird because import is for constructors

thheller15:05:35

the issue is problematic because you may skip imports that way

martinklepsch15:05:53

@thheller it works because it’s in the same file

thheller15:05:59

goog/net.XhrIo for example wouldn't work unless the XhrIo was required somewhere else already

martinklepsch15:05:27

(.-SHORTCUT_TRIGGERED shortcut/EventType) that would be perfectly valid no?

martinklepsch15:05:37

I think much of this stuff is a bit mushy because it’s JS

martinklepsch15:05:13

FWIW you can even do KeyboardShortcutHandler.EventType.SHORTCUT_TRIGGERED after importing the constructor

thheller15:05:26

yeah closure sometimes is a bit weird in their code layout

thheller15:05:58

yeah because it is all one file

thheller15:05:46

but as fair as I know the alias/something.nested syntax isn't allowed since clojure doesnt allow it

thheller15:05:32

well they allow it since you can have dots in vars, but that would be one var ...

martinklepsch15:05:55

yeah, totally get that argument

martinklepsch15:05:31

still given :import is for constructors, what would be a perfectly valid way of doing it?

thheller15:05:08

I don't know, if shortcut/EventType.SHORTCUT_TRIGGERED works just use it. (.. shortcut/EventType -SHORTCUT_TRIGGERED) or js/goog.ui.KeyBoardShortcutHandler.EventType.SHORTCUT_TRIGGERED is what I usually use

thheller15:05:22

in case of conflicting imports for EventType

thheller15:05:28

otherwise just :import

thheller15:05:05

in case of js/ don't forget the require for [goog.ui.KeyBoardShortcutHandler.EventType] though

martinklepsch15:05:59

not a fan of js/goog but yeah, whatever works I guess

martinklepsch15:05:17

curious what David has to say

antonmos18:05:17

I am looking for a way to register an unhandled error handler in re-frame or reagent. The idea is that when any unhandled error occurs, a user friendly message is displayed. is there a standard way of doing this? Thanks!

rgdelato18:05:41

I know window.onerror = function () {...} used to exist in Firefox, but I haven't used it in a long time and don't know what the browser compat is on it nowadays

dnolen18:05:29

@thheller it will always work, consider that pattern officially supported

dnolen18:05:23

goog/net.XhrIo is improper of course

dnolen18:05:39

but if you’re just talking about nested property access with inline ., will always work

dnolen18:05:23

if people want to abuse it, nothing will stop them, and we’re unlikely to bother with all the work that would be required of validation

thheller18:05:27

@dnolen ok thx, good to know.

thheller18:05:49

@martinklepsch there you have it. I was wrong I guess.

john21:05:12

I'm trying to figure out how to convert this js snippet to cljs

function hexToBase64(hexstring) {
    return btoa(hexstring.match(/\w{2}/g).map(function(a) {
        return String.fromCharCode(parseInt(a, 16));
    }).join(""));
}

john21:05:26

the match isn't working though

john21:05:59

clearly, I'm expecting the wrong thing with this: (.match "e34a" #"/\w{2}/g")

john21:05:17

or, maybe I'm reading the .map wrong?

john22:05:01

I assume we're mapping the anonymous function (on the right) across the result of the .match on the hex string.

jr22:05:32

your regex is wrong

jr22:05:46

/foo/ is a literal regexp in javascript

jr22:05:06

the / parts are unnecessary in that regexp form

john22:05:25

I figured. I've been trying variations.

john22:05:05

ah, #"\w{2}" ?

jr22:05:20

yes and the g modifier is there by default IIRC

thheller22:05:33

use re-matches not .match

john22:05:02

I hate regexs 🙂

john22:05:29

every language seems to implement them a little differently

qqq23:05:35

Is there an off the shelf drag + drop component (so an file is on the user's desktop, and they drag it onto a div, and the cljs uploads the file). All libraries I have found so far is about "dragging + droppung divs within the website, but not a file from outside the browser into a div on the browser"