Fork me on GitHub
#clojurescript
<
2017-08-01
>
noisesmith00:08:39

the latest cljs has a config for it, actually

chris_00:08:38

Sure thing @akiroz

(defn handler [response]
  response)

(defn error-handler [{:keys [status status-text]}]
  (.log js/console (str "something bad happened: " status " " status-text)))

(defn get-request-word [a-url]
  (GET
    a-url
    {:handler handler :error-handler error-handler}))

(defn get-url-as-hickory
  [a-url]
  (let [processed-response (get-request-word a-url)]
    (do
      (.log js/console "processed-response: " processed-response)
      (hc/as-hickory (hc/parse processed-response)))))

(def welcome-url "")
Then the actual call: (get-url-as-hickory welcome-url)

chris_00:08:06

'GET' is cljs-ajax/GET

chris_01:08:06

(The problem is that (:body response) is just returning null, even though I can print the raw HTML str (from the successful request) to the console.)

akiroz06:08:59

@chris_ Oh sorry, I got wrong the whole time... the response from cljs-ajax is not a ring response map but the actual body. I got it mixed up with another library.

akiroz06:08:42

but that code wouldn't work as you expected, GET doesn't return stuff so you can't so (let [processed-response (get-request-word a-url)]

akiroz06:08:06

should be something like this:

(defn url->hickory
  "Takes a URL returns Promise of a hickory tree."
  [a-url]
  (js/Promise
    (fn [rsov rjct]
      (GET a-url
        {:handler
          (fn [resp]
            (-> resp
                hc/parse
                hc/as-hickory
                rsov))
         :error-handler rjct}))))

akiroz06:08:56

not tested btw

pawel.kapala11:08:58

Could anyone give me a hint how to nail issue which manifests itself with following error:

