Fork me on GitHub
#re-frame
<
2022-05-03
>
ag01:05:29

Does anyone know a good sample app that uses http://Cypress.io for testing? I'm struggling with overriding http-xhrio fx behavior. Would be nice if I could borrow some ideas from an existing project.

olaf12:05:27

Hey everyone, I want to ask what is the best pattern to adopt in re-frame. I've a list of items, one of them has to be set :selected . I create a new reg-event-db named :select-item that receive an id. Two possible ways: 1. update-in the item that has :id equals to id , obtaining the list of items via subscribe 2. create a new property like :selected-item and don't modify the original list of items The solution that came to my mind is the first one. But reading here is WRONG. What's your solution? https://github.com/day8/re-frame/blob/master/docs/FAQs/UseASubscriptionInAnEventHandler.md

lassemaatta12:05:04

I'm not certain this is always the best way, but I always implement your 2. solution: use a different property for different things. For example, keep any data received from the backend as-is and don't modify them locally. You can always merge and fuse data in subscriptions, if needed.

p-himik13:05:41

^ this. Alternatively, you can modify the original data but I'd use a key with some "private" namespace. Not just :selected but ::selected in some specific namespace that's relevant to that functionality and isn't represented in the actual data. Also yeah, don't use subscribe in your event handlers. Instead, move the data extraction/processing functionality into a set of common functions and use those functions inside both the subs and the event handlers.

olaf13:05:44

Thanks to both! Makes sense to keep the original data and I understood why re-frame force you to use subscriptions to compute derived data. And good trick the "namespace". I found an article about it.