Skip to content

Commit

Permalink
When deriving a bucket, set its entities immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Oct 25, 2022
1 parent f7aeab1 commit a1f2d79
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/miniplex-core/src/Bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,13 @@ export class Bucket<E> {
if (existingBucket) return existingBucket

/* Create bucket */
const bucket = new Bucket<D>()
const bucket = new Bucket<D>({
entities: this.entities.filter(predicate) as D[]
})

/* Add to cache */
this.derivedBuckets.set(predicate, bucket)

/* Add entities that match the predicate */
for (const entity of this.entities) {
if (predicate(entity)) {
bucket.add(entity)
}
}

/* Listen for new entities */
bucket.onDisposed.add(
this.onEntityAdded.add((entity) => {
Expand Down

0 comments on commit a1f2d79

Please sign in to comment.