Currently I am struggeling with Ember.RSVP.all in combination with Ember.RSVP.hash
I am doing several API requests and the idea was to collect all these requests in an array (different types) and then resolve them alltogether. I think in RSVP.hash everything breaks with "Uncaught error, unexpected token u (or :,. its every time something other) in JSON..." In the error I can see parts of the data delivered by the API so the request as is seems to work.
The idea of the code structure worked totally fine with bluebird in a other version (without ember). Would it be possible simply to use bluebird in ember ?
This is what I am doing (maybe there is a better solution ?):
in my Service:
testRequest (result){
var sources = result[0]; // that are multiple sources from the store received in the controller
var startDate = result[1];
var type1 = [];
var typ2 = [];
console.log(sources);
sources.forEach(function (item, index, enumerable) {
var identifier = item.get('identifier');
var query = {id: item.get('bid'), params:{since:startDate}}; //build the query in
if (identifier == "type1"){
console.log("got", identifier, "with query:", query);
//type1.push(dummy(query));
type1.push(usabilla.websites.buttons.feedback.get(query)); // do a request for type1 structure and push to array
}
else if (identifier == "type2"){
console.log("got", identifier, "with query:", query);
//type2.push(dummy(query));
type2.push(usabilla.apps.forms.feedback.get(query)); // do a request for type 2 structure and push to array
}
else {
console.log("not supported");
}
});
return [type1, type2];
},
and the controller part:
//Controller:
//...
store.findAll('feedbacksource')
.then(function(feedbackresources){
var result = feedbackresources.toArray();
return [result, startDate];
})
.then(myService.testRequest)
.then(myService.logRes)
.then(function(results){
return Ember.RSVP.hash({
type1: Ember.RSVP.all(results[0]),
type2: Ember.RSVP.all(results[1])
});
})
.then(myService.logRes)
Thanks so much for your help, I have tried so many things but nothing seems to work or maybe I am totally wrong where I search the error. I am running out of ideas.
Aucun commentaire:
Enregistrer un commentaire