This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-27
Channels
- # announcements (3)
- # aws (7)
- # babashka (11)
- # beginners (96)
- # clojure (15)
- # clojure-europe (9)
- # clojure-germany (2)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-poland (3)
- # clojure-serbia (1)
- # clojurescript (13)
- # depstar (28)
- # fulcro (34)
- # graalvm (5)
- # honeysql (5)
- # malli (11)
- # off-topic (27)
- # pathom (9)
- # polylith (74)
- # portal (10)
- # re-frame (13)
- # releases (1)
- # ring (8)
- # shadow-cljs (3)
- # spacemacs (10)
- # tools-deps (8)
Hi,
Is it possible to trigger a subscription when a value’s metadata changes?
I have a component that renders a value that contains some metadata that I need to decide how to render it, there is an event that changes the metadata after it’s rendered and it’s not triggering a re-render (I’m guessing since the value didn’t change (= new old)
)
Is it possible to listen to metadata changes?
I'm pretty sure there's no way.
My advice would be to avoid using metadata at all costs - it's a recipe for disaster.
If you really need to use it, just create a layer-3 sub that extracts the metadata and creates a regular value from it, something like {:metadata (meta x), :value x}
.
Thanks for the quick reply
but those subs (layer-3) inputs wouldn’t change, my event is only doing vary-meta
and replacing the old with the new value, it’s not being detected as a change
Ah, sorry, of course - you're right.
Do you really have to do very-meta
? Why not just put the metadata as a regular value into the app-db?
I’m trying to make it work with metadata because 90% of the components/events don’t care about it
creating a new model, something like: {:meta m, :value v}
makes it harder for the rest 90% of the components and events
and these “elements” are everywhere in the app, it’s not as easy as just adding a couple of keys to the app-db, I need the metadata to be near the elements
I was thinking that maybe I could use a low level function that could trigger the signals manually, because the “patching with meta” function is in one place
> 90% of the components/events don’t care about it
In almost any non-trivial application that will be the case as well.
If you can't wrap then complement with an extra collection. So app-db would have e.g. a vector of values coming from the API and a separate vector with the same number of items with what you use for metadata.
Alternatively, stop using direct map accessors like get
, update
, etc, and work with the values through some functions in a single common namespace that are used by both subs and events.
Then you will be able to unwrap that map and wrap it back in any way you want, without having to change the whole app later on.