Skip to content

Instantly share code, notes, and snippets.

@travist
Last active October 2, 2021 11:28
Show Gist options
  • Select an option

  • Save travist/057e613adbcd31510d6e110786d88e10 to your computer and use it in GitHub Desktop.

Select an option

Save travist/057e613adbcd31510d6e110786d88e10 to your computer and use it in GitHub Desktop.

Revisions

  1. travist revised this gist Oct 30, 2016. No changes.
  2. travist revised this gist Oct 30, 2016. No changes.
  3. travist revised this gist Oct 30, 2016. 1 changed file with 13 additions and 8 deletions.
    21 changes: 13 additions & 8 deletions debounce.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,17 @@
    ['$scope', function($scope) {
    var debounceTimer = null;
    var debounce = function(cb) {
    if (debounceTimer) clearTimeout(debounceTimer);
    debounceTimer = setTimeout(cb, 200);
    var timeout = null;
    return function(data) {
    if (timeout) {
    clearTimeout(timeout);
    }
    timeout = setTimeout(function() {
    cb(data);
    }, 200);
    };
    };
    $scope.$watch('submission.data', function(data) {
    debounce(function() {
    // Put your logic here...
    });
    });

    $scope.$watch('submission.data', debounce(function(data) {
    // Put your logic here....
    }));
    });
  4. travist created this gist Oct 18, 2016.
    12 changes: 12 additions & 0 deletions debounce.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    ['$scope', function($scope) {
    var debounceTimer = null;
    var debounce = function(cb) {
    if (debounceTimer) clearTimeout(debounceTimer);
    debounceTimer = setTimeout(cb, 200);
    };
    $scope.$watch('submission.data', function(data) {
    debounce(function() {
    // Put your logic here...
    });
    });
    });