【发布时间】:2017-02-25 02:06:56
【问题描述】:
我已经阅读了大量有关“redux-saga”的教程,并了解如何构建我的 reducer 和 saga 以直接执行。我遇到的问题是我不知道以返回我可以使用的东西的方式实际获取请求的数据。大多数人实际使用什么来获取请求的数据?
这是我的请求传奇:
import { call } from 'redux-saga/effects';
export function* request(url, method, body) {
try {
const result = yield call(fetch, url, { method: method, body: body });
return {err: null, res: result };
} catch(error) {
return {err: error, res: null };
}
}
..“yield call(fetch...”在 Chrome 中返回一个 ReadableStream,如果我像使用 redux-thunk 一样使用“isomorphic-fetch”,它会返回一个承诺。我不能在根据我所见,生成器函数。
我确定这可能是使用结果的简单代码行,但我似乎找不到它。任何帮助表示赞赏!
【问题讨论】:
标签: javascript react-redux redux-saga