简体   繁体   English

将redux存储实现为函数而不是类的原因是什么?

[英]What is the reason behind implementing redux store as a function, not a class?

Last day I was trying to write a wrapper around Redux store but I had to copy and paste some code in order to create the same API. 昨天,我试图为Redux商店编写包装器,但必须复制并粘贴一些代码才能创建相同的API。 With react I could easily extend my class from React.Component so I was thinking why developers of Redux have not implemented their store like this? 使用react我可以轻松地从React.Component扩展我的类,所以我在想为什么Redux的开发人员没有实现这样的商店? here is copy of the store code: 这是商店代码的副本:

https://github.com/reactjs/redux/blob/master/src/createStore.js https://github.com/reactjs/redux/blob/master/src/createStore.js

Because you can use enhancer s instead, which allow you to compose multiple functions with the store in the particular order you want. 因为您可以改用enhancer ,所以您可以按照所需的特定顺序与商店组合多个功能。 Using inheritance would require that all your third party enhancers inherit from each other in the order you need them to. 使用继承将要求您所有的第三方增强器都按照您需要的顺序相互继承。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM