dalefrancis88 / redux-lens

MIT License
0 stars 0 forks source link

Creating selectors #4

Open nightscape opened 4 years ago

nightscape commented 4 years ago

Hi @dalefrancis88, I'm coming to redux from a FP background and found this nice library. One thing I'm wondering: This library allows you to use lenses to drill down into the store for "writing" aka reducers. Would it make sense to use the same lenses for reading (i.e. creating Redux selectors)? Or is there something I'm missing that makes creating selectors from lenses unnecessary?

dalefrancis88 commented 4 years ago

Nice, Welcome. So i've actually been playing around with this idea as part of a local implementation. What I'd like to get to is a point where I could compose the lens nicely. The idea here is for when you have the multiple levels instead of creating one as a path all the way from the root reducer, you can just create it at the level that's relative. You could then "add" a level as needed. The idea then would be to be able to then be able to reference a collection of the lens to create the state for a component in a call to connect it would create the mapStateToProps func

Apologies for the late reply, you caught me right on the week that i was moving house

dalefrancis88 commented 4 years ago

Was thinking, if you come from an FP background, you should check out Crocks

nightscape commented 4 years ago

Hi @dalefrancis88, thanks for your response despite being busy! We've also been thinking of composing lenses for drilling down into data structures for both the read and the write side. In fact, I was so convinced that something like this must exist that I was quite surprised that there are only ~3 lens implementations for Redux and only yours seems to be actively maintained :open_mouth: I'm still wondering if there's some obvious alternative that I'm missing, or JS people are just not aware of lenses (and potentially other beneficial FP constructs) and implement the same logic by hand over and over...

We were/are using reselect to do the drill-down on the read side. Would this also be an option of creating selectors?

dalefrancis88 commented 4 years ago

I think when it comes to JS and FP its a hard won battle. The issue I see is there is so much focus on trying to "fix" javascript by developers that don't really quite grasp the freedom of a dynamic language and push to make it closer to something like C#.

Reselect is a good library, I don't use it though, not for any reason other than i'm using that Crocks library that has a bunch of ADT's and I rolled my own before that was ever released. It's also the reason I havn't moved it into this library just yet is that it relies on that other one which I don't want to do. So I'm trying to make sure i'm fully across the problem space first and to see any potential pitfalls.

That being said, the idea of an integration could be interesting, I'll take an in depth look at the reselect but to ask you, how do you think that'd work in your mind?