2022-06-22 05:34:04 +08:00
|
|
|
import { debounce } from "@ember/runloop";
|
2022-06-22 04:01:03 +08:00
|
|
|
import { isTesting } from "discourse-common/config/environment";
|
2021-01-22 04:55:39 +08:00
|
|
|
|
2020-12-18 21:18:52 +08: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-22 05:34:04 +08:00
|
|
|
// Replace the time argument with 10ms
|
2022-01-14 04:16:34 +08:00
|
|
|
let args = [].slice.call(arguments, 0, -1);
|
2022-06-22 05:34:04 +08:00
|
|
|
args.push(10);
|
|
|
|
|
|
|
|
return debounce.apply(undefined, args);
|
2020-12-18 21:18:52 +08:00
|
|
|
} else {
|
|
|
|
return debounce(...arguments);
|
|
|
|
}
|
|
|
|
}
|