react

"mulling over state management stuff"
martinklepsch 2021-05-25T15:04:31.001900Z

Curious what kind of subscription layers people have been using. I’m looking for something that gets me a bunch of “views” on data that’s in one atom and efficiently updates those views if the underlying data changes. I wrote https://github.com/martinklepsch/derivatives once which kind of does this but there’s a few things I’d like to change about it so curious what other approaches are out there

Aron 2021-05-25T15:26:01.007800Z

I want to try the use-subscription hook, but the new one.

martinklepsch 2021-05-25T15:27:06.008200Z

do you mean this? https://www.npmjs.com/package/use-subscription

Aron 2021-05-25T16:27:34.008600Z

not quite, this is the old one I think

Aron 2021-05-25T16:29:39.009300Z

hah, I thank you, I have to realize I was very confused about the name of the thing I am talking about

Aron 2021-05-25T16:29:42.009500Z

https://github.com/facebook/react/pull/18000

Aron 2021-05-25T16:30:01.009800Z

It is related though, I think?

orestis 2021-05-25T17:30:18.010300Z

@martinklepsch I’ve made reseda for this https://github.com/orestis/reseda

orestis 2021-05-25T17:30:35.011Z

Using it in production and we quite like it so far.

orestis 2021-05-25T17:31:15.011700Z

It’s tied to React and doesn’t do too much. Haven’t had the need yet to change anything.

orestis 2021-05-25T17:34:10.012800Z

@ashnur you can see the mutable source in action too but I gave up on it until React releases a stable version.

Aron 2021-05-25T17:49:01.013200Z

I would like to see a more complex example with reseda

orestis 2021-05-25T18:05:11.014100Z

The demos are proof of concepts, do you have something in mind?

orestis 2021-05-25T18:05:40.014700Z

To phrase it differently, define “complex” 😜

martinklepsch 2021-05-25T18:22:09.017500Z

@orestis thanks for sharing, I found that - at least in our codebase - get-in style subscriptions cause a lot of data transformations to happen in components. This makes them harder to use in REPLs and harder to test. So we’re looking for something that can create more complex derived data from multiple branches of the root atom

martinklepsch 2021-05-25T18:23:31.018800Z

With resada it looks like that would only be possible with a selector function but then that function would be ran every time the root atom has sees any kind of changes.

orestis 2021-05-25T19:07:44.020500Z

Yes that’s true. Functions are in a way the lowest level in that they’re the most powerful flexible but hard to make guarantees.

orestis 2021-05-25T19:09:15.022800Z

It’s an interesting problem, how to cache results without running the code that produces the result? I guess intermediate steps might be a possibility, right? Cancel early. I’m curious about the domain you’re dealing with.

orestis 2021-05-25T19:10:21.024500Z

BTW reseda internationally deals with IWatchable so if your intermediate values implement the interface you can plug them into a reseda store to get the React updates for free.

Aron 2021-05-25T20:00:01.026200Z

orestis: my default example is a predictive autocomplete that can be reused in a form, with validation and possible completions both from client side and server side

Aron 2021-05-25T20:00:23.026700Z

it's the smallest thing that has all the gotchas that make these problems difficult