From 6de41836477eee1c6da6cfba7bf766a0cbf1694d Mon Sep 17 00:00:00 2001 From: Beef Date: Sat, 7 Jan 2023 23:04:35 +0000 Subject: [PATCH] [Metro] Remove duplicated code --- src/lib/metro/filters.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index ef1bcbf..67a9cf5 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -24,11 +24,13 @@ for (const key in window.modules) { } } +const basicFind = (prop: string) => Object.values(window.modules).find(m => m.publicModule.exports?.[prop]).publicModule.exports; + // Hoist React -window.React = Object.values(window.modules).find(m => m.publicModule.exports.createElement).publicModule.exports; +window.React = basicFind("createElement"); // Find moment -let moment = Object.values(window.modules).find(m => m.publicModule.exports.isMoment).publicModule.exports; +let moment = basicFind("isMoment"); // Function to filter through modules export const filterModules = (modules: MetroModules, single = false) => (filter: (m: any) => boolean) => {