This commit is contained in:
Nuckyz 2024-06-12 17:45:54 -03:00
parent 5931a72de2
commit e9e25306eb
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 6 additions and 6 deletions

View file

@ -6,7 +6,7 @@
import { makeLazy } from "./lazy"; import { makeLazy } from "./lazy";
export type LazyComponentType<T extends object = {}> = React.ComponentType<T> & Record<PropertyKey, any>; export type LazyComponentType<T extends object = any> = React.ComponentType<T> & Record<PropertyKey, any>;
export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner"); export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner");
@ -17,7 +17,7 @@ export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner"
* @param attempts How many times to try to get the component before giving up * @param attempts How many times to try to get the component before giving up
* @returns Result of factory function * @returns Result of factory function
*/ */
export function LazyComponent<T extends object = {}>(factory: () => LazyComponentType<T>, attempts = 5) { export function LazyComponent<T extends object = any>(factory: () => LazyComponentType<T>, attempts = 5) {
const get = makeLazy(factory, attempts, { isIndirect: true }); const get = makeLazy(factory, attempts, { isIndirect: true });
let InnerComponent = null as LazyComponentType<T> | null; let InnerComponent = null as LazyComponentType<T> | null;

View file

@ -204,7 +204,7 @@ export function find<T = AnyObject>(filter: FilterFn, callback: (module: ModuleE
* @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component
* @returns The component if found, or a noop component * @returns The component if found, or a noop component
*/ */
export function findComponent<T extends object = {}>(filter: FilterFn, parse: (component: ModuleExports) => LazyComponentType<T> = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { export function findComponent<T extends object = any>(filter: FilterFn, parse: (component: ModuleExports) => LazyComponentType<T> = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) {
if (typeof filter !== "function") if (typeof filter !== "function")
throw new Error("Invalid filter. Expected a function got " + typeof filter); throw new Error("Invalid filter. Expected a function got " + typeof filter);
if (typeof parse !== "function") if (typeof parse !== "function")
@ -249,7 +249,7 @@ export function findComponent<T extends object = {}>(filter: FilterFn, parse: (c
* @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component
* @returns The component if found, or a noop component * @returns The component if found, or a noop component
*/ */
export function findExportedComponent<T extends object = {}>(...props: string[] | [...string[], (component: ModuleExports) => LazyComponentType<T>]) { export function findExportedComponent<T extends object = any>(...props: string[] | [...string[], (component: ModuleExports) => LazyComponentType<T>]) {
const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (component: ModuleExports) => LazyComponentType<T>; const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (component: ModuleExports) => LazyComponentType<T>;
const newProps = props as string[]; const newProps = props as string[];
@ -294,7 +294,7 @@ export function findExportedComponent<T extends object = {}>(...props: string[]
* @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component
* @returns The component if found, or a noop component * @returns The component if found, or a noop component
*/ */
export function findComponentByCode<T extends object = {}>(...code: string[] | [...string[], (component: ModuleExports) => LazyComponentType<T>]) { export function findComponentByCode<T extends object = any>(...code: string[] | [...string[], (component: ModuleExports) => LazyComponentType<T>]) {
const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (component: ModuleExports) => LazyComponentType<T>; const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (component: ModuleExports) => LazyComponentType<T>;
const newCode = code as string[]; const newCode = code as string[];
@ -524,7 +524,7 @@ export function webpackDependantLazy<T = AnyObject>(factory: () => T, attempts?:
* @param attempts How many times to try to get the component before giving up * @param attempts How many times to try to get the component before giving up
* @returns Result of factory function * @returns Result of factory function
*/ */
export function webpackDependantLazyComponent<T extends object = {}>(factory: () => any, attempts?: number) { export function webpackDependantLazyComponent<T extends object = any>(factory: () => any, attempts?: number) {
if (IS_REPORTER) webpackSearchHistory.push(["webpackDependantLazyComponent", [factory]]); if (IS_REPORTER) webpackSearchHistory.push(["webpackDependantLazyComponent", [factory]]);
return LazyComponent<T>(factory, attempts); return LazyComponent<T>(factory, attempts);