[Metro] Implement findByTypeName(All)

This commit is contained in:
Beef 2023-04-04 19:45:53 +01:00
parent 81fbf02ad9
commit c10355ef70
2 changed files with 5 additions and 0 deletions

2
src/def.d.ts vendored
View file

@ -346,6 +346,8 @@ interface VendettaObject {
findByNameAll: (name: string, defaultExp?: boolean) => any[]; findByNameAll: (name: string, defaultExp?: boolean) => any[];
findByDisplayName: (displayName: string, defaultExp?: boolean) => any; findByDisplayName: (displayName: string, defaultExp?: boolean) => any;
findByDisplayNameAll: (displayName: string, defaultExp?: boolean) => any[]; findByDisplayNameAll: (displayName: string, defaultExp?: boolean) => any[];
findByTypeName: (typeName: string, defaultExp?: boolean) => any;
findByTypeNameAll: (typeName: string, defaultExp?: boolean) => any[];
findByStoreName: (name: string) => any; findByStoreName: (name: string) => any;
common: { common: {
constants: PropIntellisense<"API_HOST">; constants: PropIntellisense<"API_HOST">;

View file

@ -66,6 +66,7 @@ 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);
const nameFilter = (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 dNameFilter = (displayName: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.displayName === displayName : (m: any) => m?.default?.displayName === displayName);
const tNameFilter = (typeName: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.type?.name === typeName : (m: any) => m?.default?.type?.name === typeName);
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));
@ -74,4 +75,6 @@ export const findByName = (name: string, defaultExp = true) => find(nameFilter(n
export const findByNameAll = (name: string, defaultExp = true) => findAll(nameFilter(name, defaultExp)); export const findByNameAll = (name: string, defaultExp = true) => findAll(nameFilter(name, defaultExp));
export const findByDisplayName = (displayName: string, defaultExp = true) => find(dNameFilter(displayName, defaultExp)); export const findByDisplayName = (displayName: string, defaultExp = true) => find(dNameFilter(displayName, defaultExp));
export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp)); export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp));
export const findByTypeName = (typeName: string, defaultExp = true) => find(tNameFilter(typeName, defaultExp));
export const findByTypeNameAll = (typeName: string, defaultExp = true) => findAll(tNameFilter(typeName, defaultExp));
export const findByStoreName = (name: string) => find(storeFilter(name)); export const findByStoreName = (name: string) => find(storeFilter(name));