mardi 4 juillet 2017

Ember 2, which differences in this code?

I'm using this code to simulate a server delay for my gets.

let promises = [];
child.get('authors').forEach(author => author.get('books').forEach(book => {
  var promise = new RSVP.Promise(function (resolve, reject) {
    let time = (Math.floor(Math.random() * 10) + 1) * 1000;
    Ember.run.later(() => {
      favoriteList.pushObject(book);
      resolve();
    }, time);
    if (somethingWrong) {
      reject(error);
    }
  });
  promises.push(promise)
}));

RSVP.all(promises).then(function () {
  console.log('Yoo! Finally!')
}).catch(function (error) {});

I'm wondering, except for the Ember.run.later() which I use to simulate a server delay for all my "gets" there are differences in this code below?

child.get('authors').forEach(author => author.get('books').forEach(book => {
  favoriteList.pushObject(book);
}));

console.log('Yoo! Finally!')




Aucun commentaire:

Enregistrer un commentaire