2021-01-21 15:55:39 -05:00
|
|
|
import { debounce, next, run } from "@ember/runloop";
|
|
|
|
import { isLegacyEmber, isTesting } from "discourse-common/config/environment";
|
|
|
|
|
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.
|
|
|
|
**/
|
|
|
|
|
2021-01-21 15:55:39 -05:00
|
|
|
let testingFunc = isLegacyEmber() ? run : next;
|
|
|
|
|
2020-12-18 08:18:52 -05:00
|
|
|
export default function () {
|
|
|
|
if (isTesting()) {
|
2022-01-13 15:16:34 -05:00
|
|
|
// Don't include the time argument (in ms)
|
|
|
|
let args = [].slice.call(arguments, 0, -1);
|
|
|
|
return testingFunc.apply(void 0, args);
|
2020-12-18 08:18:52 -05:00
|
|
|
} else {
|
|
|
|
return debounce(...arguments);
|
|
|
|
}
|
|
|
|
}
|