1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

add destroy methods

This commit is contained in:
Fred Chasen 2017-02-10 15:29:20 -05:00
parent 265df07917
commit db727b00a9
11 changed files with 183 additions and 4 deletions

View file

@ -20,7 +20,7 @@
<script> <script>
var currentSectionIndex = 8; var currentSectionIndex = 8;
// Load the opf // Load the opf
var book = ePub("http://localhost:8080/books/1456.epub"); var book = ePub("http://localhost:8080/books/moby-dick.epub");
var rendition = book.renderTo("viewer", { var rendition = book.renderTo("viewer", {
width: "100%", width: "100%",
height: 600 height: 600
@ -88,6 +88,11 @@
console.log(location); console.log(location);
}); });
window.addEventListener("unload", function () {
console.log("unloading");
this.book.destroy();
});
</script> </script>
</body> </body>

View file

@ -11,8 +11,10 @@ class Archive {
constructor() { constructor() {
this.zip = undefined; this.zip = undefined;
this.checkRequirements();
this.urlCache = {}; this.urlCache = {};
this.checkRequirements();
} }
/** /**
@ -243,6 +245,13 @@ class Archive {
var fromCache = this.urlCache[url]; var fromCache = this.urlCache[url];
if(fromCache) _URL.revokeObjectURL(fromCache); if(fromCache) _URL.revokeObjectURL(fromCache);
} }
destroy() {
this.urlCache.forEach((fromCache) => _URL.revokeObjectURL(fromCache));
this.zip = undefined;
this.urlCache = {};
}
} }
export default Archive; export default Archive;

View file

@ -8,6 +8,10 @@ import {qs} from "./utils/core";
*/ */
class Container { class Container {
constructor(containerDocument) { constructor(containerDocument) {
this.packagePath = '';
this.directory = '';
this.encoding = '';
if (containerDocument) { if (containerDocument) {
this.parse(containerDocument); this.parse(containerDocument);
} }
@ -35,6 +39,12 @@ class Container {
this.directory = path.dirname(this.packagePath); this.directory = path.dirname(this.packagePath);
this.encoding = containerDocument.xmlEncoding; this.encoding = containerDocument.xmlEncoding;
} }
destroy() {
this.packagePath = undefined;
this.directory = undefined;
this.encoding = undefined;
}
} }
export default Container; export default Container;

View file

@ -23,6 +23,10 @@ class Locations {
this.break = 150; this.break = 150;
this._current = 0; this._current = 0;
this.currentLocation = '';
this._currentCfi ='';
this.processingTimeout = undefined;
} }
/** /**
@ -76,7 +80,7 @@ class Locations {
section.unload(); section.unload();
setTimeout(() => completed.resolve(locations), this.pause); this.processingTimeout = setTimeout(() => completed.resolve(locations), this.pause);
return completed.promise; return completed.promise;
}.bind(this)); }.bind(this));
@ -257,6 +261,26 @@ class Locations {
length () { length () {
return this._locations.length; return this._locations.length;
} }
destroy () {
this.spine = undefined;
this.request = undefined;
this.pause = undefined;
this.q.clear();
this.q = undefined;
this.epubcfi = undefined;
this._locations = undefined
this.total = undefined;
this.break = undefined;
this._current = undefined;
this.currentLocation = undefined;
this._currentCfi = undefined;
clearTimeout(this.processingTimeout);
}
} }
EventEmitter(Locations.prototype); EventEmitter(Locations.prototype);

View file

@ -7,6 +7,14 @@ import {qs, qsa, qsp} from "./utils/core";
*/ */
class Packaging { class Packaging {
constructor(packageDocument) { constructor(packageDocument) {
this.manifest = {};
this.navPath = '';
this.ncxPath = '';
this.coverPath = '';
this.spineNodeIndex = 0;
this.spine = [];
this.metadata = {};
if (packageDocument) { if (packageDocument) {
this.parse(packageDocument); this.parse(packageDocument);
} }
@ -273,6 +281,16 @@ class Packaging {
return ""; return "";
} }
destroy() {
this.manifest = undefined;
this.navPath = undefined;
this.ncxPath = undefined;
this.coverPath = undefined;
this.spineNodeIndex = undefined;
this.spine = undefined;
this.metadata = undefined;
}
} }
export default Packaging; export default Packaging;

View file

@ -17,6 +17,14 @@ class PageList {
this.locations = []; this.locations = [];
this.epubcfi = new EpubCFI(); this.epubcfi = new EpubCFI();
this.firstPage = 0;
this.lastPage = 0;
this.totalPages = 0;
this.toc = undefined;
this.ncx = undefined;
this.lastPage
if (xml) { if (xml) {
this.pageList = this.parse(xml); this.pageList = this.parse(xml);
} }
@ -250,6 +258,17 @@ class PageList {
var percentage = this.percentageFromPage(pg); var percentage = this.percentageFromPage(pg);
return percentage; return percentage;
} }
destroy() {
this.pages = undefined;
this.locations = undefined;
this.epubcfi = undefined;
this.pageList = undefined;
this.toc = undefined;
this.ncx = undefined;
}
} }
export default PageList; export default PageList;

View file

@ -514,8 +514,29 @@ class Rendition {
destroy(){ destroy(){
// Clear the queue // Clear the queue
this.q.clear(); this.q.clear();
this.q = undefined;
this.manager.destroy(); this.book = book;
this.views = null;
this.hooks.display.clear();
this.hooks.serialize.clear();
this.hooks.content.clear();
this.hooks.layout.clear();
this.hooks.render.clear();
this.hooks.show.clear();
this.hooks = {};
this.themes.destroy();
this.themes = undefined;
this.epubcfi = undefined;
this.starting = undefined;
this.started = undefined;
this.manager && this.manager.destroy();
} }
/** /**

View file

@ -27,6 +27,13 @@ class Resources {
this.replacementUrls = []; this.replacementUrls = [];
this.html = [];
this.assets = [];
this.css = [];
this.urls = [];
this.cssUrls = [];
this.split(); this.split();
this.splitUrls(); this.splitUrls();
} }
@ -259,6 +266,19 @@ class Resources {
} }
return substitute(content, relUrls, this.replacementUrls); return substitute(content, relUrls, this.replacementUrls);
} }
destroy() {
this.settings = undefined;
this.manifest = undefined;
this.resources = undefined;
this.replacementUrls = undefined;
this.html = undefined;
this.assets = undefined;
this.css = undefined;
this.urls = undefined;
this.cssUrls = undefined;
}
} }
export default Resources; export default Resources;

View file

@ -171,11 +171,32 @@ class Section {
return new EpubCFI(el, this.cfiBase).toString(); return new EpubCFI(el, this.cfiBase).toString();
} }
/**
* Unload the section document
*/
unload() { unload() {
this.document = undefined; this.document = undefined;
this.contents = undefined; this.contents = undefined;
this.output = undefined; this.output = undefined;
} }
destroy() {
this.unload();
this.hooks.serialize.clear();
this.hooks.content.clear();
this.hooks = undefined;
this.idref = undefined;
this.linear = undefined;
this.properties = undefined;
this.index = undefined;
this.href = undefined;
this.url = undefined;
this.next = undefined;
this.prev = undefined;
this.cfiBase = undefined;
}
} }
export default Section; export default Section;

View file

@ -23,6 +23,12 @@ class Spine {
this.epubcfi = new EpubCFI(); this.epubcfi = new EpubCFI();
this.loaded = false; this.loaded = false;
this.items = undefined;
this.manifest = undefined;
this.spineNodeIndex = undefined;
this.baseUrl = undefined;
this.length = undefined;
} }
/** /**
@ -158,7 +164,25 @@ class Spine {
} }
destroy() { destroy() {
this.each((section) => section.destroy());
this.spineItems = undefined
this.spineByHref = undefined
this.spineById = undefined
this.hooks.serialize.clear();
this.hooks.content.clear();
this.hooks = undefined;
this.epubcfi = undefined;
this.loaded = false;
this.items = undefined;
this.manifest = undefined;
this.spineNodeIndex = undefined;
this.baseUrl = undefined;
this.length = undefined;
} }
} }

View file

@ -151,6 +151,14 @@ class Themes {
this.override("font-size", size); this.override("font-size", size);
} }
destroy() {
this.rendition = undefined;
this._themes = undefined;
this._overrides = undefined;
this._current = undefined;
this._injected = undefined;
}
} }
export default Themes; export default Themes;