aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiamond <33725716+DiamondMiner88@users.noreply.github.com>2022-10-08 10:23:05 -0700
committerGitHub <noreply@github.com>2022-10-08 19:23:05 +0200
commit73a1bc94d1aca3fbae6efe3af9f1200af317d26e (patch)
treedcc631946d0bc9489c85b742fec7630c69d45ddb
parentea14bad85dec098c0a36d1ae2ff02ae059c98e42 (diff)
downloadVencord-73a1bc94d1aca3fbae6efe3af9f1200af317d26e.tar.gz
Vencord-73a1bc94d1aca3fbae6efe3af9f1200af317d26e.tar.bz2
Vencord-73a1bc94d1aca3fbae6efe3af9f1200af317d26e.zip
fix(lazyWebpack): implement more proxy traps (#65)
-rw-r--r--src/utils/misc.tsx13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx
index 4159906..989a54a 100644
--- a/src/utils/misc.tsx
+++ b/src/utils/misc.tsx
@@ -14,15 +14,20 @@ export function lazy<T>(factory: () => T): () => T {
/**
* Do a lazy webpack search. Searches the module on first property access
* @param filter Filter function
- * @returns Proxy. Note that only get and set are implemented, all other operations will have unexpected
- * results.
+ * @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({}, {
+ return new Proxy(() => null, {
get: (_, prop) => getMod()[prop],
- set: (_, prop, v) => getMod()[prop] = v
+ 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) => new newTarget(...args),
+ deleteProperty: (_, prop) => delete getMod()[prop],
+ defineProperty: (_, property, attributes) => !!Object.defineProperty(getMod(), property, attributes)
}) as T;
}