mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Unload section when destroying the renderer
This commit is contained in:
+8
-1
@@ -151,6 +151,7 @@ const makeMarginals = (length, part) => Array.from({ length }, () => {
|
||||
})
|
||||
|
||||
class View {
|
||||
#observer = new ResizeObserver(() => this.expand())
|
||||
#element = document.createElement('div')
|
||||
#iframe = document.createElement('iframe')
|
||||
#contentRange = document.createRange()
|
||||
@@ -212,7 +213,7 @@ class View {
|
||||
const layout = beforeRender?.({ vertical, rtl, background })
|
||||
this.#iframe.style.display = 'block'
|
||||
this.render(layout)
|
||||
new ResizeObserver(() => this.expand()).observe(doc.body)
|
||||
this.#observer.observe(doc.body)
|
||||
|
||||
// the resize observer above doesn't work in Firefox
|
||||
// (see https://bugzilla.mozilla.org/show_bug.cgi?id=1832939)
|
||||
@@ -352,6 +353,9 @@ class View {
|
||||
get overlayer() {
|
||||
return this.#overlayer
|
||||
}
|
||||
destroy() {
|
||||
if (this.document) this.#observer.unobserve(this.document.body)
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: everything here assumes the so-called "negative scroll type" for RTL
|
||||
@@ -941,6 +945,9 @@ export class Paginator extends HTMLElement {
|
||||
}
|
||||
destroy() {
|
||||
this.#observer.unobserve(this)
|
||||
this.#view.destroy()
|
||||
this.#view = null
|
||||
this.sections[this.#index]?.unload?.()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user