Fork me on GitHub
#react
<
2021-05-25
>
martinklepsch15:05:31

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

Aron15:05:01

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

Aron16:05:34

not quite, this is the old one I think

Aron16:05:39

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

Aron16:05:01

It is related though, I think?

orestis17:05:35

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

orestis17:05:15

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

orestis17:05:10

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

Aron17:05:01

I would like to see a more complex example with reseda

orestis18:05:11

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

orestis18:05:40

To phrase it differently, define “complex” 😜

martinklepsch18:05:09

@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

martinklepsch18:05:31

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.

orestis19:05:44

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.

orestis19:05:15

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.

orestis19:05:21

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.

Aron20:05:01

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

Aron20:05:23

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