Skip to content

Commit 91c8ff6

Browse files
author
jtassin
committed
use of logasth.debounce instead of home made timeout
1 parent 4372bb5 commit 91c8ff6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/components/digestMiddleware.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
let toRun;
1+
import debounce from 'lodash.debounce';
22

33
export default function digestMiddleware($rootScope, debounceConfig) {
4+
let debouncedFunction = $rootScope.$evalAsync;
5+
if(debounceConfig && debounceConfig.wait && debounceConfig.wait > 0) {
6+
debouncedFunction = debounce($rootScope.$evalAsync, debounceConfig.wait, { maxWait: debounceConfig.maxWait });
7+
}
48
return store => next => action => {
59
const res = next(action);
6-
if(debounceConfig && debounceConfig.wait && debounceConfig.wait > 0) {
7-
toRun = res;
8-
window.setTimeout(() => {
9-
$rootScope.$evalAsync(toRun);
10-
toRun = undefined;
11-
}, debounceConfig.wait);
12-
} else {
13-
$rootScope.$evalAsync(toRun);
14-
}
10+
debouncedFunction(res);
1511
return res;
1612
};
1713
}

0 commit comments

Comments
 (0)