Weird problems when getting metadata


#1

Hi !

Sorry for my english.

So i have really weird problems with fetching metedata. My app display a list of bookmarks. I have setup an infinite scrolling system. It work perfectly. To setup this infinite scroll i have an action in my controller which load more bookmarks:

loadMore: function() {

	var self = this;
	var meta = this.store.metadataFor('bookmark');

	if(meta.nextPage != null) {
		self.set('isLoadingMore', true);

		self.store.find('bookmark', {page: meta.nextPage})
			.then(function(bookmarks) {
				self.set('isLoadingMore', false);
			}).catch(function(err) {
				self.set('isLoadingMore', false);
			});

	}
	else {
		self.set('isLoadingMore', false);
	}

}

So like that this function work perfectly. If I scroll it load the next page of bookmarks. This is the js console:

 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=3".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=4".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=4".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=5".

But what i would like to do is to use these meteData in my template. So i had created a computed property in my controller:

metaData: Ember.computed('model.isFulffiled', function() {
 			return this.store.metadataFor('bookmark') 
 		}),

Since i have done that I can access metadata in my template but the metada seems not been updated when the loadMore function is called. So the loadMore fonction allways load the next page given in the metadata of the initial request.

 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".
jquery.js:8625 XHR finished loading: GET "http://localhost:8000/api/bookmarks?page=2".

I also posted the question on stackoverflow.


#2

I found something thanks to this link:

apparently i should use:

Ember.copy(store.metadataFor('user'))

to avoid theses problems. So i made a computed property in my controller like so:

metaData : function() {
	return Ember.copy(this.store.metadataFor('bookmark'));
}.property('content.@each'),

And it work now i can access my meta data in my template like this:

Total : {{metaData.total}} Current page: {{metaData.currentPage}}

I don’t know if it is the right way to do this so if i have an other solution feel free to post it.