Javascript 为什么';Refluw.js是否正常工作?
我使用qwest查询我的端点,如下所示,onGetResourceCompleted处理程序按预期启动,但数据未定义。为什么?Javascript 为什么';Refluw.js是否正常工作?,javascript,reactjs,refluxjs,Javascript,Reactjs,Refluxjs,我使用qwest查询我的端点,如下所示,onGetResourceCompleted处理程序按预期启动,但数据未定义。为什么? var Actions = Reflux.createActions({ 'getResource': { asyncResult: true } }); Actions.getResource.listenAndPromise(function (id) { return qwest.get('http://localhost:8000/my-data/'+
var Actions = Reflux.createActions({
'getResource': { asyncResult: true }
});
Actions.getResource.listenAndPromise(function (id) {
return qwest.get('http://localhost:8000/my-data/'+id, null, { withCredentials: true });
});
var MyStore = Reflux.createStore({
listenables: Actions,
init: function () {
Actions.getResource('');
},
onGetResourceCompleted: function (data) {
console.log('OK', data); // Get's called but data is undefined. Why?
}
});
通过查看dev工具以及单独调用qwest,我可以正确地看到数据加载,只需执行以下操作:
qwest.get('http://localhost:8000/my-data/'+id, null, { withCredentials: true }).then(function(data) {
console.log('OK', data);
});
同时执行以下操作:
ServiceActions.getResource.listen(function (id) {
ServiceActions.getResource.promise(
qwest.get('http://localhost:8000/my-data/'+id, null, { withCredentials: true })
);
});
我已经在您打开的原始版本中对这个“确认错误”的原因发表了一些评论 因此,尽管你正在按预期的方式使用回流功能,而且它们肯定在创造比赛条件,甚至没有返回比赛结果,但我认为你很幸运。事实证明,当您已经有了承诺时,您在这种类型的请求组合中使用的两个特定功能有点多余。我建议您完全删除
onGetRequestCompleted
处理程序,并使用处理已解决承诺的标准承诺方式来处理完成,这将为您提供更大的灵活性
例如:
var MyStore = Reflux.createStore({
listenables: Actions,
init: function () {
Actions.getResource('')
.then() <-- this eliminates the need for onGetResourceCompleted
.catch() <-- or this instead/in addition
.finally() <-- or this instead/in additon
},
// no more onGetResourceCompleted
});
var MyStore=reflow.createStore({
可收听者:行动,
init:函数(){
Actions.getResource(“”)
.then()我已经在您在上打开的原始版本中对这个“确认错误”的原因发表了一些评论
因此,尽管你正在按预期的方式使用回流功能,而且它们肯定在不返回比赛结果的情况下创造了比赛条件,但我认为你很幸运。事实证明,当你已经有了承诺时,你在这类请求的组合中使用的两个特定功能有点多余。我建议您完全删除onGetRequestCompleted
处理程序,并使用处理已解决承诺的标准承诺方式来处理完成,这将为您提供更大的灵活性
例如:
var MyStore = Reflux.createStore({
listenables: Actions,
init: function () {
Actions.getResource('')
.then() <-- this eliminates the need for onGetResourceCompleted
.catch() <-- or this instead/in addition
.finally() <-- or this instead/in additon
},
// no more onGetResourceCompleted
});
var MyStore=reflow.createStore({
可收听者:行动,
init:函数(){
Actions.getResource(“”)
.then()你的qwest.get(…)是什么样子的?它是否返回承诺并使用“resolve”和“reject”回调?你使用的是什么版本的RefluxJS?我可以在v0.2.8(使用)中使用listenAndPromise
。我使用的是v0.2.8。回流似乎与qwest不一致。奇怪的是,ListendPromise不起作用,但在使用qwest promises时promise起作用。我可以通过用Q promise()包装qwest使其起作用但我并不完全满意这个解决方案,只是为了让它能够与回流一起工作。我愿意接受关于Ajax promise库的建议,该库可以与回流一起工作,而无需黑客。您是否查看了axios
?请参阅我链接的部分,了解它的奶酪热:?您的qwest.get(…)看起来像?它是否返回承诺并使用“resolve”和“reject”回调?您使用的是哪个版本的RefluxJS?我可以在v0.2.8中使用ListendPromise
(使用)。我使用的是v0.2.8。回流似乎与qwest不一致。奇怪的是,ListendPromise不起作用,但在使用qwest promises时promise起作用。我可以通过用Q promise()包装qwest使其起作用但我并不完全满意这个解决方案,只是为了让它能够与回流一起工作。我愿意接受关于Ajax promise库的建议,该库可以与回流一起工作,而无需黑客。您是否查看了axios
?请参阅我链接的部分,了解它的奶酪热:?您的qwest.get(…)看起来像?它是否返回承诺并使用“resolve”和“reject”回调?您使用的是哪个版本的RefluxJS?我可以在v0.2.8中使用ListendPromise
(使用)。我使用的是v0.2.8。回流似乎与qwest不一致。奇怪的是,ListendPromise不起作用,但在使用qwest promises时promise起作用。我可以通过用Q promise()包装qwest使其起作用但我并不完全满意这个解决方案,只是为了让它能够与回流一起工作。我愿意接受有关Ajax promise库的建议,该库可以与回流一起工作,而无需黑客。您是否查看了axios
?请参阅我链接的部分了解其cheetsheat:?