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
+8 -8
View File
@@ -3,7 +3,6 @@
*/
import {VOID} from './functions.js';
import FormatType from './format/FormatType.js';
import VectorSource from './source/Vector';
/**
* {@link module:ol/source/Vector} sources use a function of this type to
@@ -17,7 +16,7 @@ import VectorSource from './source/Vector';
*
* The function is responsible for loading the features and adding them to the
* source.
* @typedef {function(this:(VectorSource|import("./VectorTile.js").default), import("./extent.js").Extent, number,
* @typedef {function(this:(import("./source/Vector").default|import("./VectorTile.js").default), import("./extent.js").Extent, number,
* import("./proj/Projection.js").default)} FeatureLoader
* @api
*/
@@ -39,10 +38,10 @@ import VectorSource from './source/Vector';
/**
* @param {string|FeatureUrlFunction} url Feature URL service.
* @param {import("./format/Feature.js").default} format Feature format.
* @param {function(this:import("./VectorTile.js").default, Array<import("./Feature.js").default>, import("./proj/Projection.js").default, import("./extent.js").Extent)|function(this:VectorSource, Array<import("./Feature.js").default>)} success
* @param {function(this:import("./VectorTile.js").default, Array<import("./Feature.js").default>, import("./proj/Projection.js").default, import("./extent.js").Extent)|function(this:import("./source/Vector").default, Array<import("./Feature.js").default>)} success
* Function called with the loaded features and optionally with the data
* projection. Called with the vector tile or source as `this`.
* @param {function(this:import("./VectorTile.js").default)|function(this:VectorSource)} failure
* @param {function(this:import("./VectorTile.js").default)|function(this:import("./source/Vector").default)} failure
* Function called when loading failed. Called with the vector tile or
* source as `this`.
* @return {FeatureLoader} The feature loader.
@@ -53,7 +52,7 @@ export function loadFeaturesXhr(url, format, success, failure) {
* @param {import("./extent.js").Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {import("./proj/Projection.js").default} projection Projection.
* @this {VectorSource|import("./VectorTile.js").default}
* @this {import("./source/Vector").default|import("./VectorTile.js").default}
*/
function(extent, resolution, projection) {
const xhr = new XMLHttpRequest();
@@ -121,11 +120,12 @@ export function xhr(url, format) {
* @param {Array<import("./Feature.js").default>} features The loaded features.
* @param {import("./proj/Projection.js").default} dataProjection Data
* projection.
* @this {VectorSource|import("./VectorTile.js").default}
* @this {import("./source/Vector").default|import("./VectorTile.js").default}
*/
function(features, dataProjection) {
if (this instanceof VectorSource) {
this.addFeatures(features);
const sourceOrTile = /** @type {?} */ (this);
if (typeof sourceOrTile.addFeatures === 'function') {
/** @type {import("./source/Vector").default} */ (sourceOrTile).addFeatures(features);
}
}, /* FIXME handle error */ VOID);
}