This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-27
Channels
- # adventofcode (1)
- # announcements (16)
- # babashka (16)
- # beginners (59)
- # calva (13)
- # clj-kondo (7)
- # clj-on-windows (3)
- # cljdoc (5)
- # clojure (85)
- # clojure-dev (5)
- # clojure-europe (4)
- # clojured (3)
- # clojurescript (87)
- # cursive (12)
- # emacs (4)
- # fulcro (15)
- # gratitude (1)
- # introduce-yourself (4)
- # malli (7)
- # off-topic (5)
- # polylith (6)
- # re-frame (15)
- # reagent (2)
- # shadow-cljs (5)
- # tools-deps (6)
- # web-security (2)
- # xtdb (5)
I have two questions, but only one here (companion question is on #calva channel).
When I run clj -M --main cljs.main
, Clojure on the JVM creates a repl in a firefox browser instance, but does not present a repl prompt at the terminal. I mention this only to show the minimum necessary to get a browser repl loaded whether or not accessible.
Let's say I add sufficient options to get a repl prompt at the terminal and I can enter and evaluate forms from this prompt.
When I send say (+ 1 1) from the repl prompt, does it go to the JVM repl first and then get passed to the browser repl, or does it go direct to the browser repl?
Hey folks, I’m trying to run through figwheel
’s tutorial and get the following error when launching the lein app:
...
Retrieving rewrite-cljs/rewrite-cljs/0.4.3/rewrite-cljs-0.4.3.jar from clojars
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Syntax error compiling at (figwheel/main/logging.clj:170:14).
No such var: figwheel.core/inline-message-display-data
Someone else had this as well… but no reply. There are #figwheel-main and #figwheel channels… https://clojurians.slack.com/archives/CALJ3BFLP/p1603900336093300 I ran through https://figwheel.org/tutorial.html it and it worked without that syntax error on my mac.
In fact, could you take the time and setup a new repo from scratch to see if the error persists? That's at least how I would approach this.
@UPJP9G4G1 Actually this is literally just the following:
lein new app test
Then copying the project.clj
from the figwheel website verbatim:
(defproject example-project "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.9.0"]]
:profiles
{:dev
{:dependencies [[org.clojure/clojurescript "1.10.773"]
[com.bhauman/figwheel-main "0.2.15"]
;; optional but recommended
[com.bhauman/rebel-readline-cljs "0.1.4"]]}})
lein trampoline run -m figwheel.main
Dependencies are downloaded as normal and then boom:
There's a gist of the output for me
This happens on both Ubuntu and OSX for me
Any ideas?
what version of java are you on?
[kevin@linux ~/repos/figwheel]
$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
using an M1 macOS machineOk so, it appears it broke because I called my lein app figwheel
Created a new app called figwheel-test
and it worked :face_with_rolling_eyes:
I added the following in my deps.edn and it seems to work...
org.slf4j/slf4j-simple {:mvn/version "1.7.32"}
org.slf4j/slf4j-api {:mvn/version "1.7.32"}
Best of luck...Just curious how to work around this
hey all, strange error here with a node REPL… I have a data reader installed with the pair sicm/quaternion sicmutils.quaternion/parse-quaternion
. When I use it with #sicm/quaternion [1 2 3 4]
in Clojure no problem. in cljs, however, I see
sicmutils.complex> #sicm/quaternion [1 2 3 4]
Execution error (IllegalStateException) at clojure.tools.reader/read-tagged (reader.clj:855).
Attempting to call unbound fn: #'sicmutils.quaternion/parse-quaternion
even though the function is indeed bound:
sicmutils.complex> (sicmutils.quaternion/parse-quaternion [1 2 3 4])
(sicmutils.quaternion/make 1 2 3 4)
other data readers are working fine
something bigger and prject-specific must be weird, I will attack this from a few angles
very weird, I HAD required the sicmutils.quaternion
namespace where I was getting that error. but adding a require
for it to a different namespace fixed the issue
how to convert an char to a number in cljs?
(int \a) doesn’t seem to work?
Both (js/parseInt \a) and (js/parseInt “a”) give NaN
I’m trying to hash the users’ password and send that to the db like so:
(hash "kasjfl")
Is this the recommended way to hash passwords?Read the output of (doc hash)
and notice how it says "hash code". A hash code is not the same as a cryptographic hash/checksum that you need for password checking (assuming that's what the intended usage is).
In CLJ, one of the common libraries to use for that is https://github.com/funcool/buddy No clue whether something like that exists for CLJS but you can certainly find an NPM library for that or maybe use built-in JS API if there's support for cryptographic stuff.
I have a component like so:
[:> flabel/FloatLabel
{:label "Title"
:name "title"
:value @title}
[:> a/Form.Item
{:name "title"}
[:> a/Input
{:onChange #(reset! title (.-value (.-target %)))
:size "large"}]]]
FloatLabel is actually created in react:
export const FloatLabel = props => {
const [focus, setFocus] = useState(false);
const { children, label, value } = props;
var floatClass, focusClass, labelClass;
labelClass = "float-label";
focusClass = focus ? ` ${labelClass}--focused` : "";
floatClass = value ? ` ${labelClass}--floated` : "";
labelClass = labelClass.concat(focusClass, floatClass);
return (
<div
className="float-label-wrapper"
onBlur={() => setFocus(false)}
onFocus={() => setFocus(true)}
>
{children}
<label className={labelClass}>{label}</label>
</div>
);
};
but when I input something in the input, I see the cursor flickering, suggesting that the whole component is rerendering when I reset the value. Is there a way to fix this flickering?Hi! I have two concecutive (set!)
calls, but I don’t think they happen syncronously, is there a way to do that?
Example:
(set! (.-height (.-style el)) 0)
(set! (.-height (.-style el)) 400)
In this case, only the 0 ever gets set.In JS, the equivalent would be
el.style.height = 0:
el.style.height = 400;
And it would be synchronous, so 400 would be the value that gets set. But in CLJS apparently that’s not the case 😞here's an example I typed into http://app.klipse.tech
(def el #js {:style #js {:height nil}})
(set! (.-height (.-style el)) 0)
(set! (.-height (.-style el)) 400)
and the resulting JS:
cljs.user.el = ({"style": ({"height": null})});
cljs.user.el.style.height = (0);
cljs.user.el.style.height = (400);
there's nothing async happening here. it complies to essentially what you want the JS equivalent to be
so I would look for something else that might be causing your element's height to be 0
it sounds like there something else going on with your code than calling set!
twice in a row
:component-did-update
(fn []
(set! (.-height (.-style @ref*)) 0)
(set! (.-height (.-style @ref*)) (.-scrollHeight @ref*))
Essentially when a component updates, I set the height of a textarea to 0, and then to its scrollHeight (so that when text was deleted, the height would decrease, because otherwise scroll height remains large).:component-did-update
(fn []
(set! (.-height (.-style @ref*)) 0)
(set! (.-height (.-style @ref*)) (doto (.-scrollHeight @ref*) (prn))))
☝️:skin-tone-2: this prints 40
?the code you pasted is equivalent to:
ref.current.style.height = 0;
ref.current.style.height = ref.current.scrollHeight;
so I'm checking to see what the scrollHeight is after you set the height to 0, since that's what you're setting the height the second time
So Im growing the textarea automatically as you type text in the textarea right, but when you delete text, the scrollHeight doesnt go smaller, stays the same. So a way to trick it into “reflowing”, is to cause a re-paint, and so do that by setting the height to 0, then that re-calculated scrollheight, and then set the height to scrollheight.
Prints correct scrollHeight. First line of text is 64 for example, as it goes to second line it becomes 88, and so on, and so on.
I googled for "react textarea set height to scrollheight" and found this gist https://gist.github.com/sikanhe/015c606710dc656f0c40
the key lines are
const textarea = this.refs.textarea
textarea.style.height = textarea.scrollHeight + 'px'
I think if you try
:component-did-update
(fn []
(set! (.-height (.-style @ref*)) 0)
(set! (.-height (.-style @ref*)) (str (.-scrollHeight @ref*) "px")))
it will workI was so use to Reagent just adding pixels itself under the hood that I didnt even think about that
yeah React adds the px to styles passed in to elements, but as you say here we are going around both React and Reagent
Hey folks, curious if anyone saw my thread above, I still can't get figwheel to work :(
It works just fine for me -- I see the following after the downloads:
[Figwheel:WARNING] Attempting to dynamically add "target" to classpath!
[Figwheel:WARNING] Target directory "target" is not on the classpath
[Figwheel:WARNING] Please fix this by adding "target" to your classpath
I.E.
For Clojure CLI Tools in your deps.edn file:
ensure "target" is in your :paths key
For Leiningen in your project.clj:
add it to the :resource-paths key
[Figwheel] Compiling build figwheel-default-repl-build to "target/public/cljs-out/figwheel-default-repl-build-main.js"
[Figwheel] Successfully compiled build figwheel-default-repl-build to "target/public/cljs-out/figwheel-default-repl-build-main.js" in 12.285 seconds.
[Figwheel] Starting Server at
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
(figwheel.main/stop-builds id ...) ;; stops Figwheel autobuilder for ids
(figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
(figwheel.main/reset) ;; stops, cleans, reloads config, and starts autobuilder
(figwheel.main/build-once id ...) ;; builds source one time
(figwheel.main/clean id ...) ;; deletes compiled cljs target files
(figwheel.main/status) ;; displays current state of system
Figwheel REPL Controls:
(figwheel.repl/conns) ;; displays the current connections
(figwheel.repl/focus session-name) ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
Docs: (doc function-name-here)
Exit: :cljs/quit
Results: Stored in vars *1, *2, *3, *e holds last exception object
[Rebel readline] Type :repl/help for online help info
Opening URL
ClojureScript 1.10.773
cljs.user=>
That's on macOS. And my browser opens just fine. What is in your ~/.lein/profiles.clj
file? That's the biggest source of lein
-related bugs.The part that breaks is lein trampoline run -m figwheel.main
Ok, so it appears that it didn't work because I called my lein app figwheel