rinchik
rinchik

Reputation: 2670

Is there a hook in ember data i can use to know when it actually sends request to the server?

I need to show spinner only if data is not in the store (if ember sends request to the server)

Is there any way to do that?

Upvotes: 1

Views: 433

Answers (2)

medokin
medokin

Reputation: 630

You can get the current state of models.

Your Controller:

savingObserver: function(){
  this.set('showSpinner', this.get('model.isSaving'));
}.observes('model.isSaving')

If that is true, show spinner.

Or if you have multiple records to watch, do this:

savingObserver: function(){
  this.set('showSpinner', this.get('content').isAny('isSaving', true);
}.observes('[email protected]')

Upvotes: 2

Kingpin2k
Kingpin2k

Reputation: 47367

save returns a promise, you can infer it's started right before you've called save and infer it's finished after the promise has resolved.

console.log('saving');
record.save().then(function(){
  console.log('done saving');
}); // finally might be more appropriate in case it fails

You can also hook up to ajaxStart and ajaxStop and put a spinner there Showing a spinner during an AJAX request?

Upvotes: 1

Related Questions