Fix AsyncCollection.filter to allow for async filter functions

This commit is contained in:
Garrett Mills 2022-04-28 19:41:04 -05:00
parent fd77ad5cd3
commit de13030815
2 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.9.40",
"version": "0.9.41",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

View File

@ -401,7 +401,17 @@ export class AsyncCollection<T> {
let newItems: CollectionItem<T>[] = []
await this.inChunks(async items => {
newItems = newItems.concat(items.filter(func).all())
const filterItems: CollectionItem<T>[] = []
for ( let i = 0; i < items.length; i += 1 ) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const item = items.get(i)!
if ( await func(item, i) ) {
filterItems.push(item)
}
}
newItems = newItems.concat(filterItems)
})
return new Collection<T>(newItems)