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
Rohan Nicholls 2020-08-13T15:58:56.333500Z

Hi 👋. I’m trying to understand the concepts in re-frame. So.. An event fx is a specialised version of an fx, and is treated more like a reducer elsewhere?

1👋
p-himik 2020-08-13T16:22:56.333600Z

What do you mean by "event fx"?

Rohan Nicholls 2020-08-13T16:25:20.336900Z

I’m reading through the docs and you have reg-event-fx and it seems to be a narrower version of event-fx. I was thinking it was specialised and was more like a reducer, but having read further I’m not so sure now.

p-himik 2020-08-13T16:32:09.337300Z

I still don't understand what you mean by "event-fx". There are events, effects, and coeffects. Events you use in calls to dispatch, then at some point in time re-frame handles those events by calling event handlers that you have registered with the reg-event-* functions. Different functions except different kinds of event handlers. Effects are similar, but you can only trigger them in an event handler, and they're the only place where you should employ side effects. Coeffects are inputs to event handlers.

Rohan Nicholls 2020-08-13T16:40:02.343200Z

Oh. Thanks. I saw code with ‘reg-event-fx’ and later with ‘reg-fx’ and was trying to understand the difference between the two. So the event one is just registering the event and by what it is returning ie. which keys in the map, those functions registered with that key with ‘reg-fx’ are then called?

Rohan Nicholls 2020-08-13T16:40:32.344200Z

Btw. Thanks 🙏 very much for your help with my confusion.

p-himik 2020-08-13T16:41:58.344400Z

Something like that, yes. > I saw code with ‘reg-event-fx’ and later with ‘reg-fx’ and was trying to understand the difference between the two. Don't look at the example before you read the documentation. The documentation contains everything and is very well written. No problem.

Rohan Nicholls 2020-08-13T16:46:28.350500Z

That example was in the docs. I was just trying to sort it out in my head. I had it backward until you clarified the situation. I’m continuing with the docs, which are excellent. I’m going to finish them off before messing with examples. It is a very nice system from what I’ve seen so far. Just needs some mental adjustments. I was trying to translate it into redux/ngrx terms but that landed me on a slippery slope.

1👍
gekkostate 2020-08-13T17:22:58.355100Z

Hi all, quick question. I have two values in my db which I would like to track i.e., if those values change then I would like to dispatch an event which flips a boolean. I was thinking of creating an event-fx which has an interceptor which provides the subscription (like what the https://day8.github.io/re-frame/FAQs/UseASubscriptionInAnEventHandler/ suggest) and then if the subscription is fired then so will my event and I can flip the boolean. Is this a good way to go about this sort of thing? Thanks for your time!

lilactown 2020-08-13T17:36:44.355700Z

@gekkostate when you say “flip a boolean” do you mean change another value in the app-db?

gekkostate 2020-08-13T17:39:16.356Z

Yes exactly.

lilactown 2020-08-13T17:55:12.356600Z

rather than store it in the app-db, could you create a subscription that uses those two values?

lilactown 2020-08-13T17:56:01.357500Z

ex.:

(rf/reg-sub
  ::some-boolean
  (fn [{:keys [val-a val-b]}]
    ;; compute the boolean based on `val-a` and `val-b`
    ))

lilactown 2020-08-13T17:56:22.358Z

that’s how you should typically create derived values from the app-db

lilactown 2020-08-13T17:57:25.358900Z

there are certain cases where this doesn’t quite work, e.g. if you need to know when a value changes, not what the value is

lilactown 2020-08-13T17:58:05.359800Z

by your verbiage it sounds like you need that, just laying out the typical case because it’s easy to colloquially use “change” and “based on some value” in the same way

gekkostate 2020-08-13T18:28:15.359900Z

This is the case we have. 😛 So, we have some auto save functionality and we want to indicate to the user that the content has been saved. So, we have a marker which shows “Saved” when the save request is successful. However, when the user makes the changes (and they can make changes in multiple places e.g., textview, input fields) we want to show “Unsaved” marker. Right now the marker is governed by a boolean. So, if we can know when some of these values have changed then we can flip the boolean to false and wait for the auto save to kick in which will make it true.