Fork me on GitHub
#clojurescript
<
2018-01-13
>
bfay03:01:30

So about the whole :refer :all is a bad practice and never will be implemented thing...

bfay03:01:14

I'm building a library for a pretty specific use case that's gonna have a lot of functions to import. Is there at least some kind of macro hack I can put together to import a bundle of functions in one go?

tagore04:01:39

@bfay This isn't just a Clojure(script) question or answer, but...

tagore04:01:09

I want to be able to see where names come from, in the file they are used in.

bfay04:01:03

I agree 99% of the time.

mikerod04:01:31

I have been using scope-capture in a cljs-repl via piggieback & figwheel - all newest versions and haven’t had any problems. Then suddenly today the cljs repl seems to not know how to analyze the sc.api/spy macro from scope-capture anymore. This is only in one project. However, I’ve made new projects to minimize it with the same compiler/figwheel settings and I get no problem. When in cljs-repl (via piggieback + figwheel)

cljs.user> (require 'sc.api)
nil

cljs.user> (sc.api/spy :foo)
---- Could not Analyze <cljs form> line:1 column:1 ----
at line 1 <cljs repl>

1 (sc.api/spy :test)
^---

---- Analysis Error ----

nil

mikerod04:01:48

I just am wondering if there is anything to do to help troubleshoot a case like this.

mikerod04:01:04

I’m even able to dig into the fn object some from the same REPL

cljs.user> sc.api/spy
#object[sc$api$spy]

(js-keys sc.api/spy)

#js ["cljs$core$IFn$_invoke$arity$2" "cljs$core$IFn$_invoke$arity$3" "cljs$core$IFn$_invoke$arity$4" "cljs$lang$maxFixedArity" "cljs$lang$macro"]


I can even call these functions and get back expected results.

mikerod04:01:21

So for some reason, it is just failing to analyze it as a macro. However, it seems like it is project-specific. I just don’t know what to tweak to try to dig out the issue

mikerod04:01:52

I think I need to do some work to get a hook into the analyzer around where it is failing to see what is going on. Seems pretty opaque though.

mikerod04:01:02

Oh, also, the figwheel popup in the browser says there is a NullPointerException

mikerod04:01:32

I think that it is coming out during the macro expansion during analysis. I wish there was a way to at least get a stack trace from the REPL when the analyzer fails like this though. Maybe there is…

carkh10:01:39

question : i have this dependency i installed with npm (it's lovefield)... It is a google library and was done according to the closure library way. I'm doing a nwjs application with it. As such, i'll just rely on the standard packaging for nwjs applications, so i do not want to append that library inside my js code when doing advanced compilation. But there is a provided lovefield.externs.js file in the node_modules/lovefield/dist directory. -Using lein, how would i go about notifying clojurescript that the externs file is right there ?

thheller15:01:55

@carkh the :externs compiler option should find it if you specify :externs ["node_modules/lovefield/dist/lovefield.externs.js"]

carkh17:01:48

@thheller I'll give this a try, thanks!

yogthos20:01:12

wrote a post about capturing ClojureScript errors on the server https://yogthos.net/posts/2018-01-12-ClojureScriptErrorPropagation.html

yogthos20:01:53

curious if anybody knows why using :npm-deps doesn't work with stacktrace-js source mapped stacktrace when using advanced compilation

Alex H21:01:18

(the deref should actually be a prop to another component, etc, but that's my minimal reproducer)

Alex H21:01:31

that's with reagent 0.7.0 and react 16.2.0

qqq21:01:53

what does :ref #(reset! ref %) mean ?

Alex H21:01:21

it's just setting the ref atom to the value passed to the ref function

qqq21:01:28

can you stick a js/console log there and see if it's auto calling itself ?

qqq21:01:50

seems like the two explainatinos are: 1. on-click is calling itself repeatedly OR 2. :ref is calling itself repeatedly and 2 seems more likely than 1

Alex H21:01:06

well, yea. nothing to do with on-click

Alex H21:01:15

it's the ref, which, when updated, causes a re-render

Alex H21:01:25

but there are some re-agent examples that do pretty much exactly that, and supposedly work

qqq21:01:36

we can debate this, or we can test it 🙂

Alex H21:01:37

which is why I'm asking how refs are supposed to work with reagent, for anyone who might have used them

Alex H21:01:51

there is nothing to debate, it's an open question.

Alex H21:01:09

I can remove the on-click and it works just fine, because it has absolutely nothing to do with it

qqq21:01:11

(fn [nv] (. js/console log "ref is looping") (reset! ref nv))

Alex H21:01:52

@qqq - I know it's because ref keeps changing. That's not the question. The question is about how it is supposed to work with reagent.

Alex H21:01:06

as I said, there are examples of that supposedly working.

qqq21:01:31

ah, sorry, I misread your question; I'll let someone more familiar with reagent handle this

ejelome21:01:53

(defn dropdown-menu [props & children]
  (let [open (r/atom false)
        ref (r/atom nil)
        handle-click (fn []
                       (swap! open not)
                       (. js/console log "State of ref atom: " @ref))
        handle-ref #(reset! ref %)]
    [:div
     [:button {:on-click handle-click
               :ref handle-ref}
      "Ho ho"]]))

ejelome21:01:15

my guess is because the line (let [_ (.log js/console "State of ref atom: " @ref)] is somehow executing during assignment, which triggers the component and causing it to keep on re-render.

ejelome21:01:58

one useful thing I learned is to declare all the definitions (`atom`s) and methods in the let block, this makes things easier to define and track. 🙂

Alex H21:01:05

I think you are on to something; just following the standard sort of React good practices to avoid unnecessary rerenders (pinning down the functions and avoiding new lambdas in the render function) avoids the re-mounting/updating of the component and avoids the continuous ref calls

ejelome21:01:48

The funny thing is, reagent doesn't really explicitly follow react (as far as my short experience with it), although ironically, it's a wrapper for it. But in any case, it worked and have fun digging deeper 😄