re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
orlandow 2021-03-27T17:05:25.036700Z

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-himik 2021-03-27T17:07:04.037Z

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

1
orlandow 2021-03-27T17:09:37.037300Z

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-himik 2021-03-27T17:10:51.037900Z

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?

orlandow 2021-03-27T17:11:03.038200Z

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

orlandow 2021-03-27T17:11:09.038400Z

and the values are not mine

orlandow 2021-03-27T17:11:35.038600Z

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

orlandow 2021-03-27T17:12:06.038800Z

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

orlandow 2021-03-27T17:13:18.039Z

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

orlandow 2021-03-27T17:14:36.039200Z

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

orlandow 2021-03-27T17:15:28.039400Z

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-himik 2021-03-27T17:15:30.039600Z

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

1
orlandow 2021-03-27T17:18:53.039900Z

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 🙂