This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-22
Channels
- # babashka (106)
- # beginners (29)
- # biff (29)
- # calva (9)
- # cider (6)
- # clj-kondo (24)
- # clojure (40)
- # clojure-europe (94)
- # clojure-japan (1)
- # clojure-nl (1)
- # clojure-norway (45)
- # clojure-uk (13)
- # clojuredesign-podcast (5)
- # clojurescript (12)
- # clr (4)
- # community-development (2)
- # conjure (13)
- # cryogen (4)
- # cursive (4)
- # deps-new (1)
- # fulcro (18)
- # hugsql (2)
- # hyperfiddle (67)
- # jobs (1)
- # malli (47)
- # meander (2)
- # missionary (34)
- # off-topic (1)
- # podcasts-discuss (1)
- # polylith (24)
- # reagent (19)
- # reitit (9)
- # sci (7)
- # shadow-cljs (3)
- # testing (28)
- # tools-deps (1)
- # xtdb (9)
I've run into some issues with defrecord during interactive development.
When reloading my file the defrecord
runs twice and all previous instances won't hash/equal to equal new instances, so things disappear from maps and all sort of issues you can imagine.
Here's an example:
(defrecord Pos [col line])
(def mypos (->Pos 3 4))
(defrecord Pos [col line])
(def mypos2 (->Pos 3 4))
(= mypos mypos2)
false
=>(= mypos mypos)
true
This also happen when I run clj
on version 1.11.1 locally but doesn't happen on http://tryclojure.org
Is this working as intended?Yes, a known issue with redefining records and other things to which you might hold a reference somewhere.
so they are just bad to use with a repl and browser hot-reload or is there some other technique a-la defonce
?
With hot code reload in a browser it should work just fine. At least, AFAICT it has always been working for me.
The technique that I prefer on the CLJ side is to never reload things by hand. Instead, I rely on the "reloaded" workflow where I make a set of changes, send a specific keystroke, and my REPL reloads all the necessary namespaces while tracking all of the dependencies. For that, I use clojure.tools.namespace.repl
and Integrant (helps with stateful things, and there are alternatives).
I came across this using hot-reload with re-frame/shadowcljs.
Saving the ns
with defrecord
makes all the keys in app-db
useless
All the keys? That sounds bizarre given that usually the keys there are keywords or other scalars.
all the keys of that type
Hmm. Yeah, I have never seen that probably only because I almost never use records.
But sounds logical. Code references should get refreshed by hot code reload, but data references cannot be when that data is in defonce
, just like re-frame.db/app-db
.
Came across this old thread, and thought I'd chime in. This technique won't work if you change an actual record's definition, but Potemkin's defrecord+
(and related macros) are designed for exactly this. They skip re-evaluation if the defrecord
's body is unchanged. Dunno about cljs tho.
Yeah, that's only for CLJ. And not necessary with a reloaded workflow. ;) With CLJS, I would simply avoid storing records altogether.
"Doctor, it hurts when I do that."
"Then stop doing that...forever."