In order to make a little yellow "Saving"/"Saved" indicator message at the top of my app, I'd like to have a boolean property indicating if any ember-data records are currently in flight.
I tried this:
App.store = DS.Store.create
isSaving: (->
for record in this.get('recordCache')
if record?.getPath('stateManager.currentState.name') == 'inFlight'
return true
return false
).property('[email protected]')
but then I discovered that recordCache
is not observable.
I don't use transactions, only App.store.commit()
, so I looked at App.store.get('defaultTransaction')
, but it didn't yield anything useful.
I'm using the RESTAdapter, so if I can extend it into giving me this piece of information, that would work too.
Why not extend model, controller and/or view:
DS.Model.reopen({
didCreate: function() {
this.set('persisted', true);
},
didUpdate: function() {
this.set('persisted', true);
},
resetPersistenceFlag: function(){
this.set('persisted', false);
}.observes('isDirty')
});
Ember.Controller.reopen({
contentPersistedObserver: function() {
if (this.get('content.persisted') === true) {
//do stuff here
}
}.observes('content.persisted')
});
Ember.View.reopen({
controllerContentPersistedObserver: function() {
if (this.get('controller.content.persisted') === true) {
//do stuff here
}
}.observes('controller.content.persisted')
});
That way your controller/view will know when model is saved. It will fire for Create/Update controllers, but for controllers that manage arrays it will not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With