Fork me on GitHub
#re-frame
<
2023-02-08
>
Benjamin09:02:37

Hi do you know public examples of idiomatic re-frame?

joshcho14:02:17

I want to inject subscriptions in event handler, and I am wondering if this (https://github.com/den1k/re-frame-utils/blob/master/src/vimsical/re_frame/cofx/inject.cljc) is the right way to go about it. I have thought of an alternative where I take out the logic in subscriptions and put it somewhere else so that the event handler can use it (a function that takes in db and other inputs and outputs a value). But I figure that is probably not cache-friendly like how subscriptions are.

p-himik14:02:03

There's a third way, where you cache the value manually under some key in app-db. Global interceptors can help with that.

hifumi12322:02:53

Note that the subscription injector you’ve linked will also cache miss if you decide to use it. IIRC there is a chance of caching when a component is already deferring the sub

hifumi12322:02:51

There are two approaches I usually see: • if no components use the sub, bite the bullet and compute the sub — the db is always with you in an event handler • if a component uses the sub, find a way to pass the value into the event vector

2
joshcho09:02:26

Cache miss only if there are no components subscribing to it, right?

joshcho16:02:14

I am using this, and I am getting "Subscribe was called outside of a reactive context." warnings on js console. How do I remove this? (I have a vague sense I want to use meta for this, but not sure which)

joshcho16:02:24

Also, can you elaborate on using global interceptors for caching values? Would it be something like if values A or B changed, recompute C (which depends on A and B)?

p-himik17:02:36

Dunno about the warning, haven't looked into it. I know the reason for it but now how to suppress it. But people have asked this before, specifically in this context - maybe there's something in the issue tracker of that project or maybe you can find something in here. Regarding global interceptors - yes, exactly.

👍 2
joshcho20:02:58

Interceptors definitely make the implementation a lot simpler. Thanks

👍 2