In this specific case, I might personally use something like:
(render-image (some-> product-image-list first deref))
...or maybe write a little function that does the above. Alternately, in
(render-image) you might start out with (if (nil? cursor) (default-image)
(code-to-render @cursor)). You'
Hi Tim,
Thanks for your feedback, I appreciate it! :)
Ye, I've been tempted and bitten by atoms-in-atoms before, and that's no
fun - My case here is slightly different though, I have a single atom and
construct cursors to paths within, which are swappable and deref'able like
normal atoms, but the
I've worked with a model much like this, and as an experience report: it
resulted in a lot of pain. Atoms inside atoms, or really more than one atom
for the entire state of your app results in to many sources of mutability.
On top of that, you have the problem of async updates: some part of your
st
Hi Sean,
Good point - as you have noticed, my use case is in ClojureScript - I'm
using reagent cursors (hence the deref) fairly heavily to chop my main atom
up and send only the relevant bits to components, but still allow them to
locally modify their state.
In my specific case, I do lookups for
Like Stuart, I don’t encounter atom-or-nil as a common pattern – could you
explain why you have functions that might return an atom or might return nil?
FYI, We have about 40,000 lines of Clojure at World Singles and just a handful
of atoms (and most of those are going away as we refactor the
Thanks Stuart,
Ah, yes - in my case I am using ClojureScript - I assumed it worked the
same in Clojure - oops!
Ok, I'll likely just step around it by making the functions returning (atom
nil) - but I assumed there would be reasoning behind the core deref not
nil-punning to nil? I'm keen to hear t
This approach would only work in ClojureScript, where IDeref is defined as
a Protocol. In Clojure(JVM), the core functions are defined in terms of
Java interfaces, which are not extensible to `nil`.
I don't find atom-or-nil to be a common value pattern. But if it's
something you encounter frequ