Convert the DOMCMapReaderFactory to an ES6 class

Given that we only create *one* instance of this class per `getDocument` call, this shouldn't matter performance wise.
This commit is contained in:
Jonas Jenwald 2017-05-05 17:55:02 +02:00
parent 15425d5b9b
commit 32baa6af7a
2 changed files with 47 additions and 53 deletions
src/display
test/unit

@ -52,22 +52,20 @@ DOMCanvasFactory.prototype = {
}
};
var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
function DOMCMapReaderFactory(params) {
this.baseUrl = params.baseUrl || null;
this.isCompressed = params.isCompressed || false;
class DOMCMapReaderFactory {
constructor({ baseUrl = null, isCompressed = false, }) {
this.baseUrl = baseUrl;
this.isCompressed = isCompressed;
}
DOMCMapReaderFactory.prototype = {
fetch(params) {
var name = params.name;
fetch({ name, }) {
if (!name) {
return Promise.reject(new Error('CMap name must be specified.'));
}
return new Promise((resolve, reject) => {
var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');
let url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');
var request = new XMLHttpRequest();
let request = new XMLHttpRequest();
request.open('GET', url, true);
if (this.isCompressed) {
@ -78,7 +76,7 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
return;
}
if (request.status === 200 || request.status === 0) {
var data;
let data;
if (this.isCompressed && request.response) {
data = new Uint8Array(request.response);
} else if (!this.isCompressed && request.responseText) {
@ -100,11 +98,8 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() {
request.send(null);
});
},
};
return DOMCMapReaderFactory;
})();
}
}
/**
* Optimised CSS custom property getter/setter.

@ -16,20 +16,19 @@
import { CMapCompressionType } from '../../src/shared/util';
class NodeCMapReaderFactory {
constructor(params) {
this.baseUrl = params.baseUrl || null;
this.isCompressed = params.isCompressed || false;
constructor({ baseUrl = null, isCompressed = false, }) {
this.baseUrl = baseUrl;
this.isCompressed = isCompressed;
}
fetch(params) {
var name = params.name;
fetch({ name, }) {
if (!name) {
return Promise.reject(new Error('CMap name must be specified.'));
}
return new Promise((resolve, reject) => {
var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');
let url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : '');
var fs = require('fs');
let fs = require('fs');
fs.readFile(url, (error, data) => {
if (error || !data) {
reject(new Error('Unable to load ' +