mardi 27 juin 2017

Ember.js 2. Lazy fetch in background after rendering the page

I have a simple page "authors" that shows a list of authors.

Each author of course has many books, but in that page (and in the API) I don't show(/include) any book data.

In the authors route I have the default model():

model() {
  return this.store.findAll('author');
}

and everything is OK.

Now I need something that fetch lazy (in background) some data from others APIs (the books ones).

But I don't want this call blocking my authors page render. So, I have the default and speedy beforeModel(), model() and afterModel() without any fetch (except for authors data).

ONLY after page is rendered I need something (maybe a service?) that calls "api/books?author:1,2,3,4,5..."

In this way I already have the books in my "store" when someone click on an athor (no waiting loader in that book page).

How to do this?




Aucun commentaire:

Enregistrer un commentaire