mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +01:00
refactor(website): extract layouts and use more server components (#9027)
Closes https://github.com/discordjs/discord.js/issues/8920 Closes https://github.com/discordjs/discord.js/issues/8997
This commit is contained in:
37
apps/website/src/util/members.ts
Normal file
37
apps/website/src/util/members.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { ApiItem, ApiItemContainerMixin } from '@microsoft/api-extractor-model';
|
||||
|
||||
/**
|
||||
* Resolves all inherited members (including merged members) of a given parent.
|
||||
*
|
||||
* @param parent - The parent to resolve the inherited members of.
|
||||
* @param predicate - A predicate to filter the members by.
|
||||
*/
|
||||
export function resolveMembers<T extends ApiItem>(
|
||||
parent: ApiItemContainerMixin,
|
||||
predicate: (item: ApiItem) => item is T,
|
||||
) {
|
||||
const seenItems = new Set<string>();
|
||||
const inheritedMembers = parent.findMembersWithInheritance().items.reduce((acc, item) => {
|
||||
if (predicate(item)) {
|
||||
acc.push({
|
||||
item,
|
||||
inherited:
|
||||
item.parent?.containerKey === parent.containerKey
|
||||
? undefined
|
||||
: (item.parent as ApiItemContainerMixin | undefined),
|
||||
});
|
||||
seenItems.add(item.containerKey);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, new Array<{ inherited?: ApiItemContainerMixin | undefined; item: T }>());
|
||||
|
||||
const mergedMembers = parent
|
||||
.getMergedSiblings()
|
||||
.filter((sibling) => sibling.containerKey !== parent.containerKey)
|
||||
.flatMap((sibling) => (sibling as ApiItemContainerMixin).findMembersWithInheritance().items)
|
||||
.filter((item) => predicate(item) && !seenItems.has(item.containerKey))
|
||||
.map((item) => ({ item: item as T, inherited: item.parent ? (item.parent as ApiItemContainerMixin) : undefined }));
|
||||
|
||||
return [...inheritedMembers, ...mergedMembers];
|
||||
}
|
||||
Reference in New Issue
Block a user