Fork me on GitHub
#re-frame
<
2019-09-26
>
kenny16:09:55

Events are supposed to represent user intent. Do you guys also use them to initialize components with data from external sources even though that isn't really a user's intent? We are currently doing that but it's a bit annoying to use with re-frame-10x. As you step through the events, if you hit a component's initialize event it will re-issue that and very quickly receive the success event. You aren't able to ever go past the component's initialization event.

henrik16:09:13

Kind of. I use effects to issue a search request. Initializing and any subsequent search is the same thing, only the first happens based on some state in the URL. The entire thing is bound to the back/forward buttons as well.

kenny16:09:47

Right - our setup is somewhat similar. Still have the same problem. A component dispatches an event to initialize. When the response comes back, another event is dispatched.

henrik19:09:44

So is the problem that one event triggers an a call to an API which in turn dispatches another event on returning, or that you’re trigger two events close together, and the order is non-deterministic?

kenny19:09:42

We just use the re-frame-http-fx lib. So the component will dispatch an event to initialize. That event uses the http-fx to call the backend. On success, the http-fx will issue a success event.

lilactown17:09:35

this is going to be an unpopular opinion in #re-frame but I prefer to keep the app-db user/application centric, and use other means to handle data fetching and caching

dpsutton17:09:32

Can you give an example of how a component would look?

kenny18:09:35

I've been thinking about going down that route too @lilactown. It is convenient to have all my data viewable in the re-frame-10x UI though.

lilactown18:09:18

yeah you do lose some visibility, but I’ve used apollo-client in the past and that was a pretty nice way to visualize all of my external data away from my app data using their devtools

kenny18:09:24

Looks like it's for GraphQL only though?

lilactown18:09:44

yeah that’s correct

kenny18:09:03

You could always argue that you should have a REPL open and to just inspect your data that way haha

lilactown18:09:12

that too ¯\(ツ)

lilactown18:09:34

I’m also working on some general tooling for browsing CLJS data… that will help a lot in the future

lilactown18:09:59

the thing is external data is actually kind of weird… often you have pieces of it accumulate over time, you need to know when to invalidate the cache and which parts to re-fetch. you might also be merging changes over time based on user input

lilactown18:09:32

you can start to tie yourself into knots weaving the logic of fetching / caching / re-fetching data with actual application state and logic

kenny18:09:48

Yeah... We use Pathom on the backend. Right now we just force a data fetch from the backend every time a page loads, even if the data is already present.

kenny18:09:29

It's more cost effective to scale the backend than to spend engineering time writing cache code on the frontend 🙂

lilactown18:09:33

pathom might also have it’s own way of caching data? for some reason I thought fulcro had some abstraction over this but I don’t know if it’s decoupled from the full framework

lilactown18:09:44

hahaha yeah fair

kenny18:09:15

I think it does some sort of caching on the backend. We aren't using it at all in the frontend since it seemed to be mostly geared towards fulcro.

lilactown18:09:31

that’s why I like tools like apollo (hopefully there’s something that comes out for pathom like that too), which bundles all the easy wins you can get by representing your data as a graph

kenny18:09:03

Ya. That was a big downside to using Pathom. The tooling for GraphQL looks excellent.

lilactown18:09:17

I just joined a team that is using clojure(script) across all the stack and I imagine we will migrate to something like Pathom or GraphQL in the near(-ish) future, and yeah, the tooling is what makes me lean more towards GraphQL

lilactown18:09:43

the type system is troublesome but I don’t know if they’ll let me invent apollo-client for pathom 😛

kenny18:09:09

May take some time but it'd be super cool! Having queries written in native data structures is a huge win though. Allows for so much flexibility.

lilactown18:09:57

yeah GraphQL made the same mistake as SQL

4
4
lilactown18:09:13

no programmatic / data API for their queries

mikethompson23:09:10

We put all data into app-db An entire class of coordination / sync problems disappear (other problems do arise when you put all the data in the one place, its just that overall we prefer that tradeoff)

4
mikethompson23:09:55

If you are interested in GraphQL, and you are using Postgres, have a look at Hasura. It is working well for us.

polymeris13:09:39

I have been experimenting with the same. What do you use for a client? https://github.com/oliyh/re-graph?