थोड़ा प्रदर्शन टिप अगर किसी के पास कुंजी के साथ डेटासोर तरह की सेवा है -> मूल्य जोड़े:
यदि आपके पास डेटास्टोर नामक एक सेवा है , तो जब भी आपका बड़ा डेटा ऑब्जेक्ट बदलता है , तो आप टाइमस्टैम्प को अपडेट कर सकते हैं। इस तरह से पूरी वस्तु को देखने के बजाय, आप केवल बदलाव के लिए टाइमस्टैम्प देख रहे हैं।
app.factory('dataStore', function () {
var store = { data: [], change: [] };
// when storing the data, updating the timestamp
store.setData = function(key, data){
store.data[key] = data;
store.setChange(key);
}
// get the change to watch
store.getChange = function(key){
return store.change[key];
}
// set the change
store.setChange = function(key){
store.change[key] = new Date().getTime();
}
});
और एक निर्देश में आप केवल बदलने के लिए टाइमस्टैम्प देख रहे हैं
app.directive("myDir", function ($scope, dataStore) {
$scope.dataStore = dataStore;
$scope.$watch('dataStore.getChange("myKey")', function(newVal, oldVal){
if(newVal !== oldVal && newVal){
// Data changed
}
});
});