Fork me on GitHub
#re-frame
<
2018-11-02
>
nustiudinastea10:11:42

hi all, is it possible to trigger an event in re-frame, based on some particular data changing in the database?

valtteri11:11:05

What is changing the data?

nustiudinastea11:11:42

its another event, an http request

nustiudinastea11:11:32

that's how I do it now, I trigger an event once that http request finishes. But I think I would like to do it when the data changes, so I can disconnect the two

nustiudinastea11:11:37

http req success event (saves result + does some data manipulation in the app db). What I would like is to move the data manipulation in its own event if possible

nustiudinastea11:11:53

but its not clear to me if its the right approach or I should not go that way

valtteri11:11:55

You don’t need to manipulate db directly in http-req-success event. You can use reg-event-fx and return effects map

{:db your-updated-app-db
 :dispatch [::some-other-event]}

valtteri11:11:32

Where ::some-other-event can do the extra data manipulation

nustiudinastea11:11:58

that's true, and that's a reasonable approach. I was just wondering if its also reasonable to have events on data changes in an app db, or based on a subscription.

nustiudinastea11:11:22

But I suppose that's not possible at the moment and the bigger question for me, is if that would be a sensible model to have in re-frame.

nustiudinastea11:11:13

As far as I can see, anything could be an event, even a data change in the db. It should not be limited to actions triggered by a user or time

valtteri11:11:01

Something always causes the data change

nustiudinastea11:11:58

good point, so you could always bundle your events there :thinking_face:

nustiudinastea11:11:24

ok, I think what I want is not really needed. Thanks for your thoughts @valtteri

valtteri11:11:09

No problem. 🙂 Often when in doubt, it’s a good idea to revise re-frame docs. Much wisdom there.

👍 4
nustiudinastea11:11:22

yes, indeed. I keep forgetting some of the things, fight re-frame by doing a weird implementation and then go back to the docs only to re-learn a concept again

valtteri11:11:15

simple != easy 😉. I’m fighting with this constantly

👍 4