1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

Add section unload, pause on generation between generation of locations

This commit is contained in:
Fred Chasen 2017-01-25 17:45:10 -05:00
parent ac1bb6fa23
commit d6eeb2a458
3 changed files with 20 additions and 4 deletions

View file

@ -1,4 +1,4 @@
import {qs, sprint, locationOf} from "./utils/core";
import {qs, sprint, locationOf, defer} from "./utils/core";
import Queue from "./utils/queue";
import EpubCFI from "./epubcfi";
import EventEmitter from "event-emitter";
@ -9,9 +9,10 @@ import EventEmitter from "event-emitter";
* @param {request} request
*/
class Locations {
constructor(spine, request) {
constructor(spine, request, pause) {
this.spine = spine;
this.request = request;
this.pause = pause || 100;
this.q = new Queue(this);
this.epubcfi = new EpubCFI();
@ -22,7 +23,6 @@ class Locations {
this.break = 150;
this._current = 0;
}
/**
@ -70,8 +70,14 @@ class Locations {
return section.load(this.request)
.then(function(contents) {
var completed = new defer();
var locations = this.parse(contents, section.cfiBase);
this._locations = this._locations.concat(locations);
section.unload();
setTimeout(() => completed.resolve(locations), this.pause);
return completed.promise;
}.bind(this));
}

View file

@ -29,6 +29,10 @@ class Section {
this.hooks.serialize = new Hook(this);
this.hooks.content = new Hook(this);
}
this.document = undefined;
this.contents = undefined;
this.output = undefined;
}
/**
@ -166,6 +170,12 @@ class Section {
cfiFromElement(el) {
return new EpubCFI(el, this.cfiBase).toString();
}
unload() {
this.document = undefined;
this.contents = undefined;
this.output = undefined;
}
}
export default Section;