move new webpack methods to more appropriate file

This commit is contained in:
V 2023-11-22 07:04:17 +01:00
parent b21b6d7e5d
commit 7b24c8ac69
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
14 changed files with 52 additions and 57 deletions

View file

@ -18,6 +18,7 @@
import { proxyLazy } from "@utils/lazy";
import { Logger } from "@utils/Logger";
import { LazyComponent, NoopComponent } from "@utils/react";
import type { WebpackInstance } from "discord-types/other";
import { traceFunction } from "../debug/Tracer";
@ -392,6 +393,41 @@ export function findStoreLazy(name: string) {
return proxyLazy(() => findStore(name));
}
/**
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
*/
export function findComponentByCode(...code: string[]) {
const filter = filters.byCode(...code);
return find(m => {
if (filter(m)) return true;
if (!m.$$typeof) return false;
if (m.type) return filter(m.type); // memos
if (m.render) return filter(m.render); // forwardRefs
return false;
}) ?? NoopComponent;
}
/**
* Finds the first component that matches the filter, lazily.
*/
export function findComponentLazy<T extends object = any>(filter: FilterFn) {
return LazyComponent<T>(() => find(filter));
}
/**
* Finds the first component that includes all the given code, lazily
*/
export function findComponentByCodeLazy<T extends object = any>(...code: string[]) {
return LazyComponent<T>(() => findComponentByCode(...code));
}
/**
* Finds the first component that is exported by the first prop name, lazily
*/
export function findExportedComponentLazy<T extends object = any>(...props: string[]) {
return LazyComponent<T>(() => findByProps(...props)?.[props[0]]);
}
/**
* Wait for a module that matches the provided filter to be registered,
* then call the callback with the module as the first argument