react

"mulling over state management stuff"
dominicm 2020-04-27T02:03:59.158500Z

@lilactown sounds like apollo or fulcro. What differences from those solutions do you think would be useful?

orestis 2020-04-27T05:35:27.160500Z

I think having multiple “stores” makes sense if your application is highly modular. (More like a set of mini-applications that share a few top-level stuff like current user etc).

👍 1
orestis 2020-04-27T05:36:24.162100Z

In redux world they deal with this with “slices” which afaict is just a naming convention. Even though redux allows you to have multiple stores...

dominicm 2020-04-27T06:50:04.163300Z

You can also solve this by giving each area a derivation of the root, and giving them a namespaced key.

dominicm 2020-04-27T06:50:24.163600Z

It's a useful thing to enforce though..

dominicm 2020-04-27T07:30:15.164200Z

https://www.apollographql.com/docs/react/why-apollo/ this looks vaguely usable from clojure script

dominicm 2020-04-27T08:00:27.165400Z

Apparently I'm preaching to the choir... https://clojureverse.org/t/example-apollo-graphql-integration-with-react-cljs/4223/5 So you'll definitely need to tell me why not just use apollo :)

orestis 2020-04-27T08:39:34.167500Z

The compile time requirements are annoying. Needing to parse graphql queries etc. The fallback is to do it at runtime but then your bundle size explodes.

orestis 2020-04-27T08:41:09.168800Z

Also - you will be dealing with JS data structures, right?

dominicm 2020-04-27T11:52:33.169200Z

Yeah, which I hate, buuut, for network requests js->clj is not terrible.

orestis 2020-04-27T12:07:06.170100Z

Oh sure - but then you can’t put the result in Apollo. The main benefit of Apollo is the cache.

dominicm 2020-04-27T12:18:11.170700Z

Oh, hmm. It would be nice if it didn't care about the store.

dominicm 2020-04-27T12:18:22.171100Z

Just data in, data out operation.

lilactown 2020-04-27T15:08:20.172Z

I loved using Apollo at my last job

lilactown 2020-04-27T15:08:34.172600Z

Problem is we’re not using graphql at my new gig

lilactown 2020-04-27T15:09:25.173900Z

Might be difficult to adopt, and we lose some of the e2e clojure benefits we have: namespaced keywords, transit

lilactown 2020-04-27T15:16:39.174500Z

Also the type system

orestis 2020-04-27T15:37:33.176300Z

Apollo includes also a graphql resolver implementation, will rewrite your queries, answer parts of them from the cache etc. I just find this way too much :)

1
dominicm 2020-04-27T15:49:15.178400Z

So, in terms of servers. There's 3 big forms that come to mind: - REST - gql - pathom/eql Do we think that the specification of the data you want should be tied to the underlying format or independent? I'm thinking tied to it.

dominicm 2020-04-27T15:55:58.181300Z

I guess what we want the library to do is: Take old data, and query, and shrink it down to the minimum query required for the data? How do caches get invalidated in an apollo world? Manually? Or do they naturally update in response to mutations or something?

lilactown 2020-04-27T16:17:24.181900Z

triggering a fetch or mutation in apollo typically invalidates the cache, though you can control that behavior

lilactown 2020-04-27T16:24:34.187Z

typically what happens is:

query in render
 -> check cache
   -> is cached? render immediately unless configured to always fetch
   -> is not cached? fetch and return a loading state
 -> subscribe to changes in cache

dispatch fetch
 -> start request
   -> notify any subscribers that want to know when data is loading
 -> request returns, populate cache
 -> notify any subscribers that data has changed

dispatch mutation
 -> start request
   -> if configured, optimistically update cache
 -> request returns
   -> if configured, update cache with returned data; GOTO last step of dispatch fetch
   -> if configured, begin fetching a query to update the cache; GOTO dispatch fetch

dominicm 2020-04-27T19:02:42.188100Z

So the other part of it is merging queries & graphs together. I wonder if that even matters now we have http/2

dominicm 2020-04-27T21:18:14.188500Z

https://hackernoon.com/non-event-driven-redux-5ce56776184f this is a question I have.

orestis 2020-04-28T07:52:19.202500Z

That’s still redux-like, and dispatching events. It’s only a question if whether the logic for handling the event is encapsulated in the event itself, or if it is at some far away place.

orestis 2020-04-28T07:54:21.203900Z

BTW it’s also almost exactly how atoms work -> dispatch a function that will change the atom.

dominicm 2020-04-28T08:46:33.214600Z

Yeah :) I guess that's kinda my point. Why not just dispatch reduction functions to your store and skip events altogether?