re-frame

jherrlin 2024-10-16T19:48:38.517429Z

Hi, I'm facing a problem Re-frame (1.4.3) flow where a flow is only executed once. In the web app I'm fetching data on Reitits :start controller and clean up the app-db with the :stop controller. In a view with tabs I re-fetch entity E over and over, a scenario like this: 1. Fetch entity E 2. Click on a new tab 3. Cleanup app-db, removing E from app-db (this removes both E and the aggregated value) 4. Re-fetching entity E I have a flow called E-for-rendering that massages E to make it easy to use in the views. The E-for-rendering flow works the first time I fetch E but after I cleaned the app-db and re-fetched the E-for-rendering flow is not executed executed, it's important to note the E hasn't changed on the server, so the E I fetched the first and the last time is equal. It looks to me like a cache problem, because if I add something unique, like :timestame (js/Date.) to E the flow executes every time.

Kimo 2024-10-16T19:54:58.476559Z

If the value of E is the same, then why do you need to run the flow again? That implies some state apart from E. Maybe the behavior that reacts to that other state could be extracted from your flow - possibly into a different flow.

p-himik 2024-10-16T19:56:22.741099Z

@kimo741 A related thing - while looking around I noticed that flow/interceptor is included twice in the impl of reg-event-fx.

✅ 1
jherrlin 2024-10-16T19:57:22.807569Z

E is not always the same, but when it is I've noticed that the flow is not executed and I get no data to the view

jherrlin 2024-10-16T19:57:58.142689Z

@p-himik shouldn't the have been addressed 🤔

Kimo 2024-10-16T19:58:27.668409Z

Oh, right. You're dissocing the flow's output. Hmm

jherrlin 2024-10-16T19:59:02.444649Z

Yeah, I remove both the aggregated/massaged output and the source

Kimo 2024-10-16T20:11:07.886839Z

We probably can't fix that at the library level. So far, it seems like users will have to touch a flow's output at their own risk.

Kimo 2024-10-16T20:11:46.204949Z

What might work in your case is to control the flow's :live? function.

Kimo 2024-10-16T20:13:45.037909Z

Your flow could basically do :live? (fn [{:keys [E]}] (some? E))

Kimo 2024-10-16T20:15:53.155009Z

Your fetch event could just dissoc E, and not touch the flow's output. Consequently, your flow would become dead (and dissoc its output, via the :cleanup function). Then when E reappears, your flow would come alive (running its :output function again).

jherrlin 2024-10-16T20:16:59.201259Z

I've currently have :live? :E and the haven't worked, would some? make a difference?

Kimo 2024-10-16T20:17:29.173989Z

no

jherrlin 2024-10-16T20:19:21.305719Z

I will try to find a ways around this and remove E and not the output value, it was just very convenient to dissoc everything I've stored under a qualified key. Thank you for the input!

Kimo 2024-10-16T20:19:28.352089Z

& you specified :live-inputs, right?

jherrlin 2024-10-16T20:19:35.504429Z

Yes

Kimo 2024-10-16T20:19:57.259379Z

that does sound like a bug, then.

Kimo 2024-10-16T20:20:20.367459Z

would you be willing to build a minimal repro? maybe from a fork of re-frame or re-frame-10x

jherrlin 2024-10-16T20:21:18.370999Z

I can fix that, hopefully tomorrow, ping you when it's done

Kimo 2024-10-16T20:21:46.408069Z

cool.

Kimo 2024-10-16T20:24:09.222579Z

the other thing that comes to mind is - you could register and deregister the flow. Basically your fetch event would have a :clear-flow {:id :E-for-rendering} effect, and your on-fetch-success would have :reg-flow {:id :E-for-rendering ...}

jherrlin 2024-10-16T20:25:22.572309Z

Ah! Ofc, that's a good thing to test

jherrlin 2024-10-16T21:13:43.646229Z

When I created a new project and tried to make a small example that shows the bug nothing worked, and I came to realize that I have a mix of re-frame.core/dispatch and re-frame.alpha/dispatch and I haven't set (rf/reg-global-interceptor re-frame.flow.alpha/interceptor). But when I added (rf/reg-global-interceptor re-frame.flow.alpha/interceptor) my flow started to work as expected.