mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
refactor: use reduce for stale group filtering
Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -333,12 +333,13 @@ export class FeedEngine<TItems extends FeedItem = FeedItem> {
|
|||||||
|
|
||||||
// Remove stale item IDs from groups and drop empty groups
|
// Remove stale item IDs from groups and drop empty groups
|
||||||
const itemIds = new Set(currentItems.map((item) => item.id))
|
const itemIds = new Set(currentItems.map((item) => item.id))
|
||||||
const validGroups = allGroupedItems
|
const validGroups = allGroupedItems.reduce<ItemGroup[]>((acc, group) => {
|
||||||
.map((group) => ({
|
const ids = group.itemIds.filter((id) => itemIds.has(id))
|
||||||
...group,
|
if (ids.length > 0) {
|
||||||
itemIds: group.itemIds.filter((id) => itemIds.has(id)),
|
acc.push({ ...group, itemIds: ids })
|
||||||
}))
|
}
|
||||||
.filter((group) => group.itemIds.length > 0)
|
return acc
|
||||||
|
}, [])
|
||||||
|
|
||||||
return { items: currentItems, groupedItems: validGroups, errors: allErrors }
|
return { items: currentItems, groupedItems: validGroups, errors: allErrors }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user