This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-08
Channels
- # babashka (18)
- # beginners (35)
- # biff (15)
- # cider (24)
- # clj-commons (26)
- # clj-kondo (12)
- # clojure (18)
- # clojure-austin (1)
- # clojure-dev (2)
- # clojure-europe (15)
- # clojure-losangeles (1)
- # clojure-nl (1)
- # clojure-norway (88)
- # clojure-seattle (2)
- # clojure-spec (14)
- # clojure-uk (27)
- # clojuredesign-podcast (5)
- # clojurescript (25)
- # cursive (3)
- # datahike (26)
- # datalevin (13)
- # datomic (39)
- # etaoin (19)
- # events (1)
- # fulcro (12)
- # graphql (1)
- # hyperfiddle (40)
- # introduce-yourself (3)
- # joyride (8)
- # lsp (53)
- # missionary (7)
- # nyc (1)
- # off-topic (31)
- # overtone (10)
- # reitit (6)
- # shadow-cljs (9)
- # slack-help (9)
- # thejaloniki (1)
- # tools-deps (12)
Hi folks!
I found an unexpected behavior, so I decided to ask: is there a rationale on why js/debugger
generates debugger$
on the final Javascript file? I saw that I can use (js-debugger)
to generate the same thing, just want to understand why, for example, js/undefined
is a possibility but js/debugger
isn't
some names are protected as to avoid clashes with JS reserved names such as debugger
mostly so that a namespace like (ns debugger.foo)
or (let [debugger foo] ...)
don't blow up
Hello everyone ๐โบ๏ธ If I have a map with some state (atom):
(def a {:a (atom 1)})
and I'd like to clone that map:
(def b (clone a))
and have b to have its own state (i.e clone the atom as well)
are there any clever techniques for that?if this is static map then I would write some strait forward function to recreate the same structure:
(def a {:a (atom 1)})
(defn clone-a [a]
{:a (atom (get a :a))})
(def b (clone-a a))
if the map is arbitrary then clojure.walk/pre-walk should help.
(defn clone-walk [a]
(walk/prewalk
(fn [x]
(if (instance? clojure.lang.Atom x)
(atom @x)
x))
a))
If you have control over a
, I'd create a factory function instead:
(defn make-state []
{:a (atom 1)})
(def a (make-state))
(def b (make-state))
also it is good to remember that in general state is better controlled when it is in one atomic data structure. So instead of having a map with multiple atoms inside I would make one atom with all the details in it.
hey, i'm a complete beginner to js and front end web development, I'm trying to learn cljs and most guides try to teach cljs with the assumption that the student knows how js scripts work. So some code example they show contains things like
(ns ^:figwheel-hooks learn-cljs.weather
(:require
[goog.dom :as gdom]
[reagent.core :as reagent :refer [atom]]
[reagent.dom :as rdom]))
(defn get-app-element []
(gdom/getElement "app"))
(defn hello-world []
[:div
[:h1 (:text @app-state)]])
(defn mount [el]
(rdom/render [hello-world] el))
(defn mount-app-element []
(when-let [el (get-app-element)]
(mount el)))
and I can't understand the example because idk what they meant by (gdom/getElement "app")
(I understand that we are trying to grab the element with the id
"class" after someone told me) but what does that mean when they use it
here (rdom/render [hello-world] el)
what does rdom/render
really do?
What i'm ultimately trying to ask is, is there any guide that teaches you
clojurescript as your first entry to web programming. Ik I should learn
reagent and re-frame instead of directly manipulating elements using
cljs but i thought learning the basics will be deeply helpful. Please
point me in the right directionI have never seen a good guide that wouldn't result in more questions and frustrations. I'd recommend learning the basics of JS first, along with the most frequently used parts of the browser API. It'll take you a few days since you're a beginner, maybe a week. Then learn the basics of React, build a couple of simple projects. Probably another week. In just two weeks, you'll have a very strong foundation to build upon, not something shaky that some "all in one" guide can offer.
i see, many people ik said they only learned clojurescript and reagent, by learning these they naturally learned js and react. That's why I was asking for clojurescript based solutions. Thanks for your answer
You can definitely start right on CLJS and Reagent, picking up React and JS along the way. That is how I approach things. And while I am struggling, I always wish I was an experienced React/JS or whatever dev, because I know everything would be a lot easier with that context.
Currently I am enjoying #C03A6GE8D32 and Flutter, never having touched Flutter or Dart, and it is deja vu all over again. But at one point I broke down and worked through a pure Dart/Flutter tutorial. It may have been the best two hours of this learning curve.
Looking at your specific question, I have to go with @U2FRKM4TW on this one. That rdom/render
works because the DOM is mutable, and we can go find the DOM element "app" -- prolly an empty DIV -- and pour our whole app into it. And "we" in this case is the Reagent internals, which know how to convert Hiccup to proper DOM and splice new DOM into existing DOM.
No chance we can as noobs work that out just by eyeballing the code. Hth!
ps. Kudos for wanting to pull back the curtain on every little detail. Those of us successful at diving into deep ends skip the details as long as possible. We lack patience, and pay for that with more headscratching than is necessary.
wow, i'm glad i could find someone who exactly understood my pain points, yes this is exactly the issue i was going through. I would have looked into Clojure dart if it was much more mature, i'm trying to get a job in Clojure with everything i learned. So if i learn i'll have to learn everything from start if they're using reagent and most importantly i heard Clojure dart had to deal with oop side of things i really dislike dealing with the boiler plate of the oop. Thanks for your reply it was helpful <3
"i heard Clojure dart had to deal with oop side of things i really dislike dealing with the boiler plate of the oop."
I hear you, @U03VC5CUADR. But the #clojuredart lads have done a brilliant job with type inference (and more) so we almost never have to specify types.
As for boilerplate, I honestly do not know how native Dart/Flutter programmers deal with that. But there is cljd.flutter/widget
and my https://github.com/kennytilton/flutter-mx library, both of which eliminate 95% of the noise. This displays three sliders for volume, pitch, and rate to control a flutter text-to-speech player:
(defn equalizer []
(container {:margin (m/EdgeInsets.only .bottom 24)}
(column
(mapv (fn [[label & opnds]]
(container {:margin (m/EdgeInsets.only .right 24 .bottom 0)}
(fx/row {:mainAxisAlignment m/MainAxisAlignment.end
:mainAxisSize m/MainAxisSize.min}
(container {:width 64
:alignment m/Alignment.topRight}
(m/Text label))
(apply property-slider label opnds))))
equalizer-sliders))))
Flutter itself is what they call "aggressive composition", the container
widget being a bit of an exception, but, eg, to disable a widget:
(ignore-pointer {:ignoring (cF (= :off (app-fts-status)))}
(opacity {:opacity (cF (if (= :off (app-fts-status))
0.15 1.0))}
...the button itself....))
Note two whole widgets, one to dim the button, the other to actually ignore clicks. This granularity is a great idea, I think, and CLJ macrology makes it painless.
I do not know if there are any jobs anywhere these days, but I think CLJD/Flutter has a lot of potential for that, esp since Dart/Flutter is so horrid. ๐i see, that sounds really interesting, i'll definitely look into clojure dart. I worked professionally in flutter dart front end for nearly two months so i kinda know a bit of how to navigate around dart oop system and use flutter's widget. If the clojure dart removes so much boilerplate the experience will be way better than flutter dart i guess. but i plan to still learn reagent and re-frame. i think this will give me so much surface area of options. I think it'll be a valuable experience but i'll definitely look into clojure dart after i make 2 or 3 web apps in reagent/re-frame
Jobs-wise I think re-frame/reagent is def the way to go. But please follow #C03A6GE8D32, you might be able to help with Flutter Qs! ๐
Hi everyone ๐ I'm trying to prevent clojure from turning arraymaps with more than 8 keys to hashmaps:
(set! (.-HASHMAP-THRESHOLD PersistentArrayMap) 12)
this doesn't seem to work.
does anyone knows what am I missing?
And, is there a difference between map literals and programmatically generated maps (conj\assoc...)?I think youโre pretty likely to run into trouble messing with that. We do not provide knobs for this at all.
So is it impossible? I was sure I was able to tinker with this a while back and it worked :thinking_face:
Why do you want to?
We use arraymap in a way that relies on the literal key order
You might want to look at the ordered-map library