From e000d8384ce7b67b3162d23349b6d63d193eb11a Mon Sep 17 00:00:00 2001 From: Jack <30497388+FieryFlames@users.noreply.github.com> Date: Mon, 20 Mar 2023 04:09:25 -0400 Subject: [PATCH] [Metro] Implement findByName (#35) * [Metro] Correct findByDisplayName behavior * [Metro] Temporarily revert findByDisplayName to name filter This is to allow plugin developers to switch their plugins to use findByName --- src/def.d.ts | 6 ++++-- src/lib/metro/filters.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/def.d.ts b/src/def.d.ts index 5ba9fef..3b068b9 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -335,8 +335,10 @@ interface VendettaObject { findAll: (filter: (m: any) => boolean) => any[]; findByProps: PropsFinder; findByPropsAll: PropsFinderAll; - findByDisplayName: (name: string, defaultExp?: boolean) => any; - findByDisplayNameAll: (name: string, defaultExp?: boolean) => any[]; + findByName: (name: string, defaultExp?: boolean) => any; + findByNameAll: (name: string, defaultExp?: boolean) => any[]; + findByDisplayName: (displayName: string, defaultExp?: boolean) => any; + findByDisplayNameAll: (displayName: string, defaultExp?: boolean) => any[]; findByStoreName: (name: string) => any; common: { constants: PropIntellisense<"API_HOST">; diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index ca00b47..700f7cd 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -64,12 +64,15 @@ export const find = filterModules(modules, true); export const findAll = filterModules(modules); const propsFilter = (props: (string | symbol)[]) => (m: any) => props.every((p) => m[p] !== undefined); -// TODO: This uses .name, not .displayName. We should fix this SOON. Changing it directly WILL break plugins, though. -const dNameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.name === name : (m: any) => m?.default?.name === name); +const nameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.name === name : (m: any) => m?.default?.name === name); +const dNameFilter = (displayName: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.displayName === displayName : (m: any) => m?.default?.displayName === displayName); const storeFilter = (name: string) => (m: any) => m.getName && m.getName.length === 0 && m.getName() === name; export const findByProps: PropsFinder = (...props) => find(propsFilter(props)); export const findByPropsAll: PropsFinderAll = (...props) => findAll(propsFilter(props)); -export const findByDisplayName = (name: string, defaultExp = true) => find(dNameFilter(name, defaultExp)); -export const findByDisplayNameAll = (name: string, defaultExp = true) => findAll(dNameFilter(name, defaultExp)); +export const findByName = (name: string, defaultExp = true) => find(nameFilter(name, defaultExp)); +export const findByNameAll = (name: string, defaultExp = true) => findAll(nameFilter(name, defaultExp)); +// TODO: Make this use dNameFilter +export const findByDisplayName = (displayName: string, defaultExp = true) => find(nameFilter(displayName, defaultExp)); +export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(nameFilter(displayName, defaultExp)); export const findByStoreName = (name: string) => find(storeFilter(name)); \ No newline at end of file