2021-01-22 04:55:39 +08:00
|
|
|
import { debounce, next, run } from "@ember/runloop";
|
|
|
|
import { isLegacyEmber, isTesting } from "discourse-common/config/environment";
|
|
|
|
|
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.
|
|
|
|
**/
|
|
|
|
|
2021-01-22 04:55:39 +08:00
|
|
|
let testingFunc = isLegacyEmber() ? run : next;
|
|
|
|
|
2020-12-18 21:18:52 +08:00
|
|
|
export default function () {
|
|
|
|
if (isTesting()) {
|
2021-01-22 04:55:39 +08:00
|
|
|
return testingFunc(...arguments);
|
2020-12-18 21:18:52 +08:00
|
|
|
} else {
|
|
|
|
return debounce(...arguments);
|
|
|
|
}
|
|
|
|
}
|