mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:55:25 +08:00
DEV: Introduce discourseLater
(#17532)
A wrapper for `later()` from `@ember/runloop`, similar to `discourseDebounce`. It automatically reduces the delay in testing environment.
This commit is contained in:
14
app/assets/javascripts/discourse-common/addon/lib/later.js
Normal file
14
app/assets/javascripts/discourse-common/addon/lib/later.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { later } from "@ember/runloop";
|
||||
import { isTesting } from "discourse-common/config/environment";
|
||||
|
||||
export default function () {
|
||||
if (isTesting() && typeof [...arguments].at(-1) === "number") {
|
||||
// Replace the `wait` argument with 10ms
|
||||
let args = [].slice.call(arguments, 0, -1);
|
||||
args.push(10);
|
||||
|
||||
return later.apply(undefined, args);
|
||||
} else {
|
||||
return later(...arguments);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user