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('recordCache.@each.stateManager.currentState.name')
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.
Well, you could simply create a base model with a didUpdate property that handles showing your notification message, then have each of your models extend it. It’s really a stop-gap solution, but it works for the time being:
However….this will fire for EVERY record that is updated. So you’d probably want create your notification class in such a way that it will not open more then one saved notification at once…but that’s up to you.
I’m currently working on implementing some of the basic server-validation methods from this pull request https://github.com/emberjs/data/pull/376, and I’m hoping that I’ll come up with a better way to observe the status of commits (and will of course post back here if I do).