Fork me on GitHub
#clojurescript
<
2017-06-26
>
mobileink04:06:03

cljs.repl> *cljs-verbose*
WARNING: Use of undeclared Var cljs.repl/*cljs-verbose* at line 1 <cljs repl>

mobileink04:06:42

But it’s right there in the source and the docs. ???

mobileink04:06:11

trying to get :repl-verbose going, using boot-cljs-repl, with no luck. anybody know how?

krukow09:06:24

Hey, I’m in the process of setting up a development environment for a Chrome extension based on the sample https://github.com/binaryage/chromex-sample — the project uses figwheel which is great, but is configured to not setup a ClojureScript repl… I’m wondering if there is a way to get the REPL working too, or there is some reason why the REPL can’t be supported in that environment…

pesterhazy09:06:10

@mobileink 👍 for the interop guide! let us know when you open the PR to clojurescript-site, so we can comment

pesterhazy09:06:15

Question about figwheel: I'm noticing that I need to Shift-Reload in Chrome a lot because I'm seeing stale builds. Anyone seen caching issues like that?

robert-stuttaford09:06:51

@pesterhazy i get that because non-compilation bugs screw either the react state or my app state up 🙈

robert-stuttaford09:06:10

happens very often when refactoring. i guess autosave in Emacs is partly at fault

pesterhazy09:06:29

hm. that sounds like a different issue

pesterhazy09:06:41

I get the problem even if I restart lein figwheel

robert-stuttaford09:06:03

i do occasionally have to (reset-autobuilds) in the FW repl

pesterhazy09:06:20

ah interesting

pesterhazy09:06:35

but I think the problem is with browser caches, not Figwheel's cache

pesterhazy09:06:42

I see "200 OK (from disk cache)" in Chrome network tab

pesterhazy09:06:51

not sure why Chrome thinks it can safely cache those files

darwin09:06:14

@krukow it should work with figwheel REPL except for :content-script build-id

krukow09:06:26

darwin: when I enable that it hangs waiting for connection, let me reproduce

krukow09:06:52

@darwin “Prompt will show when Figwheel connects to your application”

krukow11:06:02

@darwin thanks for the update… I’m continuing down this path. I’ve enabled the REPL using :repl true and I get

krukow11:06:04

Launching ClojureScript REPL for build: background
...
Prompt will show when Figwheel connects to your application

krukow11:06:39

and it never connects, even if I open the background.htmlpage

darwin11:06:01

ok, let me try it here

krukow11:06:12

Thanks! I appreciate it

darwin11:06:28

ah, I see where is the problem

darwin11:06:53

if you run goog.require("figwheel.connect.build_background") manually in background context (or popup context) it starts working

krukow11:06:43

what exactly does that do?

darwin11:06:10

if you look at resources/unpacked/compiled/main.js, you will see document.write("<script>if (typeof goog != \"undefined\") { goog.require(\"figwheel.connect.build_background\"); }</script>"); which was generated by :figwheel true I assume

krukow11:06:50

I do see that

krukow11:06:54

let me try

darwin11:06:03

but for chrome extension we don’t use main.js directly, we hand-roll it via resources/unpacked/background.js

krukow11:06:25

so add it to the background.js in dev/unpacked

darwin11:06:35

you got it!

krukow11:06:51

let me try§!

darwin11:06:17

unpacked is dev-only, so it won’t affect release which is a single js file only

krukow11:06:57

right got it… Thanks a lot!

krukow11:06:09

Do you have time for another question?

darwin11:06:43

not sure what I was thinking 🙂

krukow11:06:35

guess your weren’t using it

krukow11:06:41

are you an emacs user?

darwin11:06:02

I use Cursive

darwin11:06:07

I’m sorry

krukow11:06:57

ah, maybe I should try that. I’m trying to connect emacs CIDER to the ClojureScript repl started with lein fig

krukow11:06:12

thanks for the help so far, I’ll update and close the public github issue

darwin11:06:55

I’m going to commit a fix

darwin11:06:09

I now understand, figwheel renamed the namespaces

darwin11:06:31

instead of figwheel.connect.background it is newly figwheel.connect.build_background

darwin11:06:47

I was just fixing errors without deeper understanding what was causing them

darwin09:06:04

I tend to use Figwheel only for hot-reloading, disable its REPL in favor of using Dirac REPL. That is why it was left disabled there.

rauh09:06:12

@pesterhazy You disable Chrome caching in the Dev console

pesterhazy09:06:38

@rauh, is that a question or an assertion?

krukow09:06:54

@darwin just posted here too: https://github.com/binaryage/chromex-sample/issues/3 so we can share a solution more broadly

rauh09:06:22

It's in the "network" tab

krukow09:06:36

@darwin thanks for the reference - infact maybe the diract REPL is what I want, let me pursue this and get back! Thanks I appreciate the quick response

pesterhazy09:06:18

@rauh, right, I know I can disable it if I want, but regular "reload" should work without manual intervention

darwin09:06:01

@krukow good luck and let me know if you hit some roadblocks, I could help probably, also feel free to modernize chromex-sample, it’s been a while since I last reviewed it

rauh09:06:12

@pesterhazy It should work on reloading since figwheel will add a parameter to the URL. But not on F5, then it's up to chrome if it wants to load from memory or fresh.

krukow09:06:31

@darwin thanks I appreciate it, I’ll keep exploring

pesterhazy10:06:16

@rauh, reloading via the "Reload" button (Cmd-R) is a normal part of everyone's dev workflow, so if that serves stale files, it's an issue I think

darwin10:06:17

@krukow now I recall, it wasn’t because Dirac, it was because I was using lein-cooper (see the “devel” lein alias) which does not work well with interactive prompts

darwin10:06:05

@krukow if you run lein fig directly (along with other cooper tasks in other terminal sessions), you should be able to get figwheel REPL working from command-line

rauh10:06:17

@pesterhazy I don't think it serves stale files. It's just that Chrome goes for the (old) cache. You can right click on the reload button in Chrome to see what options you have. A hard reload will avoid the cache.

rauh10:06:44

Another option is to file an issue with fighweel so that it serves the right headers to avoid any caching.

pesterhazy10:06:00

I didn't phrase that well - you're right that figwheel doesn't serve stale files

rauh10:06:27

It used to be that Chrome didn't use the cache when the Dev Console was open. But that seemed to have changed at some point. Now you have to explicitly disable it.

pesterhazy10:06:42

I think Chrome'e behavior has changed even with the Dev Console closed, caching scripts more aggressively even if no caching headers are returned.

pesterhazy10:06:48

But I can't prove that 🙂

dnolen12:06:51

@mobileink you need to provide that option :repl-verbose true when configuring the REPL, not sure how boot-cljs-repl does that

juhoteperi12:06:30

@mobileink That option should be passed to piggieback/cljs-repl here: https://github.com/adzerk-oss/boot-cljs-repl/blob/master/src/adzerk/boot_cljs_repl.clj#L128, currently not supported

juhoteperi13:06:14

I might have a snapshot with support ready in few minutes, I noticed a new piggieback version which might fix problems why I haven't used cljs repl

bbqbaron13:06:25

so considerate

dnolen13:06:21

this would imply that Google needs our favorite PL to build their JS applications

robert-stuttaford13:06:06

that is hilarious

joshkh15:06:28

so some mild frustration with secretary and pushy... what's the "correct" way to navigate? should i continue to use [:a {:href "#/my/route"}] or should all of my links now dispatch an event using (set-token! history "/my/route")?

mobileink16:06:21

thanks to @juhoteperi I can set :repl-verbose now with boot-cljs-repl. However I get the following output; is there any way to get just the meat, i.e. ((1) + (2))?

cljs.user> (+ 1 2)
cljs.core._STAR_print_namespace_maps_STAR_ = true
(function (){try{return cljs.core.pr_str((function (){var ret__19869__auto__ = ((1) + (2));
cljs.core._STAR_3 = cljs.core._STAR_2;

cljs.core._STAR_2 = cljs.core._STAR_1;

cljs.core._STAR_1 = ret__19869__auto__;

return ret__19869__auto__;
})());
}catch (e46877){var e__19870__auto__ = e46877;
cljs.core._STAR_e = e__19870__auto__;

throw e__19870__auto__;
}})()
3

yedi16:06:39

hey all, whats the current story on importing npm dependencies via clojurescript?

yedi16:06:58

but from what I've been reading there are some issues with it

juhoteperi16:06:39

@mobileink You should probably try this without boot-cljs-repl/piggieback/weasel/cider-nrepl etc. with just bare Cljs repl to see if this is inference from tooling or from Cljs compiler: https://clojurescript.org/reference/repl#using-the-rhino-environment

noisesmith16:06:17

juhoteperi: @mobileink: there’s no “interference” here, in order to run the repl you need to assign *1, *2, *3, *e and that’s the code you need to emit to make sure those are assigned.

juhoteperi16:06:10

If those are supposed to be printed, the example at Cljs site is a bit misleading: https://clojurescript.org/reference/repl-options#repl-verbose

noisesmith16:06:07

that might be the case - my point was that in order to do what a repl is supposed to do in a clojure implementation, it needs to set those bindings, so it’s not something added by tooling, it’s fundamental repl stuff

mobileink17:06:54

@U051SS2EU assign howso? my repl-fu doesn’t have a whole lot of fu, I’m afraid.

noisesmith17:06:30

the repl guarantees that *1 will be the result of the last expression in the repl, that *2 will be the second last, etc. and that *e will be the last uncaught exception

user=> (doc *1)
-------------------------
clojure.core/*1
  bound in a repl thread to the most recent value printed
nil

noisesmith17:06:40

it’s part of clojure.core

mobileink17:06:32

when you say “you need to assign *1” etc. - ?

noisesmith17:06:01

the docs for *1 and *e etc. describe this behavior, it’s part of what defines clojure

mobileink17:06:03

you mean “that has to happen”, so it’s normal output?

noisesmith17:06:42

I mean that defining those things is correct behavior for a clojure repl, so I would not expect code that assigns them to come from anything other than the core language

noisesmith17:06:50

they aren’t added by tooling

mobileink17:06:28

gotcha, that’s just the way the repl works.

noisesmith17:06:28

whether that’s exposed in the generated code you see while interacting with a repl is implementation details I think

noisesmith17:06:39

(and I’d agree that they are just noise unless you are debugging the repl mechanisms themselves, but I don’t think our debug levels are fine grained enough to make that distinction inside them?)

mobileink16:06:09

@juhoteperi thanks, good point

dnolen16:06:28

@yedi nothing significant has changed recently - it’s still for adventurous users

dnolen16:06:50

there’s some stuff queued up for a future ClojureScript releases that will make it better gradually

yedi16:06:20

do you have an alternative method you'd recommend

yedi16:06:48

i've been able to get the method described here working: http://blob.tomerweller.com/reagent-import-react-components-from-npm

yedi16:06:56

but it feels a lil unwieldy

dnolen16:06:09

foreign deps and/or CLJSJS for simple stuff, if more complex package your deps with webpack to produce a single foreign import

dnolen16:06:58

@yedi those are your options

dnolen16:06:05

all of them have tradeoffs as will :npm-deps even when enhanced and matured

yedi16:06:40

alright, thanks man

julianwegkamp17:06:16

I have a question about not using clj->js like @dnolen said a couple of days ago...

julianwegkamp17:06:23

I mainly use clj->js for converting dom attribute maps I build in om.next components. I use clojure functions to build the map (nice) and convert it just before calling a om.dom function (mainly in the om.dom/x invocation itself).

julianwegkamp17:06:29

Since the map is very small and rendering (hopefully) doesn't occur often, performance issues shouldn't be a problem.

julianwegkamp17:06:34

However, I am wondering since david talks about maybe deprecating clj->js what is best way to build these js objects...

dnolen17:06:15

@julianwegkamp in your case you are probably safe because the keys in props are owned by you

dnolen17:06:22

but that’s not often the case

dnolen17:06:29

and it’s actually js->clj that’s the problem for that scenario

dnolen17:06:52

fwiw in my own om stuff I just use #js I don’t find it cumbersome

alice17:06:23

I hate to interrupt -- but if you're the real @dnolen I've watched so many of your talks and respect you & your work bigtime! You're walking inspiration.

dnolen17:06:20

@alice the one and only 😉

julianwegkamp17:06:29

@dnolen thx. Do you use goog.object to build/make changes to a js object or are there ways I'm not aware of?

julianwegkamp17:06:08

@alice I agree completely!

dnolen17:06:18

yes goog.object

dnolen17:06:44

but to be completely honest I almost always just build literals and don’t do much more

alice17:06:59

Don't wanna gush in public too much, but you're probably really responsible for all of my recent pursuits and my decision to dedicate myself to clojure lol

dnolen17:06:34

@alice thanks for saying so! Clojure is fun 🙂

julianwegkamp17:06:59

@dnolen I'm looking into how I can use goog.object in the same way I use the standard clojure functions (mainly updating values by adding to className and setting defaults) but out of curiosity: what would be the problem js->clj in my scenario?

dnolen17:06:23

@julianwegkamp if you’re using js->clj and you don’t have externs for something then you may see very strange problems under advanced compilation

dnolen17:06:57

i.e. Closure renames some ISeq protocol access to ve and some JS object accidentally has a property call ve

julianwegkamp17:06:56

ah, ok. For a moment I forgot about advanced compilation 😄

julianwegkamp17:06:25

Thx for explaining. I will do some more testing with #js and try to figure out the best way to use it

krukow18:06:46

I've read about ClojureScript, figwheel, but actually experiencing browser connected REPL with Emacs CIDER while writing a Chrome plugin is just... Wow! @darwin

crioux19:06:24

I'm developing a ClojureScript library intended to be required and used by NodeJS users writing JavaScript. I'm able to require the library fine, and the main function runs but the result when I execute lib = require('my-lib'); is an empty object, but I want to expose a more useful interface to node users. Googling seems to only return pages about using Node libs from ClojureScript. I'm sure there are existing repos that implement this, but I don't know their names, can anyone point me at one? Thanks in advance. 🙂

spieden19:06:22

@krubar my reaction was similar =) i had both content and background scripts in mine. did the (minimal) background ones in straight js but now can’t remember why…

crioux19:06:50

Seems I should have searched here, my question was answered a few days ago: https://github.com/thheller/shadow-cljs/wiki/ClojureScript-for-node.js-libraries Thanks again!

thheller19:06:07

@crioux please note that this only works with shadow-cljs. the other build tools don’t support this feature. feel free to ask questions if you have any, docs are in rough shape still.

crioux19:06:14

Thanks! I'm currently working on my shadow-cljs.edn file, I have a pretty simple build but I'll let you know if I have any questions.

sh3rawi20:06:37

@crioux i was searching for an answer for this last couple of days as well, didnt come across this! Thanks for that, but what i found was a somewhat manual thing, refer to https://github.com/tonsky/datascript

sh3rawi20:06:28

He concats a prefix and a suffix to the compiled js file, while annotating all exported functions with ^:export inside the cljs files

puzzler23:06:22

In Clojurescript, js's undefined is considered false-y, right?

anmonteiro23:06:31

@puzzler yeah. in Lumo:

Lumo 1.5.0
ClojureScript 1.9.542
Node.js v7.10.0
 Docs: (doc function-name-here)
       (find-doc "part-of-name-here")
 Source: (source function-name-here)
 Exit: Control+D or :cljs/quit or exit

cljs.user=> (if js/undefined 1 2)
2

anmonteiro23:06:20

it’s actually the same as nil 🙂

cljs.user=> (nil? js/undefined)
true

puzzler23:06:37

Great, thanks. I didn't realize I could get at undefined with js/undefined, so wasn't sure offhand how to test it for myself. Good to know.

anmonteiro23:06:40

@puzzler I should be clear. js/undefined is not the same as nil, but it’s equal to nil

anmonteiro23:06:58

cljs.user=> (== nil (js* "null"))
true
cljs.user=> (== nil js/undefined)
false

darwin23:06:19

undefined != null is false (first condition)