Easy Peasy VS React Redux

Easy Peasy VS React Redux

最近我发现了这个图书馆:https://easy-peasy.now.sh/ 实施了它,必须说它非常好。为什么它不如 redux 流行?为什么人们在可以使用它时倾向于使用 redux?两者的优点和缺点是什么? 还想知道当我可以做这样的事情时,状态的不变性是如何简单地保存的:

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

很明显它改变了状态..也许它不会改变实际状态? 总的来说想知道是否保留了所有 redux 原则,两者之间的主要区别是什么?

easy-peasy 是对 Redux 的抽象,它在内部使用 Redux 来管理状态。

有些人会选择使用 Redux,因为他们可以完全控制操作、操作创建器、reducer 等的实现方式。然而,easy-peasy 的用户被赋予了一种使用 Redux 的自以为是的方式,这大大减少了你必须编写的样板文件的数量。

至于它如何在 reducer 中强制执行不可变性,而正在编写的代码看起来像是在改变数据,easy-peasy 实际上在“幕后”使用了 Immer;引用自 Immer 网站:

"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."

与 easy-peasy 网站上的 stated 一样,该库允许扩展底层 Redux 存储,这允许您插入 vanilla Redux middleware/enhancers。