Fork me on GitHub
Bardia Pourvakil04:04:44

@potetm I get this error when I tried your solution: `Error in phase :compilation dot prop access with args {:form (. el -style "backgroundColor")} ExceptionInfo: dot prop access with args`


It seems that you changed -backgroundColor to "backgroundColor". Why?

Bardia Pourvakil06:04:22

Figured it out but that was just the error not what I typed in

Bardia Pourvakil06:04:51

Have you guys gotten an error like this before?


i believe that looks confusing due to 0-indexing


(nth [:a] 1)
Execution error (Error) at (<cljs repl>:1).
No item 1 in vector of length 1


but (nth [:a] 0) correctly returns :a

Bardia Pourvakil06:04:08

Ah so I’m just going past the end of my vector hmm thanks I’ll debug it

Bardia Pourvakil06:04:43

My codes up at if it will help, it’s quite short


I'm working my way through some reitit clojurescript template, and I see there sometimes #'some-var is used instead of some-var for no obvious reason, can someone please explain why? For example, there's this fragment: (def router (reitit/router [["/" {:name :home :view #'home-page}] ...where #'home-page is just some normally defn -ed Hiccup func, which is later passed to another Hiccup component via some obvious re-frame machinery, and then rendered there. When I replace #'home-page with home-page , nothing seems to break, I can't see any changes in behavior. What is the point of this #' here?


I think this is to make repl-driven development easier. Without the #’ the var will be interned, so you have to reload not just the home-page var after a change, but also the router.


yea I was trying to remember what it was, as I investigated this at one time too


I think that indeed was it


@mkvlr thanks, that must be it. Not sure I fully get it, though. Do you mean that w/o #' the "old" value of the var can get "cached" in the router, and with #' the lookup is forced on each use -- something like that?


@jason358 yes, pretty much. Without it it the router will just the the value of the var, and not perform the var lookup at runtime

👍 8

For the same reason that if you did something like

(def my-age 20)
(def my-info {:name "Cameron" :age my-age})
(def my-age 30)
my-info 's :age would just be 20. That value would originally come from my-age, but would have no real connection to it afterwards, and when I change my-age , my-info would still just have an age of 20. But with reitit, by storing the var my-age instead, it has a reference of sorts to its value that it can use to get the current value at any point in time, rather than hardcoding the value home-page evaluated to when the router was defined

👍 4

Yeah, I think I get the gist of it. It shouldn't apply though to e.g. situations where the dependent var and the "source" file are defined in the same file that gets reloaded (and not via e.g. defonce ), because either both get reloaded or none. And yeah, REPL is another matter, because more fine-grained changes are possible.


How do I embed pure js code in cljs? Say I have some pure js code like maybe:

dimensions = {
        max_height : 800,
        max_width  : 600,
        width  : 800, // this will change
        height : 600, // this will change
        largest_property : function () {
            return this.height > this.width ? "height" : "width";
        read_dimensions : function (img) {
            this.width = img.width;
            this.height = img.height;
            return this;
        scaling_factor : function (original, computed) {
            return computed / original;
        scale_to_fit : function () {
            var x_factor = this.scaling_factor(this.width,  this.max_width),
                y_factor = this.scaling_factor(this.height, this.max_height),

                largest_factor = Math.min(x_factor, y_factor);

            this.width  *= largest_factor;
            this.height *= largest_factor;


canvas.width  = dimensions.width;
canvas.height = dimensions.height;
context.drawImage(img, 0, 0, dimensions.width, dimensions.height);
and I want to use this code in clojurescript with `(.drawImage context img 0 0 (.-width dimensions) (.-height dimensions))` without having to rewrite the entire thing in cljs. How can I do that?

Jacob O'Bryant03:04:20

One way is you could just stick it in an external js file and load that before loading the js file that contains your compiled cljs. Not sure if that's the best way or not. You may have to add an externs file/do something to make sure the closure compiler doesn't bork your interop code.


With shadow CLJS and the default optimization profile, it just works.