import { HttpService, RequestState } from "../services/HttpService";
import {
Choice,
- debounce,
fetchLimit,
fetchUsers,
getIdFromString,
personToChoice,
setIsoData,
} from "../utils";
+import { debounce } from "../utils/helpers/debounce";
import { getQueryParams } from "../utils/helpers/get-query-params";
import { getQueryString } from "../utils/helpers/get-query-string";
import { amAdmin } from "../utils/roles/am-admin";
Choice,
capitalizeFirstLetter,
communityToChoice,
- debounce,
elementUrl,
emDash,
enableNsfw,
updateCommunityBlock,
updatePersonBlock,
} from "../../utils";
+import { debounce } from "../../utils/helpers/debounce";
import { HtmlTags } from "../common/html-tags";
import { Icon, Spinner } from "../common/icon";
import { ImageUploadForm } from "../common/image-upload-form";
archiveTodayUrl,
capitalizeFirstLetter,
communityToChoice,
- debounce,
fetchCommunities,
getIdFromString,
ghostArchiveUrl,
validURL,
webArchiveUrl,
} from "../../utils";
+import { debounce } from "../../utils/helpers/debounce";
import { Icon, Spinner } from "../common/icon";
import { LanguageSelect } from "../common/language-select";
import { MarkdownTextArea } from "../common/markdown-textarea";
buildCommentsTree,
commentsToFlatNodes,
commentTreeMaxDepth,
- debounce,
editComment,
editWith,
enableDownvotes,
updatePersonBlock,
} from "../../utils";
import { isBrowser } from "../../utils/browser/is-browser";
+import { debounce } from "../../utils/helpers/debounce";
import { CommentForm } from "../comment/comment-form";
import { CommentNodes } from "../comment/comment-nodes";
import { HtmlTags } from "../common/html-tags";
capitalizeFirstLetter,
commentsToFlatNodes,
communityToChoice,
- debounce,
enableDownvotes,
enableNsfw,
fetchCommunities,
setIsoData,
showLocal,
} from "../utils";
+import { debounce } from "../utils/helpers/debounce";
import { getQueryParams } from "../utils/helpers/get-query-params";
import { getQueryString } from "../utils/helpers/get-query-string";
import type { QueryParams } from "../utils/types/query-params";
import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces";
import { HttpService, UserService } from "./services";
import { isBrowser } from "./utils/browser/is-browser";
+import { debounce } from "./utils/helpers/debounce";
import { groupBy } from "./utils/helpers/group-by";
let Tribute: any;
return dt === DataType.Post ? "Post" : "Comment";
}
-export function debounce<T extends any[], R>(
- func: (...e: T) => R,
- wait = 1000,
- immediate = false
-) {
- // 'private' variable for instance
- // The returned function will be able to reference this due to closure.
- // Each call to the returned function will share this common timer.
- let timeout: NodeJS.Timeout | null;
-
- // Calling debounce returns a new anonymous function
- return function () {
- // reference the context and args for the setTimeout function
- const args = arguments;
-
- // Should the function be called now? If immediate is true
- // and not already in a timeout then the answer is: Yes
- const callNow = immediate && !timeout;
-
- // This is the basic debounce behavior where you can call this
- // function several times, but it will only execute once
- // [before or after imposing a delay].
- // Each time the returned function is called, the timer starts over.
- clearTimeout(timeout ?? undefined);
-
- // Set the new timeout
- timeout = setTimeout(function () {
- // Inside the timeout function, clear the timeout variable
- // which will let the next execution run when in 'immediate' mode
- timeout = null;
-
- // Check if the function already ran with the immediate flag
- if (!immediate) {
- // Call the original function with apply
- // apply lets you define the 'this' object as well as the arguments
- // (both captured before setTimeout)
- func.apply(this, args);
- }
- }, wait);
-
- // Immediate mode and no wait timer? Execute the function..
- if (callNow) func.apply(this, args);
- } as (...e: T) => R;
-}
-
export function getLanguages(
override?: string,
myUserInfo = UserService.Instance.myUserInfo
--- /dev/null
+export function debounce<T extends any[], R>(
+ func: (...e: T) => R,
+ wait = 1000,
+ immediate = false
+) {
+ // 'private' variable for instance
+ // The returned function will be able to reference this due to closure.
+ // Each call to the returned function will share this common timer.
+ let timeout: NodeJS.Timeout | null;
+
+ // Calling debounce returns a new anonymous function
+ return function () {
+ // reference the context and args for the setTimeout function
+ const args = arguments;
+
+ // Should the function be called now? If immediate is true
+ // and not already in a timeout then the answer is: Yes
+ const callNow = immediate && !timeout;
+
+ // This is the basic debounce behavior where you can call this
+ // function several times, but it will only execute once
+ // [before or after imposing a delay].
+ // Each time the returned function is called, the timer starts over.
+ clearTimeout(timeout ?? undefined);
+
+ // Set the new timeout
+ timeout = setTimeout(function () {
+ // Inside the timeout function, clear the timeout variable
+ // which will let the next execution run when in 'immediate' mode
+ timeout = null;
+
+ // Check if the function already ran with the immediate flag
+ if (!immediate) {
+ // Call the original function with apply
+ // apply lets you define the 'this' object as well as the arguments
+ // (both captured before setTimeout)
+ func.apply(this, args);
+ }
+ }, wait);
+
+ // Immediate mode and no wait timer? Execute the function..
+ if (callNow) func.apply(this, args);
+ } as (...e: T) => R;
+}