Fork me on GitHub
#re-frame
<
2020-08-20
>
Shako Farhad06:08:39

Hey guys. I have a question. If I want to dispatch an event as soon as there is a change to a specific value in my app-db, how should I do that? Can I dispatch events in reg-sub? Or do I put the dispatch in with the view like this: (do (dispatch event) [:div "hello"]) My backend is sending patch diffs of state through sse and I just merge them into my app-db. But certain keys in my db need to trigger an event. Any suggestions? :x

Lu09:08:39

Never dispatch in reg-sub or in the rendering function. What I would do is to check if the diffs contain the key that should trigger the event, and if so, you can dispatch from your event-fx like so:

{:db diffed-db
 :dispatch (when (:trigger diffed-db)
             [:event-to-dispatch])}

p-himik09:08:05

@shakof91 There's re-frame.core/on-changes interceptor that does what you want. Combined with somewhat recently introduced global interceptors, this should cover your need.

👆 6
Shako Farhad09:08:02

Thanks for the feedback guys. I appreciate it 🙂

Ramon Rios10:08:15

Folks, have you tried to dockerize a re-frame app? I'm kinda lost if a need to treat as a usual npm app or do i need something different

mikethompson10:08:45

For production, a re-frame app is going to end up being a .js file, plus some css files, etc.

mikethompson10:08:05

It is just a client side framework. So you will need a way to "serve" these files. Perhaps you use a two stage Docker file which first builds the production artifacts (js, css, html, etc) and then copies them into a nginx image?

mikethompson10:08:27

On the other hand, perhaps you are talking about dockerising the server side?

Ramon Rios10:08:54

On my case, i already have my backend dockerized

Ramon Rios10:08:41

In my head, pretty easy, just get the jar and execute it. But i never did something with .js files i and was looking at it now

mikethompson10:08:16

If you use the re-frame-template to create an application ... ... you can use the lein release command (see the README) which will build the production artifacts (in /resources)

mikethompson10:08:54

You then need to get them into a Docker image which will serve them

jmckitrick21:08:04

What’s the latest re-frame modal library these days?

jmckitrick21:08:13

I see re-frame-modal but it’s a few years old.

jmckitrick21:08:20

Unless that means it’s tried and true.

mikethompson23:08:33

@jmckitrick You don't need anything re-frame specific. You just need a Reagent component. Perhaps look at re-com or google for "Reagent Material UI" etc.