mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-24 12:45:18 +08:00
30 lines
750 B
JavaScript
30 lines
750 B
JavaScript
import ResizeObserver from 'resize-observer-polyfill'
|
|
|
|
class ResizeObserverDelegate {
|
|
constructor () {
|
|
console.log('resize observer')
|
|
this.handleResize = this.handleResize.bind(this)
|
|
this.observer = new ResizeObserver(this.handleResize)
|
|
this.elHandlersMap = new Map()
|
|
}
|
|
handleResize (entries) {
|
|
for (const entry of entries) {
|
|
const handler = this.elHandlersMap.get(entry.target)
|
|
if (handler) {
|
|
// console.log(entry)
|
|
handler()
|
|
}
|
|
}
|
|
}
|
|
registerHandler (el, handler) {
|
|
this.elHandlersMap.set(el, handler)
|
|
this.observer.observe(el)
|
|
}
|
|
unregisterHandler (el) {
|
|
this.elHandlersMap.delete(el)
|
|
this.observer.unobserve(el)
|
|
}
|
|
}
|
|
|
|
export default new ResizeObserverDelegate()
|