You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, I have a snippet of code that I keep copy and pasting all over my controllers for handling "auto-saving" functionality for objects:
var pendingPromise = null;
//Set up watch to auto save CTA on changes, but throttled once every 500ms.
$scope.$watch('myObject', function(nv, ov){
if((nv && ov) && (!_.isEqual(nv, ov))){
if (pendingPromise) {
$timeout.cancel(pendingPromise);
}
pendingPromise = $timeout(function () {
persistMyObject();
}, 500, false);
}
}, true);
I do this so that the API the underlying service talks to doesn't get inundates w/ requests, especially for ui components like sliders that change the model incrementally very quickly. If would be wonderful if in some later release of Angular if this were condensed down to something like:
So, I have a snippet of code that I keep copy and pasting all over my controllers for handling "auto-saving" functionality for objects:
I do this so that the API the underlying service talks to doesn't get inundates w/ requests, especially for ui components like sliders that change the model incrementally very quickly. If would be wonderful if in some later release of Angular if this were condensed down to something like:
Where 500 is the time in milliseconds to set on the throttle.
The text was updated successfully, but these errors were encountered: