FIX: Correctly debounce various functions (#18673)

Debouncing inline anonymous functions does not work.

This fixes all instances of that error by extracting the function or using the new `@debounce(delay)` decorator
This commit is contained in:
Jarek Radosz
2022-10-20 13:28:09 +02:00
committed by GitHub
parent ce53152e53
commit 8304f40f84
12 changed files with 170 additions and 204 deletions

View File

@ -1,5 +1,5 @@
import { debounce } from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import discourseDebounce from "discourse-common/lib/debounce";
import { headerOffset } from "discourse/lib/offset-calculator";
import isElementInViewport from "discourse/lib/is-element-in-viewport";
import { withPluginApi } from "discourse/lib/plugin-api";
@ -74,28 +74,22 @@ function initialize(api) {
// No need to unsubscribe, core unsubscribes /topic/* routes
},
@debounce(500)
_scrollToDiscobotPost(postNumber) {
discourseDebounce(
this,
function () {
const post = document.querySelector(
`.topic-post article#post_${postNumber}`
);
if (!post || isElementInViewport(post)) {
return;
}
const viewportOffset = post.getBoundingClientRect();
window.scrollTo({
top: window.scrollY + viewportOffset.top - headerOffset(),
behavior: "smooth",
});
},
postNumber,
500
const post = document.querySelector(
`.topic-post article#post_${postNumber}`
);
if (!post || isElementInViewport(post)) {
return;
}
const viewportOffset = post.getBoundingClientRect();
window.scrollTo({
top: window.scrollY + viewportOffset.top - headerOffset(),
behavior: "smooth",
});
},
});