vendredi 30 juin 2017

ember.js 2, promises or not promises?

I have this code:

let promise = child.get('authors').forEach(author => author.get('books').forEach(book => {

  let time = (Math.floor(Math.random() * 10) + 1) * 1000;

  Ember.run.later(() => {

    //Some operations and then every book in the forEach is added to my favoriteList
    favoriteList.pushObject(book);

  }, time);

}));

promise.then(() => {
  console.log('Yoo! Finally!')
})

I need that message (and other actions) to execute finally, after all forEach. But now that message is consolelogged before that forEach get finished. Why?

I know I have to use: RSVP, Promises, EmberPromiseMixin and these stuff but it's a mess!

Would you suggest the code and something beautiful site or book or something to finally learn once for all this stuff?




Aucun commentaire:

Enregistrer un commentaire