javascript - Why doesn't the Reflux.js listenAndPromise helper work? -


i'm using qwest query endpoint shown below, ongetresourcecompleted handler fires expected data undefined. why?

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 data undefined. why?   }  }); 

i can see data loads correctly looking @ dev tools calling qwest in isolation doing:

qwest.get('http://localhost:8000/my-data/'+id, null, { withcredentials: true }).then(function(data) {   console.log('ok', data); }); 

also doing following works:

serviceactions.getresource.listen(function (id) {   serviceactions.getresource.promise(     qwest.get('http://localhost:8000/my-data/'+id, null, { withcredentials: true })   ); }); 

i've put comments on cause of "confirmed bug" in original issue opened @ github.com/spoike/refluxjs.

so, though using reflux features way intended, , they're creating race condition without returning race results, think you're in luck. turns out 2 particular features you're using in combination type of request bit redundant when have promise available. i'd recommend drop ongetrequestcompleted handler entirely, , handle completion using standard promise ways of handling resolved promises, give more flexibility anyways.

for example:

var mystore = reflux.createstore({    listenables: actions,    init: function () {     actions.getresource('')       .then()  <-- eliminates need ongetresourcecompleted       .catch() <-- or instead/in addition       .finally() <-- or instead/in additon   },    // no more ongetresourcecompleted  }); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -