mercredi 2 septembre 2015

How do you use in practice findAll and peekAll in Ember?

From EmberJS documentation i get the following two ways to retrieve all records of a given type, one that makes a request and one that doesn't.

var posts = this.store.findAll('post'); // => GET /posts

var posts = this.store.peekAll('post'); // => no network request

It seems to me that i always need to do first a findAll but isn't clear for my understanding when should i do a peekAll.

For example, the user enters my blog and then i get all the posts using findAll, then at some point in the same flow i need all those post, so i should use a peekAll to save bandwidth. So how should i know that i have requested all posts previously ? Should i save some global state to handle that ? I would assume that the first time the client request a peekAll if there isn't any record it will automatically do a findAll or maybe i should that manually but it probably introduce some boilerplate.

How do you use in practice findAll and peekAll or they equivalents for single record ? Any recommendation ?




Aucun commentaire:

Enregistrer un commentaire