Fork me on GitHub
#clojurescript
<
2017-07-31
>
chris_00:07:11

@akiroz When I try (:body response), I get nothing

chris_00:07:28

*printing that to the console prints nothing

akiroz00:07:27

does it print nil or not print anything at all?

chris_00:07:15

i.e. (.log js/console (str "Body Response: " (:body response))) prints Body Response: to console, and nothing else

akiroz00:07:50

use clojure's printing fns instead

chris_00:07:07

Ah, I can use that in the browser?

akiroz00:07:21

yep, just (prn response)

akiroz00:07:49

oh yeah, you need to set (enable-console-print!) first

chris_00:07:53

yeah that's the HTML stir I want

chris_00:07:17

(I am seeing the HTML str in the console now, after doing (prn "response was: " response))

chris_00:07:19

It seems that, using console-log or Clojure's prn, I can see (in the browser console) the html str I want

chris_00:07:53

But the response itself seems to be goog.net.XhrIo object

chris_00:07:46

And (:body response) evals to null

chris_00:07:14

getResponseBody and getResponseText appear to be methods of the goog.net.XhrIo's parent class, but calling them on response also just produces 'null'

mobileink01:07:21

all you polymer geeks who are dying to help out: see the stuff in index.html and src/shell (except the driver.js bit). driver in ES6, implementation delegated to clojurescript.

xanderseren01:07:56

👋 I'm setting up a simple form with reagent and I can't figure out how to correctly set a default-value on the input. The default-value comes from an api call whose results are eventually sent into this EntryEditor function. Any thoughts on how I can get this to work?

akiroz01:07:43

@chris_ care to share the code you're using to make the request?

xanderseren01:07:57

Got it! I found what I was looking for in the todomvc example for anyone interested: https://github.com/tastejs/todomvc/blob/gh-pages/examples/reagent/src/cljs/todomvc/components/todo_edit.cljs

anmonteiro02:07:21

@bensu I guess you might be missing :install-deps true in your compiler options

anmonteiro02:07:41

we ended up changing the default behavior last minute and the example should account for it, I’ll edit it

anmonteiro02:07:47

let me know if that doesn’t fix it

bensu02:07:47

Thanks!!!

bensu02:07:58

It worked. Do you mind if I correct the post?

bensu02:07:09

It took me 1 hour to ask the question 🙂

anmonteiro02:07:38

@bensu I submitted the PR above to correct the post

anmonteiro02:07:48

sorry for the waste of time

anmonteiro02:07:28

btw, we don’t install deps by default because of this reason: you may choose to install deps yourself (e.g. with yarn, and not even pass :npm-deps)

anmonteiro02:07:37

and we’ll know that you’re requiring a node module 🙂

anmonteiro02:07:04

as long as they’re installed before CLJS compilation begins, the compiler can figure it out

bensu02:07:02

no need to be sorry! this feature is great. thank you for your help

akiroz03:07:49

hey guys, I'm trying out the new :npm-deps and stumbled upon an java.lang.RuntimeException : INTERNAL COMPILER ERROR. at this JS code:

node_modules/dom-helpers/transition/properties.js:17:4
animationEnd = void 0;
node_modules/dom-helpers/transition/properties.js:15:0
var prefix = void 0,
Is this a bug within the closure compiler?

akiroz03:07:33

Stacktrace:

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)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:730)
    com.google.javascript.jscomp.NodeTraversal.traverseChildren (NodeTraversal.java:802)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:726)
    com.google.javascript.jscomp.NodeTraversal.traverseChildren (NodeTraversal.java:802)
    com.google.javascript.jscomp.NodeTraversal.handleScript (NodeTraversal.java:680)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:705)
    com.google.javascript.jscomp.NodeTraversal.traverse (NodeTraversal.java:307)
    com.google.javascript.jscomp.NodeTraversal.traverseEs6 (NodeTraversal.java:647)
    com.google.javascript.jscomp.ProcessCommonJSModules.process (ProcessCommonJSModules.java:134)
    com.google.javascript.jscomp.Compiler.processAMDAndCommonJSModules (Compiler.java:2106)
    com.google.javascript.jscomp.Compiler.parseInputs (Compiler.java:1792)
    com.google.javascript.jscomp.Compiler.parse (Compiler.java:1007)

anmonteiro03:07:04

will be in the next version of Closure which we’ll hopefully be able to squeeze into the next release of ClojureScript

akiroz03:07:39

@anmonteiro awesome, thanks! 🙂

curlyfry12:07:03

How do I require the spec.gen namespace in ClojureScript now that we have cljs.spec.alpha? I had [cljs.spec.impl.gen :as gen] earlier.

dnolen12:07:52

cljs.spec.gen.alpha

curlyfry12:07:05

Hmm, that's what I tried without success...

dnolen12:07:18

@curlyfry won’t work if you dont have test.check as a dep in your project

curlyfry12:07:41

@dnolen Sorry about that, I had something else wrong! I think I also got a bit confused by what has been fixed in a later cljs version than what I'm using: CLJS-2242: Lots of undeclared Var warns in cljs.spec.gen.alpha

curlyfry12:07:14

Can I safely use 1.9.854 btw? I saw it referenced as a 'release candidate'

dnolen12:07:31

yes - it should work, there are some minor things we need to fix, but I think no deal breakers

curlyfry12:07:04

Ok, thanks!

lsenta13:07:31

Hi there, following my questions of yesterday, I have a dozen definitions/modules, I load one during the macro expansion phase. I expect the output javascript to NOT include the other modules (compilation :advanced)

lsenta13:07:42

