Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux-saga的优势 #11

Open
du1wu2lzlz opened this issue Jul 4, 2018 · 0 comments
Open

Redux-saga的优势 #11

du1wu2lzlz opened this issue Jul 4, 2018 · 0 comments

Comments

@du1wu2lzlz
Copy link
Owner

为什么使用take , put 而不用async await```呢

个人理解: 为了方便进行单元测试

单元测试:
关注,测试 : 函数内部代码逻辑,若内部逻辑涉及异步请求,并不关心异步请求的返回值

redux-saga中文文档中声明式 Effect :

redux-saga 提供了一个不一样的方式来执行异步调用 :

通过call(fn, ...args) 这个函数。现在我们不立即执行异步调用,相反,call 创建了一条描述结果的信息。因此我们不必再使用mock来模拟异步请求的返回函数了,因为redux-saga的call函数已经帮我返回了结果信息

redux-saga middleware 确保执行函数调用并在响应被 resolve 时恢复 generator。

所以现在我们不需要模拟任何东西了,一个简单的相等测试就足够了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant