Fork me on GitHub
#re-frame
<
2021-03-27
>
orlandow17:03:25

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?

p-himik17:03:04

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}.

3
orlandow17:03:37

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

p-himik17:03:51

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?

orlandow17:03:03

I’m trying to make it work with metadata because 90% of the components/events don’t care about it

orlandow17:03:09

and the values are not mine

orlandow17:03:35

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

orlandow17:03:06

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

orlandow17:03:18

creating a new model, something like: {:meta m, :value v} makes it harder for the rest 90% of the components and events

orlandow17:03:36

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

orlandow17:03:28

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

p-himik17:03:30

> 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.

3
orlandow17:03:53

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 🙂