re-frame

valerauko 2023-12-04T09:41:37.224829Z

Are flows hard wired to app-db? Subscriptions can use alternative inputs (iirc there was one that used datascript as backend), and it feels weird that flows apparently can't (looking at resolve-inputs and run in flows.alpha)

p-himik 2023-12-04T09:48:09.675339Z

I'd say it's the other way around - it feels weird putting anything that doesn't originate from app-db as a subscription signal. It makes the state of the app fractured and negates all the advantages of having all the state at one place.

valerauko 2023-12-04T09:50:35.262569Z

In my case I'd want to use a reactive database (something that can notify changes) to store user data and the app-db to store ephemeral application state

p-himik 2023-12-04T09:52:52.585829Z

I understand the need, my point is that it doesn't sit well with the overall re-frame design and its justifications. Local Storage is somewhat similar to a reactive database. When using it, I basically copy the values that I need into app-db when they change and then use them from there. Perhaps it's something you can employ as well.

šŸ‘ 1
Kimo 2023-12-04T11:55:00.404109Z

> Are flows hard wired to app-db? Yes :)

valerauko 2023-12-04T11:55:59.943979Z

is that an intentional choice, and if so what's the reasoning?

DrLjótsson 2023-12-04T19:55:59.259779Z

šŸ‘‹ , I’ve looked into flow and I think it may solve some problems that I’ve been struggling with. I have a couple of thoughts, questions. 1. The :live? seems to couple presentation with the flow, since the flow needs to know what tab is showing. Would it not be possible to track references to the flow? 2. I have thought a lot about a machinery to handle time consuming and cascading recalculations of data as result of changes in app-db. I’ve followed the example in the re-frame docs of an event that runs and then triggers a new event to continue the calculation, handing back control to the browser. Would it be possible to implement something similar i flows?

Kimo 2023-12-04T20:03:51.103439Z

what is presentation?

DrLjótsson 2023-12-04T20:11:55.619589Z

Maybe not a good term… in contrast to regular subscription, that are automatically ā€œfreedā€ when no one is subscribing to them, the flows need to know what components that depend on the so they can be cleaned up when the component (the tab in the example) is no longer showing. Of course the current tab is also stored in app-db, but it seems to me to be another concern.

Kimo 2023-12-04T20:19:49.739249Z

I wouldn't say a flow needs to know about any components. What we're imagining is a system where a dataflow lives or dies based on explicit predicates. You can ideally do all your essential calculations with flows. Then, your view logic might use those predicates to mount or unmount, but that's more incidental. It's your decision to couple views and flows, whereas with subscriptions, they were always coupled, and you didn't really have a choice.

Kimo 2023-12-04T20:21:54.593569Z

It does make me wonder what a reference-counted flow might look like.

Kimo 2023-12-04T20:29:41.316249Z

You might be interested in the subscription alpha, too - it offers another approach to lifecycle definition. We don't have an official doc, but I wrote up some https://github.com/day8/re-frame/issues/680#issuecomment-1676487563 and some https://github.com/day8/re-frame/blob/master/test/re_frame/subs/alpha_test.cljc

DrLjótsson 2023-12-04T20:32:26.060839Z

On second thought, I think that this ā€œcouplingā€ may be unavoidable. If I have a regular subscription to the value in :path, it’s not simple for the flow mechanism to understand that the flow should be cleaned up when that component unmounts.

Kimo 2023-12-04T20:32:32.592229Z

> Would it be possible to implement something similar i flows? As for this, not sure. Do you have a link to the specific tutorial?

DrLjótsson 2023-12-04T20:37:10.020499Z

https://day8.github.io/re-frame/Solve-the-CPU-hog-problem/

DrLjótsson 2023-12-04T20:42:05.493119Z

I’ve made a very bespoke solution that runs takes a vector of values, a reducing function, and a path for the final storage. The machinery feeds reducer each element in the vector for about 6 ms, yields back to the browser, and the runs it again, etc., until the vector is empty, and then the value is stored in the path.

šŸ¤” 1
Kimo 2023-12-04T21:02:20.737709Z

interesting, I haven't tried that pattern before

Kimo 2023-12-04T21:06:43.073059Z

I guess we both see how you can set up a flow to do a certain calculation. And technically it could stop after some time. I think a flow could have an input path that's the same as its output path - maybe that would come in handy for iterative calculations. A flow can't declare effects, the way an event handler can, which might make it hard to keep the iteration going.

Kimo 2023-12-04T21:07:23.152259Z

no :dispatch effect after the flow runs

Kimo 2023-12-04T21:08:46.822789Z

so far I see how a flow might add complication to solve the problem, but I don't see a clear way for a flow to simplify things

šŸ‘ 1
DrLjótsson 2023-12-04T21:22:38.836439Z

Makes sense. I just wanted to check if this triggered any ideas 😊

Kimo 2023-12-04T21:54:12.057659Z

might be worth looking at https://github.com/day8/re-frame-async-flow-fx, too

DrLjótsson 2023-12-05T07:49:57.856529Z

That solves another problem that I’ve another bespoke solution for 😃