@abradley2/redux-loop 中文文档教程
Elm Architecture 到 Redux 的端口,允许您通过从 reducer 返回它们来自然而纯粹地对效果进行排序.
在减速器中引起副作用是不是不正确?
是的! 绝对地。
redux-loop 不会在 reducer 中产生副作用吗?
它没有。 调度效果时从 reducer 返回的值 redux-loop 只是描述 的效果。 调用减速器不会导致 运行效果。 reducer 返回的值只是一个对象, 当 redux-loop 增强时,store 知道如何解释。 您可以安全地 在你的测试中调用一个 reducer 而不必担心等待效果完成 以及它们会对您的环境造成什么影响。
redux-loop 对环境有什么要求?
redux-loop
需要包含 ES6 Promise
和 Symbol
的 polyfill,如果 您定位的浏览器本身并不支持它们。
Why use this?
使用并遵循 Redux 和 Elm 架构的进展,并且 在尝试了 Redux 的其他效果模式之后,我们得出了以下结果 结论:
从reducer返回一个新状态引起的同步状态转换 对一个动作的反应只是一个动作可能产生的所有可能效果之一 有申请状态。
在 Redux 中处理效果的许多其他方法,尤其是那些已实现的方法 对于 action-creators,错误地告诉用户异步效果是 从根本上不同于同步状态转换。 这种分离 鼓励不同的和越来越具体的处理特定的方法 类型效果。 相反,我们应该专注于让我们的减速器足够强大 处理异步效果以及同步状态转换。 和 redux-loop
,reducer 不只是决定现在会发生什么 特定的操作,它决定下一步会发生什么。 你的所有行为 可以通过一个地方跟踪应用程序,并且可以很容易地破坏该行为 分开又组合在一起。 这是最强大的功能之一 Elm 架构,以及 redux-loop
这也是 Redux 的一个特性。
Installation
npm install --save redux-loop
Support
应提交潜在错误、一般性讨论和提案或 RFC 作为此 repo 的问题,我们将尽最大努力快速解决它们。 我们用这个 图书馆也是如此,并希望它成为最好的! 有关使用的问题 库,在 StackOverflow 上提交问题 使用 redux-loop
标签。
Slack channel
Don't see a feature you want?
如果您有兴趣向 redux-loop
添加一些东西,但不要不想等 为了让我们融入您可以按照以下步骤获得您自己的可安装的想法 包含您的功能的 redux-loop
版本:
- Fork the main repo here
- Add your feature or change
- Change the package
"name"
in package.json to be"@<your-npm-username>/redux-loop
- Commit to master and
npm publish
npm install @<your-npm-username>/redux-loop
我们总是 对新想法感兴趣,但有时我们会有点忙而跌倒 在响应和审查 PR 方面落后。 希望这个过程能让你 继续在您的项目上取得进展,并在以下情况下为我们提供更多背景信息 当您决定为您的新功能或更改制作 PR 时。 最好的验证方式 库的新功能是在真实场景中使用它们!
Contributing
请注意,此项目随 贡献者行为准则 一起发布。 参与此项目即表示您同意遵守其条款。 contributor-covenant.org 提供多种语言翻译
A port of the Elm Architecture to Redux that allows you to sequence your effects naturally and purely by returning them from your reducers.
Isn't it incorrect to cause side-effects in a reducer?
Yes! Absolutely.
Doesn't redux-loop put side-effects in the reducer?
It doesn't. The values returned from the reducer when scheduling an effect with redux-loop only describe the effect. Calling the reducer will not cause the effect to run. The value returned by the reducer is just an object that the store knows how to interpret when it is enhanced by redux-loop. You can safely call a reducer in your tests without worrying about waiting for effects to finish and what they will do to your environment.
What are the environment requirements for redux-loop?
redux-loop
requires polyfills for ES6 Promise
and Symbol
to be included if the browsers you target don't natively support them.
Why use this?
Having used and followed the progression of Redux and the Elm Architecture, and after trying other effect patterns for Redux, we came to the following conclusion:
Synchronous state transitions caused by returning a new state from the reducer in response to an action are just one of all possible effects an action can have on application state.
Many other methods for handling effects in Redux, especially those implemented with action-creators, incorrectly teach the user that asynchronous effects are fundamentally different from synchronous state transitions. This separation encourages divergent and increasingly specific means of processing particular types effects. Instead, we should focus on making our reducers powerful enough to handle asynchronous effects as well as synchronous state transitions. With redux-loop
, the reducer doesn't just decide what happens now due to a particular action, it decides what happens next. All of the behavior of your application can be traced through one place, and that behavior can be easily broken apart and composed back together. This is one of the most powerful features of the Elm architecture, and with redux-loop
it is a feature of Redux as well.
Installation
npm install --save redux-loop
Support
Potential bugs, general discussion, and proposals or RFCs should be submitted as issues to this repo, we'll do our best to address them quickly. We use this library as well and want it to be the best it can! For questions about using the library, submit questions on StackOverflow with the redux-loop
tag.
Slack channel
Don't see a feature you want?
If you're interested in adding something to redux-loop
but don't want to wait for us to incorporate the idea you can follow these steps to get your own installable version of redux-loop
with your feature included:
- Fork the main repo here
- Add your feature or change
- Change the package
"name"
in package.json to be"@<your-npm-username>/redux-loop
- Commit to master and
npm publish
npm install @<your-npm-username>/redux-loop
We are always interested in new ideas, but sometimes we get a little busy and fall behind on responding and reviewing PRs. Hopefully this process will allow you to continue making progress on your projects and also provide us with more context if and when you do decide to make a PR for your new feature or change. The best way to verify new features for a library is to use them in real-world scenarios!
Contributing
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. Multiple language translations are available at contributor-covenant.org