Fork me on GitHub

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


and the values are not mine


I mean, they are an external model coming from an api


so I can’t “patch” them with an extra field or something


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.


yeah, that was an alternative I was trying to avoid, I was happy with the resulting code from the components and the events but couldn’t make everything work, I guess I’ll have to go that route thanks for the suggestion 🙂