which is wrong apparently, am I missing something?

dnolen13:07:56

what you’re saying doesn’t really make sense to me

dnolen13:07:06

“load during macro expansion phase”, what does that mean?

lsenta13:07:46

@dnolen I have a macro that reads an env variable, and require the corresponding module

dnolen13:07:12

but there’s no such thing as requiring a module that way, I’m not sure how you tried to accomplish that

dnolen13:07:15

but it’s not recommended at all

dnolen13:07:40

I don’t know - but dynamic require is simply not possible

dnolen13:07:51

require must be top level only

dnolen13:07:59

and it must appear at the top of your source file only

dnolen14:07:35

if anything you’re trying doesn’t take these assumptions into account - it’s not going to work

lsenta14:07:32

I'm afraid we're not talking about the same thing

lsenta14:07:47

I rely on the fact that the macro expansion happens in clojure

dnolen14:07:52

macroexpansion doesn’t matter

lsenta14:07:54

so in "clojure mode" I read the env variable, require the module and load a variable from it, to produce a simple (def preloaded {:my-def [{:a 1} {:b 2} ...]})

dnolen14:07:18

if you mean you’re using the macro splice stuff in, then that’s a different thing

dnolen14:07:28

still I would rewind - it’s very hard for me to understand what you are trying to accomplish

lsenta14:07:39

I have a evaluator that process a bot definition and user input and produces an output

lsenta14:07:00

my evaluator AND the bot definitions (a dozen) are written in clojure

lsenta14:07:19

I compile this to js to use it in a google cloud function

lsenta14:07:57

I want to avoid loading a dozen definitions every time my cloud function starts. I'm hoping to get a quick win by just picking ONE definition at compile time, that'd produce a smaller js and I'd use it without changing the rest of my code.

lsenta14:07:21

So I try the macro route, since I know that's eval'd during the clojure phase, I wrote a macro that loads a module and pull a variable from it. Instead of loading 12 modules, I have a single (def preload {:bot-001 CONTENT-OF-MODULE-DEFINITION})

dnolen14:07:44

but why do you need to bother with all this? advanced compilation includes whole program tree shaking / dead code elimination

thheller15:07:03

@lsenta you are bitten by the fact that CLJS includes ALL files it found in your :source-paths in the :advanced compilation

thheller15:07:29

that is no longer true if you use :modules though which only includes what is reached by your :entries

thheller15:07:34

maybe it makes sense to make a :module per “bot”? not sure what you are building

lsenta15:07:55

I didn't know about this one, thanks! The clojure macro can use the env which is more handy for me

lsenta15:07:34

@dnolen that's what I'm trying to get, I load a single module so that dead code elimination gets rid of the unused 11 modules

lsenta15:07:13

For this I use an env variable to decide at compile time

lsenta15:07:23

but @thheller do you have a reference for this? it sounds like dead code elimination would work only for imported libraries then

lsenta16:07:59

Same issue with modules & closure defines, the cond over the goog-define value is optimized (I copied the example with identical? in https://cljs.github.io/api/cljs.core/goog-define)

lsenta16:07:56

but all the modules are included in the javascript output. Even the one that are never accessed.

dnolen16:07:16

@lsenta that will only happen if you have side effects in your leaf entries

dnolen16:07:37

if someone is never accessed it will be DCE’ed, if it’s not being DCE’ed something is wrong with the code

lsenta07:08:08

@dnolen My experiments show something different, I pushed a minimal repos that demonstrate the issue

lsenta07:08:18

It seems that only leave are DCE'ed, not internal nodes

wcohen17:07:38

Hi -- I’m trying to migrate from consuming an external bundle to consuming node_modules or :npm-deps directly, using cljs master and closure-compiler master. Files using require('assert') fail with JSC_JS_MODULE_LOAD_WARNING. Failed to load module "assert". Do I need to pass an option to clojurescript related to the node API? Alternatively, adding the commonjs assert package to package.json or :npm-deps doesn’t remove the error -- if using this package is the right solution, should I be adding something to my namespace as well?

anmonteiro17:07:05

@wcohen that needs more investigation, can you please open a JIRA ticket?

anmonteiro17:07:14

I think I know what’s wrong but need to have a more in-depth look later

wcohen17:07:21

Issue is here: https://dev.clojure.org/jira/browse/CLJS-2290. This is my first bug report, so please let me know if additional or different information would be useful

mikerod19:07:09

Using cljs :infer-externs true I get WARNING - name goog is not defined in the externs coming from the prefix goog.string; and some longer paths under goog.string there should be no reason to create externs for goog closure stuff, so this seems harmless. However, what is causing it? in v1.9.671 I tried searching and best I found was a similar question asked on slack quite a while back.

mikerod19:07:24

didn’t see it in jira, unless my searches are failing

mikerod19:07:05

oh, also I don’t believe I Have any sort of type hints involving goog.string

dnolen19:07:54

@mikerod not enough information to understand what you are saying - come up with something minimal and report an issue in JIRA

mikerod19:07:42

@dnolen yeah, not sure how to recreate it so was first checking if this is just a “known thing”. I’ll see about coming up with something that reproduces it

dnolen19:07:54

never heard of anything like that

mikerod19:07:39

ok, good to know

bfabry23:07:49

is there a clojurescript equivalent to alter-var-root? trying to figure how to get https://github.com/bhb/expound printer to be pervasic in a cljs repl

bfabry23:07:26

oh nvm, set! was working I was just being thrown by the return value function spraying js all over my repl 😆

bfabry23:07:30

any way to stop the repl from trying to print fns?