Reputation: 773
My backend always responds with all available data and it took a considerably amount of time. So I'm reloading store periodically and I plan to use peekAll() and peekRecord().
My code is:
model: function() {
return Ember.RSVP.hash({
'clusters': this.store.peekAll('cluster'),
'single': this.store.peekRecord('cluster', 'cluster::My')
});
When code is executed, at first I can see that both of these items do not contain content. After few seconds data are loaded to store and I can see content 'clusters' on template as expected. But 'single' is still completely without content ({{model.single}} does not return nothing in template). But when I have a button with action:
alert(this.store.peekRecord('cluster', 'cluster::My'));
I can see that the record was found. Records are also available via Ember Inspector. What am I doing wrong that only peekAll() works in model for me.
Upvotes: 3
Views: 2774
Reputation: 6577
The semantics of both methods are:
store.peekAll
returns a live array that is updated as the store is updated.store.peekRecord
returns the corresponding object in the current cache, or null
, and it does not update.So the behaviour you're observing is the expected one. If you want to use the peek
methods, my advise is to make sure that the initial request has finished loading before fetching any data from the store.
Upvotes: 5