beef up ConsoleShortcuts

This commit is contained in:
V 2023-11-23 02:44:04 +01:00
parent a2560ede1c
commit 6869705673
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
2 changed files with 39 additions and 15 deletions

View file

@ -52,7 +52,18 @@ export const filters = {
return true;
},
byStoreName: (name: string): FilterFn => m =>
m.constructor?.displayName === name
m.constructor?.displayName === name,
componentByCode: (...code: string[]): FilterFn => {
const filter = filters.byCode(...code);
return m => {
if (filter(m)) return true;
if (!m.$$typeof) return false;
if (m.type) return filter(m.type); // memos
if (m.render) return filter(m.render); // forwardRefs
return false;
};
}
};
export const subscriptions = new Map<FilterFn, CallbackFn>();
@ -397,18 +408,9 @@ export function findStoreLazy(name: string) {
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
*/
export function findComponentByCode(...code: string[]) {
const filter = filters.byCode(...code);
const res = find(m => {
if (filter(m)) return true;
if (!m.$$typeof) return false;
if (m.type) return filter(m.type); // memos
if (m.render) return filter(m.render); // forwardRefs
return false;
}, { isIndirect: true });
const res = find(filters.componentByCode(...code), { isIndirect: true });
if (!res)
handleModuleNotFound("findComponentByCode", ...code);
return res;
}