angular-debounce icon indicating copy to clipboard operation
angular-debounce copied to clipboard

seeking your help about how to use angular-debounce

Open johnson1968 opened this issue 8 years ago • 0 comments

Hello Ruben,

My name is Johnson Yang, I come from China, and I'm a software engineer working on UI program.

The reason why I'm seeking your help is that during the past 2 weeks, I was unable to solve debounce issue in our angularJS application, which is really troublesome, because the default debounce program would make multiple calls which lead to multiple commits and errors when saving data to the back end database.

After seeing your solution , I become optimistic.

However after I've applied your solution to my own program, I found it still does not work. I do not know the reason why? Below are the steps I've taken to apply the solution:

(1) modify the below JS file so that it can be invoked by other file as a non-anonymous service object.
https://github.com/rubenv/angular-debounce/blob/master/src/debounce.js

define( [],function () { function AngularDeboundService($timeout, wait, fn, no_postpone) { ....

// Cancels the queued execution if any
    wrapper.cancel = cancel;

    return wrapper;
};

return AngularDeboundService; });

(2) reference the debounce file (after renaming the above debounce.js to angular-debounce.js): define(['../factory/angular-debounce'], function(_,angularDebounce)...

(3) make debounce call (in the saveTabs event): saveTabs: function() { angularDebounce($timeout, 2000, function() {
$timeout (function()) { _saveToDatabase(); } ); }, true) ();
}

I just want to achieve the same effect as below: var fn = debounce(2000, function () { // Do things here. }, true);

Please also notice that I've added a $timeout parameter, because angularDebounce service requires it as an input.

And my testing result is that: I'm unable to limit the calls to 1 during the 2000 ms period. It would still have 3 calls made (or save data to database 3 times).

Would you mind advising me how I can do to solve the problem? (limit calls to 1 during the set time limit).

Thanks a lot!

And I'm looking forward to your reply.

Best Regards, Johnson

johnson1968 avatar Nov 24 '17 13:11 johnson1968