You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.2 KiB
TypeScript
64 lines
1.2 KiB
TypeScript
4 years ago
|
import { IFlow } from './message'
|
||
|
|
||
4 years ago
|
export class FlowManager {
|
||
4 years ago
|
private items: IFlow[]
|
||
|
private _map: Map<string, IFlow>
|
||
|
private filterText: string
|
||
|
private filterTimer: number | null
|
||
|
private num: number
|
||
|
private max: number
|
||
|
|
||
4 years ago
|
constructor() {
|
||
|
this.items = []
|
||
|
this._map = new Map()
|
||
|
this.filterText = ''
|
||
|
this.filterTimer = null
|
||
|
this.num = 0
|
||
|
|
||
|
this.max = 1000
|
||
|
}
|
||
|
|
||
|
showList() {
|
||
|
if (!this.filterText) return this.items
|
||
|
return this.items.filter(item => {
|
||
|
return item.request.url.includes(this.filterText)
|
||
|
})
|
||
|
}
|
||
|
|
||
4 years ago
|
add(item: IFlow) {
|
||
4 years ago
|
item.no = ++this.num
|
||
|
this.items.push(item)
|
||
|
this._map.set(item.id, item)
|
||
4 years ago
|
|
||
4 years ago
|
if (this.items.length > this.max) {
|
||
|
const oldest = this.items.shift()
|
||
4 years ago
|
if (oldest) this._map.delete(oldest.id)
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
get(id: string) {
|
||
4 years ago
|
return this._map.get(id)
|
||
|
}
|
||
|
|
||
4 years ago
|
changeFilter(text: string) {
|
||
4 years ago
|
this.filterText = text
|
||
|
}
|
||
|
|
||
4 years ago
|
changeFilterLazy(text: string, callback: () => void) {
|
||
4 years ago
|
if (this.filterTimer) {
|
||
|
clearTimeout(this.filterTimer)
|
||
|
this.filterTimer = null
|
||
|
}
|
||
|
|
||
|
this.filterTimer = setTimeout(() => {
|
||
|
this.filterText = text
|
||
|
callback()
|
||
4 years ago
|
}, 300) as any
|
||
4 years ago
|
}
|
||
|
|
||
|
clear() {
|
||
|
this.items = []
|
||
|
this._map = new Map()
|
||
|
}
|
||
|
}
|