I’ve implementing a periodic autosave feature in my Ember app like this:
var App = Ember.Application.create({
ready: function () {
setInterval(function() { App.store.commit(); }, 10000);
}
});
It works great, flushing all changes to the server periodically. But how I can hook into the event so that I can give a visual indication that it’s happening to the user?
I can’t just stick it in the ‘ready’ event handler, because most times App.store.commit() won’t actually have any work to do, and even if it did, it happens asynchronously – commit() returns immediately, before the requests are generated.
That’s true
commitdoes not indicated its progress. SetupdidCreate&didUpdatecallbacks on your models to inject change notifications into your app.The nature of the Ember-Data transaction model means that much can happen when a
commitis requested, or not. Your callback notifications will probably need to be coalesced or throttled into a sensible user-facing message.DIY Alternative: create an isSaving property & afterSave observer
On your controller, use computed properties & observes to watch your specific data model for the
isSavingstate:This is a dirty compared to a generic, global
isSavingorisInFlightstate in ember-data, but it works very well in practice.