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
Markus Str 2020-11-01T17:42:19.276300Z

has anybody used reframe successfully inside a chrome extension? (one source of persistent truth between background and content-script)

Ivan Fedorov 2020-11-01T18:15:33.277500Z

Hey, how do you manage queried data in re-frame? I mean, the data that you query from the server, based on route and other primary state parts. Can you use subscriptions to calculate the required data? Example: I’m on a page /notes. I would like to have a sub :sub/required-entities which could calculate the entities I need. I would deref it once and then query the required notes and put them into the app-db. Then I would deref the sub second time but now it will return an empty set. Generally: Subs are what I would call derived state, and the app-db is primary state. I’m using subs almost exclusively for UI, but it would cool to use them for server queries as well. And are there any other side effects apart from circular state dependency?

Ivan Fedorov 2020-11-02T11:59:04.280400Z

Thanks! @p-himik

uosl 2020-11-06T11:03:47.287600Z

It sounds to me like what you want is load-on-mount or rather, load-on-sub? It's possible to do, but re-frame encourages you to be more low-level and load (query the server) the data manually by dispatching an event before or when you'll need the data. https://day8.github.io/re-frame/FAQs/LoadOnMount/

uosl 2020-11-06T11:04:40.287900Z

You might get closer to your ideal by dispatching on route change, which with reitit frontend you can do using the start function of the controller.

Ivan Fedorov 2020-11-06T12:54:21.288400Z

@regen hey, thanks for the input! That’s what I do, actually. My case is about converting window.scrollY into time offset and building the UI for that or querying the server with new date boundaries. App demo here: https://lightpad.ai/w/timeflow/page/timeflow ATM I have one dispatch call from one sub computation function. When you scroll past certain amount of dates – an event will be dispatched to apply new date boundaries to the db. Otherwise, I would need to store a lot more state in the app-db and I fear performance degradation here.

Ivan Fedorov 2020-11-06T12:58:09.288700Z

Again, while it look like anti-pattern to me, I think this can work, when all measures are taken to prevent circular computation.

p-himik 2020-11-01T18:19:02.277700Z

The question is too vague. I have event handlers that pull the data and eventually put it into the app-db. There are also subs that query the data. > I’m afraid of circular locks in this case. Exactly what locks are you talking about?

kenny 2020-11-01T18:42:17.278600Z

I’m not super familiar but pretty sure that’s not possible because those are entirely separate processes.

kenny 2020-11-01T18:42:33.279200Z

You’d need to serialize and de-serialize all data.

👍 1
Ivan Fedorov 2020-11-01T18:56:20.279500Z

@p-himik thanks for the reply, I’ve updated the question

Ivan Fedorov 2020-11-01T18:56:55.279700Z

@p-himik do you use subs to calculate what you will query from the remote API?

p-himik 2020-11-01T19:02:19.279900Z

I don't use subs for that. But it's possible: https://day8.github.io/re-frame/Subscribing-To-External-Data/