10

Recently I found this library: https://easy-peasy.vercel.app/ Implemented it, and must say it was quite nice. Why it is not so popular as redux? why people tend to use redux when they can use this? What are the advantages and disadvantages of both? Also wanted to know how immutability of state is conserved in easy peasy when I can do things like that:

addProduct: action((state, payload) => {
    state.productIds.push(payload);
  })

clearly it mutates the state.. Maybe it doesn't mutate the actual state? In general wanted to know if all redux principles are kept, and what are the main differences between the two?

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
MD10
  • 1,313
  • 3
  • 12
  • 35

1 Answers1

11

easy-peasy is an abstraction over Redux, and it uses Redux internally to manage state.

Some people would choose to use Redux as they would have complete control over how actions, action creators, reducers etc. are implemented. However users of easy-peasy are given an opinionated way of using Redux, which cuts down drastically on the amount of boilerplate you have to write to work with it.

As for how it enforces immutability in the reducers, whilst the code being written looks like its mutating the data, easy-peasy actually uses Immer "under the hood"; quote from the Immer website:

"The basic idea is that you will apply all your changes to a temporary draftState, which is a proxy of the currentState. Once all your mutations are completed, Immer will produce the nextState based on the mutations to the draft state. This means that you can interact with your data by simply modifying it while keeping all the benefits of immutable data."

As is stated on the easy-peasy website, the library allows the extension of the underlying Redux store, which allows you to plug in vanilla Redux middleware/enhancers.

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
  • 4
    Note that I am a fan of easy-peasy, and the amount of time saved not having to write boiler plate code is a huge win! – Ben Smith May 24 '20 at 01:02
  • when it comes to big project.Readability and maintainability goes down this is my observation. – Pradnya Kulkarni Nov 08 '22 at 18:32
  • @PradnyaKulkarni an abstraction such as easy-peasy is designed to improve readability and maintainability. How do you think easy-peasy makes a large project less readable/maintainable as compared to one which doesn't use a Redux framework? – Ben Smith Nov 09 '22 at 09:23
  • Basically you have to write every common action creator in reducer only.Functions becomes large over there.Then there is service layer u need to make which makes whole architecture clusmy.Instead in redux or reduxtool kits in such libraries.No tight bundling of action creator with reducer.you can only play with states in reducer makes it easy. – Pradnya Kulkarni Nov 10 '22 at 17:15