在我的redux-saga函数中,我需要在回调中产生一个put。因此,我将生成器作为回调传递。但是我的回调没有执行。如果相反,我使用匿名函数,则回调将运行。
此记录数据:
Tabletop.init({
key: action.key,
callback: googleData => {
console.log(googleData);
},
simpleSheet: true
});
这不会记录数据:
Tabletop.init({
key: action.key,
callback: yield function*(googleData) {
console.log(googleData);
yield put(setProblems(googleData));
},
simpleSheet: true
});
我在网上看到,您可以兑现部分诺言。 Tabletop.js支持如下承诺:
function init() {
Tabletop.init( {
key: 'https://docs.google.com/spreadsheets/d/0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE/pubhtml',
simpleSheet: true }
).then(function(data, tabletop) {
console.log(data)
})
}
但是这种方式对我不起作用,因为出现此错误:
TypeError:未定义不是函数(在'...}附近)。然后(函数(数据,选项卡...']
[[https://github.com/jsoma/tabletop/issues/175]
有人可以告诉我使它正常工作的正确方法吗?提取数据后,我想在我的化简器中进行设置。
所以这就是我的工作方式。让我知道是否还有其他方法可以使这项工作。
我创建了一个返回承诺的函数:
function fetchProblemsPromise(key) {
return new Promise(resolve => {
Tabletop.init({
key: key,
callback: googleData => {
resolve(googleData);
},
simpleSheet: true
});
});
}
然后屈服:
const data = yield call(fetchProblemsPromise, [action.key]);
yield put(setProblems(data));
这帮助我弄清楚了:https://github.com/redux-saga/redux-saga/issues/508