From 296336535f6d23c586c7e83edf0420b58cbf011a Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 14 Oct 2022 21:34:35 +0200 Subject: Fix modals, add wp.mapMangledModule --- src/utils/misc.tsx | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/utils/misc.tsx') diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx index b646ec1..f6ea36c 100644 --- a/src/utils/misc.tsx +++ b/src/utils/misc.tsx @@ -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(factory: () => T): () => T { +export function makeLazy(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(factory: () => T): () => T { * @returns A proxy to the webpack module. Not all traps are implemented, may produce unexpected results. */ export function lazyWebpack(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)); } /** -- cgit