component events
This commit is contained in:
24
library/internal/limited-collection.ts
Normal file
24
library/internal/limited-collection.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export class LimitedCollection<T> {
|
||||
private items: T[] = []
|
||||
|
||||
constructor(private readonly size: number) {}
|
||||
|
||||
add(item: T) {
|
||||
if (this.items.length >= this.size) {
|
||||
this.items.shift()
|
||||
}
|
||||
this.items.push(item)
|
||||
}
|
||||
|
||||
has(item: T) {
|
||||
return this.items.includes(item)
|
||||
}
|
||||
|
||||
values(): readonly T[] {
|
||||
return this.items
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this.items[Symbol.iterator]()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user