cljs.user> (require 'react-bootstrap-typeahead)
----  Exception    ----

      java.lang.RuntimeException : INTERNAL COMPILER ERROR.
Please report this problem.
...
(Full java stack trace follows) FYI: I’m experimenting with :npm-deps {:react-bootstrap-typeahead "2.0.0-alpha.3" :install-deps true with figwheel (`0.15.2-SNAPSHOT`)

pawel.kapala11:08:50

Any tips welcome, thanks!

dnolen11:08:52

@pawel.kapala looks like a Closure Compiler problem

pawel.kapala11:08:39

@dnolen yep, NPE I guess:

null
  Node(NAME animationEnd): /tmp/example/node_modules/dom-helpers/transition/properties.js:17:4
    animationEnd = void 0;
  Parent(VAR): /tmp/example/node_modules/dom-helpers/transition/properties.js:15:0
var prefix = void 0,

  java.lang.NullPointerException : 

----  Exception Stack Trace  ----

java.lang.NullPointerException: null
 at com.google.javascript.rhino.Node.replaceWith (Node.java:872)
    com.google.javascript.jscomp.ProcessCommonJSModules$RewriteModule.updateNameReference (ProcessCommonJSModules.java:1075)
    com.google.javascript.jscomp.ProcessCommonJSModules$RewriteModule.maybeUpdateName (ProcessCommonJSModules.java:954)
    com.google.javascript.jscomp.ProcessCommonJSModules$RewriteModule.visit (ProcessCommonJSModules.java:712)

pawel.kapala11:08:13

I’d have to try to isolate it and report it https://github.com/google/closure-library, right?

dnolen11:08:06

@pawel.kapala Closure Complier, not library

pawel.kapala11:08:32

duh 🙂 thanks!

lsenta12:08:03

On top of my issue with the DCE https://clojurians.slack.com/archives/C03S1L9DN/p1501573388897284?thread_ts=1501519537.283529&amp;cid=C03S1L9DN I'm seeing this in my output js:

ReferenceError: $cljs$core$MultiFn$$ is not defined
(opti :advanced with pretty-print and pseudo-names, else it's a random symbol .dd or something) And indeed, the code use the variable without initialising it before:
$cljs$core$MultiFn$$.prototype.$cljs$core$IMultiFn$_add_method$arity$3$ = ....
Seem's to be in the core, is there anything I can do to find the cause for the issue?

dnolen12:08:54

@lsenta sorry I don’t have time to look at this, I’ve already said that I don’t think your approach is going to be fruitful

dnolen12:08:20

trying to do your own DCE seems ineffective to me - Closure’s DCE works

dnolen12:08:32

all of Google major JS properties leverage it

dnolen12:08:01

so whatever conclusions you may be arriving at about DCE I would not put a much stake in it yet

dnolen12:08:11

as I said yesterday

dnolen12:08:19

DCE won’t work if there are side-effects

dnolen12:08:28

multimethods are one of those cases

lsenta12:08:31

Hey David, this is super confusing, could you at least open the file and let me know what's not done in the clojurescript way?

lsenta12:08:09

you seem to say my approach is broken, I redid all my code using the default, dumb goog-define, I really don't see what's "my" in this

dnolen12:08:20

exporting will pin everything in the call graph

dnolen12:08:15

DCE is whole program optimization, Google will crawl everything to determine dependencies at the level of values

dnolen12:08:37

if you export, then it will determine all values that your exported thing depends on

dnolen13:08:01

side note: this stuff is pretty well covered in Google Closure documentation, and it’s pretty easy to find more details on the Closure Compiler mailing list, the O’Reilly book is also a great resource on what expectations you should have

dnolen13:08:20

@lsenta I also see your misunderstanding here

dnolen13:08:36

DCE doesn’t work inside fns like you expect

dnolen13:08:42

only at the fn level

lsenta13:08:31

Does that explain why the DCE works in one case, bot=001 and not when its bot=004

dnolen13:08:58

DCE simply does not eliminate at the level of fn contents

dnolen13:08:04

either a fn is used or it isn’t

dnolen13:08:14

if it’s used it’s assumed anything it calls is needed

lsenta13:08:27

the cond is using a goog-define with "identical?"

lsenta13:08:40

which gets optimized / inlined in the output js

lsenta13:08:48

so the result js knows that a single module is used

lsenta13:08:04

and in one case, the optimization works, only bot004 is present in the output

dnolen13:08:22

anyways I really don’t have time to work through DCE with you 🙂

lsenta13:08:23

but in the other case, both bot are present, as if the DCE doesn't handle inner nodes

dnolen13:08:37

you can easily ask the exact same questions on the Google Closure compiler list 🙂

lsenta13:08:44

I understand and thank for trying to make this more clear

lsenta13:08:53

I'm still very frustrated by the impression that one switch-case is optimized and not the other is a bug. And I don't see how any of your answers adress this

dnolen13:08:26

there’s no way to answer that without looking at a lot more of your code

lsenta13:08:26

I mean (if true a b), b is eliminated, (if false a b) a is not eliminated

dnolen13:08:38

but trust me something is wrong somewhere without a doubt

dnolen13:08:45

there’s a small chance you have found a bug

lsenta13:08:46

I'm telling you, my code is almost empty, there's like 50 loc of cljc

dnolen13:08:51

I’ve spent weeks on this stuff 🙂

dnolen13:08:15

this is why (js/console.log "Hello world") is just a couple of K under advanced compilation

lsenta13:08:28

and I trust you write deterministic code 😉

dnolen13:08:31

this is why code motion works - you have to be very very careful if you want something specific to happen

lsenta13:08:07

David, is there anyone else that'd have time to read these 50 lines of cljc and at least check that the bug is in my code?

dnolen13:08:24

@lsenta a better use of your time is to just write the same thing in JS and see what happens

dnolen13:08:29

then I don’t have explain anything 🙂

dnolen13:08:04

then you also have a example which you can ask about on the Closure mailing list if something seems wrong

lsenta13:08:09

that's a fair point, will you review the js and the demo repo if I find something doesn't match?

dnolen13:08:23

figure out what’s different

dnolen13:08:07

if I was you however I would not spend any more time on this - I would just use the provided :modules code splitting feature and spent my time on more interesting stuff

dnolen13:08:25

parse times for 100K LOCs of JS is measured in milliseconds

lsenta13:08:27

I am using modules...

thheller13:08:46

@lsenta I think you should look into :modules more and the new cljs.loader maybe

dnolen13:08:05

if you’re not seeing real performance issues, what’s the point of this exercise?

thheller13:08:32

and change your configuration in that the catalyst.js does not require the bots but the bots register themselves on load

thheller13:08:49

then you can control which bots get loaded by configuration

thheller13:08:00

:modules already solve exactly what you are trying to do if I read everything correctly

thheller13:08:01

instead of trying to figure out why code doesn’t get DCE’d you should probably focus on not feeding the code into closure in the first place

thheller13:08:44

If I had to guess why your code doesn’t get remove its the concat in 004

thheller13:08:55

closure does not understand lazy seqs so won’t remove them

deadghost14:08:38

basic question: how do I turn a hashmap into a prettified string?

hlolli14:08:36

(doseq [namespace '(project.a project.b project.c)]
  (require `'~namespace)
  ;; (require namespace)
  )
Is there any way to require a namespace from a list of namespaces. I always get
Arguments to require must be quoted. Offending spec

moxaj14:08:01

@U0CAUAKCG you can't require dynamically in clojurescript

hlolli15:08:42

ok, makes sense (in terms of what I tried), thanks!

hlolli15:08:24

For my usecase I can just access the list like this

(keys (get-in @cljs.env/*compiler*
                [:cljs.analyzer/namespaces
                 'somename.space
                 :requires]))

deadghost14:08:06

@pesterhazy doesn't seem to actually prettify it

pesterhazy14:08:40

(with-out-str (clojure.pprint/pprint {:foo :bar}))

deadghost14:08:45

@pesterhazy nope still not seeing any pretty printing

deadghost14:08:55

even when adjusting it to cljs.pprint

chris_19:08:17

@akiroz Thank you! -- I tried out httpurr and cljs-http, and I think the underlying issue is that I don't understand asynchronous programming in the slightest! So I'm going to work on that.

martinklepsch21:08:10

@pawel.kapala if you end up creating a minimal closure repro I’d be interested in adding that somewhere to the CLJSJS docs, it’s something more people will bump into with the new module processing stuff

pawel.kapala21:08:13

@martinklepsch I've spent some time minimizing dom-helpers, so I might have something for you, prolly tomorrow.

martinklepsch21:08:47

awesome, I wish much success 🙂 😛

juhoteperi21:08:19

Var from combined var statement being exported

juhoteperi21:08:37

var prefix = void 0,
    transitionEnd = void 0,
    animationEnd = void 0;
exports.transitionEnd = transitionEnd;

juhoteperi21:08:52

This is fixed in Closure-compiler master, but combined var statements are broken in another way currently

qqq22:08:35

with cljs, can I do anything besides :optimizations none :parallel-build true to speed up my builds ?

dnolen22:08:31

@qqq don’t blow away :output-dir unless you really need to

qqq22:08:12

@dnolen : sorry, I don't understand what :output-dir has to do with this

qqq22:08:37

oh, you mean incrementla compiles?

qqq23:08:43

does :optimizations :none even call google-closure ? if not, is all the time clojure code doing "cljs -> js" conversion ? if it does call google-closure, is there a split of cljs -> js time spent and calling closure on js time spent ?