Description
Devs should be able to $watch
two different meta properties of objects in the store to stay up-to-date with the latest version of those objects.
lastSaved
- A timestamp of the last time an object was saved via an async adapter
lastModified
- A timestamp of the last time any of the properties on an object changed
Examples:
$scope.$watch(function () {
return DS.lastSaved('document', 45);
}, function (lastSavedTimestamp) {
$scope.document = DS.get('document', 45);
});
In the above example the document on the $scope is only updated when the object is saved to the server. This is useful when you don't want the data binding in a form updating the object all over the screen when the user hasn't clicked the save button yet.
$scope.$watch(function () {
return DS.lastModified('document', 45);
}, function (lastModifiedTimestamp) {
$scope.document = DS.get('document', 45);
});
The above example would be more efficient than the following:
$scope.$watch(function () {
return DS.get('document', 45);
}, ...);
because internally angular-data would use Object.observe
if available, else its own digest loop that performs dirty checking just like Angular. Maybe devs should be able to throttle this digest loop as well.
This digest loop would be kicked off whenever $rootScope
's digest loop runs. Maybe it can be configured to run on an interval.