This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-12
Channels
- # announcements (1)
- # babashka (124)
- # beginners (98)
- # calva (54)
- # cider (32)
- # cljdoc (5)
- # cljs-dev (131)
- # cljsrn (1)
- # clojure (107)
- # clojure-australia (2)
- # clojure-europe (2)
- # clojure-losangeles (1)
- # clojure-norway (3)
- # clojure-uk (28)
- # clojurescript (21)
- # conjure (86)
- # core-async (7)
- # cursive (3)
- # datascript (5)
- # datomic (28)
- # defnpodcast (2)
- # devcards (1)
- # exercism (47)
- # fulcro (22)
- # graalvm (29)
- # graphql (1)
- # malli (5)
- # nrepl (31)
- # off-topic (111)
- # re-frame (23)
- # reitit (4)
- # spacemacs (6)
- # tools-deps (10)
- # tree-sitter (1)
- # xtdb (6)
@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`
Figured it out but that was just the error not what I typed in
Have you guys gotten an error like this before?
(nth [:a] 1)
Execution error (Error) at (<cljs repl>:1).
No item 1 in vector of length 1
Ah so I’m just going past the end of my vector hmm thanks I’ll debug it
My codes up at http://github.com/bardia95/sorting-visualizer 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.
@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
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 definedYeah, 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;
}
};
dimensions.read_dimensions(img).scale_to_fit();
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?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. https://shadow-cljs.github.io/docs/UsersGuide.html#js-deps