[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
This commit is contained in:
Jack 2023-03-20 04:09:25 -04:00 committed by GitHub
parent e1e8012e60
commit e000d8384c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

6
src/def.d.ts vendored
View file

@ -335,8 +335,10 @@ interface VendettaObject {
findAll: (filter: (m: any) => boolean) => any[]; findAll: (filter: (m: any) => boolean) => any[];
findByProps: PropsFinder; findByProps: PropsFinder;
findByPropsAll: PropsFinderAll; findByPropsAll: PropsFinderAll;
findByDisplayName: (name: string, defaultExp?: boolean) => any; findByName: (name: string, defaultExp?: boolean) => any;
findByDisplayNameAll: (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; findByStoreName: (name: string) => any;
common: { common: {
constants: PropIntellisense<"API_HOST">; constants: PropIntellisense<"API_HOST">;

View file

@ -64,12 +64,15 @@ export const find = filterModules(modules, true);
export const findAll = filterModules(modules); export const findAll = filterModules(modules);
const propsFilter = (props: (string | symbol)[]) => (m: any) => props.every((p) => m[p] !== undefined); 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 nameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.name === name : (m: any) => m?.default?.name === name);
const dNameFilter = (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; 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 findByProps: PropsFinder = (...props) => find(propsFilter(props));
export const findByPropsAll: PropsFinderAll = (...props) => findAll(propsFilter(props)); export const findByPropsAll: PropsFinderAll = (...props) => findAll(propsFilter(props));
export const findByDisplayName = (name: string, defaultExp = true) => find(dNameFilter(name, defaultExp)); export const findByName = (name: string, defaultExp = true) => find(nameFilter(name, defaultExp));
export const findByDisplayNameAll = (name: string, defaultExp = true) => findAll(dNameFilter(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)); export const findByStoreName = (name: string) => find(storeFilter(name));