Merge pull request #9409 from fredj/rm_opt_this
Remove more opt_this parameters
This commit is contained in:
@@ -4,6 +4,16 @@
|
||||
|
||||
#### Backwards incompatible changes
|
||||
|
||||
#### Removal of optional this arguments
|
||||
|
||||
The optional this (i.e. opt_this) arguments were removed from the following methods.
|
||||
Please use closures, the es6 arrow function or the bind method to achieve this effect (Bind is explained here:
|
||||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
|
||||
|
||||
* `forEachCorner` in `ol/extent`
|
||||
* `LRUCache#forEach`
|
||||
* `RBush#forEach` and `RBush#forEachInExtent`
|
||||
|
||||
##### The `setCenter`, `setZoom`, `setResolution` and `setRotation` methods on `ol/View` do not bypass constraints anymore
|
||||
|
||||
Previously, these methods allowed setting values that were inconsistent with the given view constraints.
|
||||
|
||||
@@ -44,7 +44,7 @@ class TileCache extends LRUCache {
|
||||
this.remove(getKey(tile.tileCoord));
|
||||
tile.dispose();
|
||||
}
|
||||
}, this);
|
||||
}.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -400,26 +400,25 @@ export function extendXY(extent, x, y) {
|
||||
* callback returns a truthy value the function returns that value
|
||||
* immediately. Otherwise the function returns `false`.
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {function(this:T, import("./coordinate.js").Coordinate): S} callback Callback.
|
||||
* @param {T=} opt_this Value to use as `this` when executing `callback`.
|
||||
* @param {function(import("./coordinate.js").Coordinate): S} callback Callback.
|
||||
* @return {S|boolean} Value.
|
||||
* @template S, T
|
||||
* @template S
|
||||
*/
|
||||
export function forEachCorner(extent, callback, opt_this) {
|
||||
export function forEachCorner(extent, callback) {
|
||||
let val;
|
||||
val = callback.call(opt_this, getBottomLeft(extent));
|
||||
val = callback(getBottomLeft(extent));
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
val = callback.call(opt_this, getBottomRight(extent));
|
||||
val = callback(getBottomRight(extent));
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
val = callback.call(opt_this, getTopRight(extent));
|
||||
val = callback(getTopRight(extent));
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
val = callback.call(opt_this, getTopLeft(extent));
|
||||
val = callback(getTopLeft(extent));
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class Circle extends SimpleGeometry {
|
||||
return true;
|
||||
}
|
||||
|
||||
return forEachCorner(extent, this.intersectsCoordinate, this);
|
||||
return forEachCorner(extent, this.intersectsCoordinate.bind(this));
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
@@ -485,7 +485,7 @@ class VectorSource extends Source {
|
||||
}
|
||||
} else {
|
||||
if (this.featuresRtree_) {
|
||||
this.featuresRtree_.forEach(this.removeFeatureInternal, this);
|
||||
this.featuresRtree_.forEach(this.removeFeatureInternal.bind(this));
|
||||
for (const id in this.nullGeometryFeatures_) {
|
||||
this.removeFeatureInternal(this.nullGeometryFeatures_[id]);
|
||||
}
|
||||
|
||||
@@ -96,17 +96,15 @@ class LRUCache extends EventTarget {
|
||||
|
||||
|
||||
/**
|
||||
* @param {function(this: S, T, string, LRUCache): ?} f The function
|
||||
* @param {function(T, string, LRUCache): ?} f The function
|
||||
* to call for every entry from the oldest to the newer. This function takes
|
||||
* 3 arguments (the entry value, the entry key and the LRUCache object).
|
||||
* The return value is ignored.
|
||||
* @param {S=} opt_this The object to use as `this` in `f`.
|
||||
* @template S
|
||||
*/
|
||||
forEach(f, opt_this) {
|
||||
forEach(f) {
|
||||
let entry = this.oldest_;
|
||||
while (entry) {
|
||||
f.call(opt_this, entry.value_, entry.key_, this);
|
||||
f(entry.value_, entry.key_, this);
|
||||
entry = entry.newer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,41 +156,35 @@ class RBush {
|
||||
* Calls a callback function with each value in the tree.
|
||||
* If the callback returns a truthy value, this value is returned without
|
||||
* checking the rest of the tree.
|
||||
* @param {function(this: S, T): *} callback Callback.
|
||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
||||
* @param {function(T): *} callback Callback.
|
||||
* @return {*} Callback return value.
|
||||
* @template S
|
||||
*/
|
||||
forEach(callback, opt_this) {
|
||||
return this.forEach_(this.getAll(), callback, opt_this);
|
||||
forEach(callback) {
|
||||
return this.forEach_(this.getAll(), callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls a callback function with each value in the provided extent.
|
||||
* @param {import("../extent.js").Extent} extent Extent.
|
||||
* @param {function(this: S, T): *} callback Callback.
|
||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
||||
* @param {function(T): *} callback Callback.
|
||||
* @return {*} Callback return value.
|
||||
* @template S
|
||||
*/
|
||||
forEachInExtent(extent, callback, opt_this) {
|
||||
return this.forEach_(this.getInExtent(extent), callback, opt_this);
|
||||
forEachInExtent(extent, callback) {
|
||||
return this.forEach_(this.getInExtent(extent), callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array<T>} values Values.
|
||||
* @param {function(this: S, T): *} callback Callback.
|
||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
||||
* @param {function(T): *} callback Callback.
|
||||
* @private
|
||||
* @return {*} Callback return value.
|
||||
* @template S
|
||||
*/
|
||||
forEach_(values, callback, opt_this) {
|
||||
forEach_(values, callback) {
|
||||
let result;
|
||||
for (let i = 0, l = values.length; i < l; i++) {
|
||||
result = callback.call(opt_this, values[i]);
|
||||
result = callback(values[i]);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -239,13 +239,6 @@ describe('ol.extent', function() {
|
||||
}
|
||||
);
|
||||
|
||||
it('calls the callback with given scope', function() {
|
||||
const extent = [1, 2, 3, 4];
|
||||
const scope = {humpty: 'dumpty'};
|
||||
_ol_extent_.forEachCorner(extent, callbackTrue, scope);
|
||||
expect(callbackTrue.calledOn(scope)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getArea', function() {
|
||||
|
||||
Reference in New Issue
Block a user