Replace instanceof checks with other logic

This commit is contained in:
ahocevar
2018-10-05 16:16:51 +02:00
parent 96e99e481e
commit 9163558511
40 changed files with 232 additions and 268 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
/**
* @module ol/format/XML
*/
import {isDocument, isNode, parse} from '../xml.js';
import {isDocument, parse} from '../xml.js';
/**
* @classdesc
@@ -18,15 +18,15 @@ class XML {
* @api
*/
read(source) {
if (isDocument(source)) {
return this.readFromDocument(/** @type {Document} */ (source));
} else if (isNode(source)) {
return this.readFromNode(/** @type {Element} */ (source));
if (!source) {
return null;
} else if (typeof source === 'string') {
const doc = parse(source);
return this.readFromDocument(doc);
} else if (isDocument(source)) {
return this.readFromDocument(/** @type {Document} */ (source));
} else {
return null;
return this.readFromNode(/** @type {Element} */ (source));
}
}