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()) {
|
2021-01-21 15:55:39 -05:00
|
|
|
return testingFunc(...arguments);
|
2020-12-18 08:18:52 -05:00
|
|
|
} else {
|
|
|
|
return debounce(...arguments);
|
|
|
|
}
|
|
|
|
}
|