mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 06:33:03 -04:00
Fix modals, add wp.mapMangledModule
This commit is contained in:
parent
563f2fb1dc
commit
296336535f
7 changed files with 102 additions and 29 deletions
|
@ -1,15 +1,17 @@
|
|||
import { FilterFn, find } from "../webpack";
|
||||
import { React } from "../webpack/common";
|
||||
import { proxyLazy } from "./proxyLazy";
|
||||
|
||||
/**
|
||||
* Makes a lazy function. On first call, the value is computed.
|
||||
* On subsequent calls, the same computed value will be returned
|
||||
* @param factory Factory function
|
||||
*/
|
||||
export function lazy<T>(factory: () => T): () => T {
|
||||
export function makeLazy<T>(factory: () => T): () => T {
|
||||
let cache: T;
|
||||
return () => cache ?? (cache = factory());
|
||||
}
|
||||
export const lazy = makeLazy;
|
||||
|
||||
/**
|
||||
* Do a lazy webpack search. Searches the module on first property access
|
||||
|
@ -17,18 +19,7 @@ export function lazy<T>(factory: () => T): () => T {
|
|||
* @returns A proxy to the webpack module. Not all traps are implemented, may produce unexpected results.
|
||||
*/
|
||||
export function lazyWebpack<T = any>(filter: FilterFn): T {
|
||||
const getMod = lazy(() => find(filter));
|
||||
|
||||
return new Proxy(() => null, {
|
||||
get: (_, prop) => getMod()[prop],
|
||||
set: (_, prop, value) => getMod()[prop] = value,
|
||||
has: (_, prop) => prop in getMod(),
|
||||
apply: (_, $this, args) => (getMod() as Function).apply($this, args),
|
||||
ownKeys: () => Reflect.ownKeys(getMod()),
|
||||
construct: (_, args, newTarget) => Reflect.construct(getMod(), args, newTarget),
|
||||
deleteProperty: (_, prop) => delete getMod()[prop],
|
||||
defineProperty: (_, property, attributes) => !!Object.defineProperty(getMod(), property, attributes)
|
||||
}) as any as T;
|
||||
return proxyLazy(() => find(filter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue