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.
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.
@kimo741 A related thing - while looking around I noticed that flow/interceptor is included twice in the impl of reg-event-fx.
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
@p-himik shouldn't the have been addressed 🤔
Oh, right. You're dissocing the flow's output. Hmm
Yeah, I remove both the aggregated/massaged output and the source
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.
What might work in your case is to control the flow's :live? function.
Your flow could basically do :live? (fn [{:keys [E]}] (some? E))
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).
I've currently have :live? :E and the haven't worked, would some? make a difference?
no
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!
& you specified :live-inputs, right?
Yes
that does sound like a bug, then.
would you be willing to build a minimal repro? maybe from a fork of re-frame or re-frame-10x
I can fix that, hopefully tomorrow, ping you when it's done
cool.
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 ...}
Ah! Ofc, that's a good thing to test
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.