Fork me on GitHub
#re-frame
<
2021-12-27
>
Noah Bogart21:12:07

If I want the value of :db in an effect handler (`reg-fx`), I need to pass it into the effect value of the event handler, right? so {:do-stuff [:interesting-stuff 42 db]} instead of just {:do-stuff [:interesting-stuff 42]}?

Noah Bogart22:12:46

I could write an after interceptor to do this automatically

Noah Bogart22:12:27

Hmm now that I think about it more, my need stems from not using subscriptions, so I will have to think on this further

Noah Bogart22:12:09

I could deref app-db directly in the handler

p-himik22:12:22

re-frame.db/app-db is not a public API. What exactly do you plan to do with app-db in the effect handler?

Noah Bogart22:12:37

I'm currently sending updates of all “lobbies” (this is a game server) to all connected players after certain player actions (such as creating a new lobby or leaving a lobby). In the client, this would be handled by subscriptions but server side, I have to do the querying and diff payload creation by hand

p-himik23:12:18

I'm not sure how this answers my question to be honest. My question is technical rather than domain-specific. So you might be e.g. getting a single key out of the db or maybe somehow doing something to the whole db. I'm now especially confused by the mention of a backend - do you use re-frame on a backend?

Noah Bogart23:12:30

Yeah, I mentioned yesterday I'm experimenting with it as a server side workflow because I really like how it forces writing pure functions while allowing for injecting impure data and performing side effects. My particular use case is well suited because I'm only using It for web socket messages related to this part of the application: lobbies and active game state.

Noah Bogart23:12:53

To your technical question, I'm relying on two keys from app-db, :lobbies and :users. At the moment, broadcasting updates is simple: any change sends the full list of lobbies to all connected users. I don’t worry about creating diffs or subsets in the interest of simple code, especially given that I know I won’t ever have more than 100 users at a time. (It’s an unpopular game lol)

p-himik23:12:21

Ah, right. I'm kinda all over the place here so don't recall all the specifics often. In that case, I would just pass those two values alone to the effect - lobbies and users. No need to pass the whole db.

👍 1
Noah Bogart23:12:25

No worries, I shouldn't assume everyone remembers all of my details lol. Thanks for the tip, I’ll give that a try!

👍 1
emccue00:12:43

if this is a side project and it doesn’t matter, give a shot to lamdera

emccue00:12:52

totally different language and paradigm

emccue00:12:08

but it makes server code very straight forward

Noah Bogart01:12:04

Interesting! I'm bound to clojure for both emotional and code size reasons but I have been looking for a reason to check out elm