使用Redux而不是Flux的不利之处 [英] What could be the downsides of using Redux instead of Flux

查看:67
本文介绍了使用Redux而不是Flux的不利之处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才发现 Redux .一切看起来都不错.在Redux上使用Redux是否有任何弊端,陷阱或妥协?谢谢

I just recently discovered Redux. It all looks good. Are there any downsides, gotcha or compromises of using Redux over Flux? Thanks

推荐答案

Redux作者在这里!

Redux author here!

我想说的是,您将在使用它时做出以下折衷:

I'd like to say you're going to make the following compromises using it:

  • 您将需要学习避免突变. Flux对突变数据一无所知,但是Redux不喜欢突变,并且许多与Redux互补的软件包都假设您永远不会突变状态.您可以使用仅限开发人员的软件包(例如 redux-immutable-state-invariant 强制实施此操作) ,请使用 Immutable.js ,或相信自己和您的团队编写非可变代码,但是这是您需要注意的事情,并且需要您的团队接受这一有意识的决定.

  • You'll need to learn to avoid mutations. Flux is unopinionated about mutating data, but Redux doesn't like mutations and many packages complementary to Redux assume you never mutate the state. You can enforce this with dev-only packages like redux-immutable-state-invariant, use Immutable.js, or trust yourself and your team to write non-mutative code, but it's something you need to be aware of, and this needs to be a conscious decision accepted by your team.

您将需要仔细挑选包裹.尽管Flux明确地不会尝试解决附近"问题,例如持久性表单,Redux具有扩展点,例如中间件和商店增强器,并且具有产生了一个年轻而丰富的生态系统.这意味着大多数软件包都是新主意,尚未达到临界使用量.您可能依赖于几个月后显然不是一个好主意的东西,但是现在还很难说.

You're going to have to carefully pick your packages. While Flux explicitly doesn't try to solve "nearby" problems such as undo/redo, persistence, or forms, Redux has extension points such as middleware and store enhancers, and it has spawned a young but rich ecosystem. This means most packages are new ideas and haven't received the critical mass of usage yet. You might depend on something that will be clearly a bad idea a few months later on, but it's hard to tell just yet.

您还没有很好的Flow集成. Flux当前使您能够进行非常令人印象深刻的静态类型检查,而Redux 尚不支持.我们会到达那里,但需要一些时间.

You won't have a nice Flow integration yet. Flux currently lets you do very impressive static type checks which Redux doesn't support yet. We'll get there, but it will take some time.

我认为第一个是初学者最大的障碍,第二个可能是过度热情的早期采用者所面临的问题,第三个是我的个人宠儿.除此之外,我认为使用Redux不会带来Flux可以避免的任何特殊缺点,并且有些人说与Flux相比,它甚至还有一些缺点.

I think the first is the biggest hurdle for the beginners, the second can be a problem for over-enthusiastic early adopters, and the third is my personal pet peeve. Other than that, I don't think using Redux brings any particular downsides that Flux avoids, and some people say it even has some upsides compared to Flux.

另请参阅我在使用Redux方面的答案.

这篇关于使用Redux而不是Flux的不利之处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