我最近才发现 Redux.这一切看起来都不错.在 Flux 上使用 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 明确不尝试解决附近"的问题,例如 撤销/重做,持久化 或 forms,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 的缺点是什么
发布评论