2022-06-21 17:34:04 -04:00
|
|
|
import { debounce } from "@ember/runloop";
|
2022-06-21 16:01:03 -04:00
|
|
|
import { isTesting } from "discourse-common/config/environment";
|
2021-01-21 15:55:39 -05:00
|
|
|
|
2020-12-18 08:18:52 -05:00
|
|
|
/**
|
|
|
|
Debounce a Javascript function. This means if it's called many times in a time limit it
|
|
|
|
should only be executed once (at the end of the limit counted from the last call made).
|
|
|
|
Original function will be called with the context and arguments from the last call made.
|
|
|
|
**/
|
|
|
|
|
|
|
|
export default function () {
|
|
|
|
if (isTesting()) {
|
2022-06-21 17:34:04 -04:00
|
|
|
// Replace the time argument with 10ms
|
2022-01-13 15:16:34 -05:00
|
|
|
let args = [].slice.call(arguments, 0, -1);
|
2022-06-21 17:34:04 -04:00
|
|
|
args.push(10);
|
|
|
|
|
|
|
|
return debounce.apply(undefined, args);
|
2020-12-18 08:18:52 -05:00
|
|
|
} else {
|
|
|
|
return debounce(...arguments);
|
|
|
|
}
|
|
|
|
}
|