Skip to content

Evaluate other Redux abstraction layers for inspiration #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
markerikson opened this issue Apr 27, 2020 · 5 comments
Open

Evaluate other Redux abstraction layers for inspiration #527

markerikson opened this issue Apr 27, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@markerikson
Copy link
Collaborator

markerikson commented Apr 27, 2020

There's a bunch of Redux abstraction layers out there. Most of them take Redux in directions I'm not comfortable endorsing officially, but some of them might have some useful ideas we can swipe.

Note that we did something similar back in #17 when we analyzed libs like redux-actions and autodux to help come up with APIs like createSlice, so that sort of analysis would be the kind of thing I'm looking for here.

redux-bundler

Henrik Joreteg made a neat little lib called https://github.com/HenrikJoreteg/redux-bundler . It wraps the Redux store to allow defining reusable "bundles", and adds a bunch of various shortcuts. There might be some interesting concepts or bits of behavior we might be able to take inspiration from.

My biggest concern with it is that it relies very heavily on implicit naming and behavior, and it takes the Redux API in some directions I don't particularly want to endorse.

@alexkrolick suggests that something like the createAsyncResourceBundle might be useful - see https://reduxbundler.com/api-reference/included-bundles#createasyncresourcebundle-optionsobject and https://github.com/HenrikJoreteg/redux-bundler/blob/master/src/extras/create-async-resource-bundle.js .

Kea

https://kea.js.org/ is an abstraction layer that has chunks of reusable "logic", which can contain reducers, actions, and sagas. Those can be mounted and unmounted dynamically at runtime.

Easy-Peasy

https://easy-peasy.now.sh/ focuses on "zero config" and has things like computed properties.

Rematch

https://rematchjs.org/ has "no config", built-in side effects, and a plugins API.

VueX

VueX isn't Redux, of course, but it's inspired by Redux. The thing I find most interesting is the "modules" ability ( https://vuex.vuejs.org/guide/modules.html ), which allows plugging in additional chunks of code at runtime.

@markerikson markerikson changed the title Evaluate redux-bundler APIs for inspiration Evaluate other Redux abstraction layers for inspiration Feb 21, 2021
@nathggns
Copy link

Computed properties or properties with dependent varied sounds cool. I guess in theory you should just use a selector, but in some cases you do want to manually set the value. I've found myself using "setter functions" that work quite well with Immer, but that requires discipline and makes it hard to visualise / understand the links between various properties.

@markerikson
Copy link
Collaborator Author

markerikson commented Mar 9, 2021

Good comment at https://www.reddit.com/r/reactjs/comments/m0hk63/do_you_use_vanilla_react/gqbst2w/ :

I've used RTK in the past but have chosen to go with Easy Peasy for a variety of reasons. Though I'm definitely going to re-evaluate when RTK Query comes out.

Before that though, I'll list out reasons I think are unfair comparisons:

  • "Redux is wordy". RTK and Easy Peasy are roughly equivalent in "length". Neither are particularly wordy especially in comparison to traditional Redux
  • "Redux TS support is bad". They both have excellent Typescript support, although I prefer the Easy Peasy approach to TS. They're both very robust

The actual reasons I ended up going with Easy Peasy:

  • Injections and action mocking make it much easier to test
  • The manner in which you define actions and thunks allows you to completely ignore reduces. Which keeps the state definitions clean
  • Injections allow you to cleanly separate the state management and network requests in a way that makes those interactions very service-like
  • It is incredibly simple to create computed properties and action/thunk listeners.
  • It's still Redux under the hood so I can use the whole ecosystem of tooling, middleware, etc
  • Makes state persistence dead easy (you can persist per model and vary what kind of persistence level)

I'm not trying to downplay the value of RTK, it is very good. One key downside of Easy Peasy is that the manner in which actions/thunks/etc are defined will be harder to migrate if there are any issues or other libraries I want to integrate that require deep integration into either the state or network layer (limited to Axios-like libraries).

RTK manages to make Redux really easy and straightforward to use without requiring as much control over your state management as Easy Peasy. I think RTK Query (and whether I can leverage it in Easy Peasy) will change the calculus, though I'm unsure how exactly.

Important Note

The RTK Entity Adaptors allow you to optimally managed to handle a normalized state structure (which I always use).

But Easy Peasy usually allows you to completely bypass the need for that kind of sophistication to normalized state management. Though there are a few key features that are missing.

@LuisOsta
Copy link

LuisOsta commented Mar 9, 2021

@markerikson Are there any specific areas around current RTK that you think would be worthwhile to look at how other abstraction layers handle it?

Disclaimer:
I am the person who made that comment above.

@markerikson
Copy link
Collaborator Author

Not really sure, and that's kinda the point of the issue :) I'm interested in knowing what other libs do that RTK doesn't, and maybe some implementation analysis on how they do those different things so that we can determine if it's a thing that we might want to try and if it's feasible to do.

@markerikson markerikson added the enhancement New feature or request label Jun 7, 2021
@markerikson
Copy link
Collaborator Author

markerikson commented Apr 3, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants