Telegram Web K with changes to work inside I2P
https://web.telegram.i2p/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
/* |
|
* https://github.com/morethanwords/tweb |
|
* Copyright (C) 2019-2021 Eduard Kuzmenko |
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE |
|
*/ |
|
|
|
import VisibilityIntersector from "./visibilityIntersector"; |
|
import findAndSpliceAll from "../helpers/array/findAndSpliceAll"; |
|
import findAndSplice from "../helpers/array/findAndSplice"; |
|
import LazyLoadQueueIntersector, { LazyLoadElement } from "./lazyLoadQueueIntersector"; |
|
|
|
export default class LazyLoadQueue extends LazyLoadQueueIntersector { |
|
constructor(parallelLimit?: number) { |
|
super(parallelLimit); |
|
|
|
this.intersector = new VisibilityIntersector(this.onVisibilityChange); |
|
} |
|
|
|
private onVisibilityChange = (target: HTMLElement, visible: boolean) => { |
|
if(visible) { |
|
/* if(DEBUG) { |
|
this.log('isIntersecting', target); |
|
} */ |
|
|
|
// need for set element first if scrolled |
|
findAndSpliceAll(this.queue, (i) => i.div === target).forEach((item) => { |
|
item.wasSeen = true; |
|
this.queue.unshift(item); |
|
//this.processQueue(item); |
|
}); |
|
|
|
this.setProcessQueueTimeout(); |
|
} |
|
}; |
|
|
|
protected getItem() { |
|
return findAndSplice(this.queue, item => item.wasSeen); |
|
} |
|
|
|
public async processItem(item: LazyLoadElement) { |
|
await super.processItem(item); |
|
this.intersector.unobserve(item.div); |
|
} |
|
|
|
protected addElement(method: 'push' | 'unshift', el: LazyLoadElement) { |
|
const inserted = super.addElement(method, el); |
|
|
|
if(!inserted) return false; |
|
|
|
this.intersector.observe(el.div); |
|
/* if(el.wasSeen) { |
|
this.processQueue(el); |
|
} else */if(!el.hasOwnProperty('wasSeen')) { |
|
el.wasSeen = false; |
|
} |
|
|
|
return true; |
|
} |
|
}
|
|
|