Skip to content

Instantly share code, notes, and snippets.

@ianjosephwilson
Created March 22, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianjosephwilson/fd7d10d57566ac8a56d7 to your computer and use it in GitHub Desktop.
Save ianjosephwilson/fd7d10d57566ac8a56d7 to your computer and use it in GitHub Desktop.
function startWatchingTagSettings() {
var request = null, timeout = null, temp = null, rate = 300;
$scope.$watch('tagSettings', function (val, oldVal) {
if (val === oldVal) {
// Special case where we are called durining initialization.
return;
}
temp = val;
if (timeout) {
$timeout.cancel(timeout);
}
if (request) {
request.abort();
request = null;
}
timeout = $timeout(function() {
console.log('updating the tag settings');
request = TagService.updateTag($scope.tag.id, temp);
}, rate);
}, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment