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
|
#### 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
|
##### 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.
|
Previously, these methods allowed setting values that were inconsistent with the given view constraints.
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ class TileCache extends LRUCache {
|
|||||||
this.remove(getKey(tile.tileCoord));
|
this.remove(getKey(tile.tileCoord));
|
||||||
tile.dispose();
|
tile.dispose();
|
||||||
}
|
}
|
||||||
}, this);
|
}.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -400,26 +400,25 @@ export function extendXY(extent, x, y) {
|
|||||||
* callback returns a truthy value the function returns that value
|
* callback returns a truthy value the function returns that value
|
||||||
* immediately. Otherwise the function returns `false`.
|
* immediately. Otherwise the function returns `false`.
|
||||||
* @param {Extent} extent Extent.
|
* @param {Extent} extent Extent.
|
||||||
* @param {function(this:T, import("./coordinate.js").Coordinate): S} callback Callback.
|
* @param {function(import("./coordinate.js").Coordinate): S} callback Callback.
|
||||||
* @param {T=} opt_this Value to use as `this` when executing `callback`.
|
|
||||||
* @return {S|boolean} Value.
|
* @return {S|boolean} Value.
|
||||||
* @template S, T
|
* @template S
|
||||||
*/
|
*/
|
||||||
export function forEachCorner(extent, callback, opt_this) {
|
export function forEachCorner(extent, callback) {
|
||||||
let val;
|
let val;
|
||||||
val = callback.call(opt_this, getBottomLeft(extent));
|
val = callback(getBottomLeft(extent));
|
||||||
if (val) {
|
if (val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
val = callback.call(opt_this, getBottomRight(extent));
|
val = callback(getBottomRight(extent));
|
||||||
if (val) {
|
if (val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
val = callback.call(opt_this, getTopRight(extent));
|
val = callback(getTopRight(extent));
|
||||||
if (val) {
|
if (val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
val = callback.call(opt_this, getTopLeft(extent));
|
val = callback(getTopLeft(extent));
|
||||||
if (val) {
|
if (val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class Circle extends SimpleGeometry {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return forEachCorner(extent, this.intersectsCoordinate, this);
|
return forEachCorner(extent, this.intersectsCoordinate.bind(this));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ class VectorSource extends Source {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.featuresRtree_) {
|
if (this.featuresRtree_) {
|
||||||
this.featuresRtree_.forEach(this.removeFeatureInternal, this);
|
this.featuresRtree_.forEach(this.removeFeatureInternal.bind(this));
|
||||||
for (const id in this.nullGeometryFeatures_) {
|
for (const id in this.nullGeometryFeatures_) {
|
||||||
this.removeFeatureInternal(this.nullGeometryFeatures_[id]);
|
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
|
* 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).
|
* 3 arguments (the entry value, the entry key and the LRUCache object).
|
||||||
* The return value is ignored.
|
* 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_;
|
let entry = this.oldest_;
|
||||||
while (entry) {
|
while (entry) {
|
||||||
f.call(opt_this, entry.value_, entry.key_, this);
|
f(entry.value_, entry.key_, this);
|
||||||
entry = entry.newer;
|
entry = entry.newer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-15
@@ -156,41 +156,35 @@ class RBush {
|
|||||||
* Calls a callback function with each value in the tree.
|
* Calls a callback function with each value in the tree.
|
||||||
* If the callback returns a truthy value, this value is returned without
|
* If the callback returns a truthy value, this value is returned without
|
||||||
* checking the rest of the tree.
|
* checking the rest of the tree.
|
||||||
* @param {function(this: S, T): *} callback Callback.
|
* @param {function(T): *} callback Callback.
|
||||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
|
||||||
* @return {*} Callback return value.
|
* @return {*} Callback return value.
|
||||||
* @template S
|
|
||||||
*/
|
*/
|
||||||
forEach(callback, opt_this) {
|
forEach(callback) {
|
||||||
return this.forEach_(this.getAll(), callback, opt_this);
|
return this.forEach_(this.getAll(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls a callback function with each value in the provided extent.
|
* Calls a callback function with each value in the provided extent.
|
||||||
* @param {import("../extent.js").Extent} extent Extent.
|
* @param {import("../extent.js").Extent} extent Extent.
|
||||||
* @param {function(this: S, T): *} callback Callback.
|
* @param {function(T): *} callback Callback.
|
||||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
|
||||||
* @return {*} Callback return value.
|
* @return {*} Callback return value.
|
||||||
* @template S
|
|
||||||
*/
|
*/
|
||||||
forEachInExtent(extent, callback, opt_this) {
|
forEachInExtent(extent, callback) {
|
||||||
return this.forEach_(this.getInExtent(extent), callback, opt_this);
|
return this.forEach_(this.getInExtent(extent), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<T>} values Values.
|
* @param {Array<T>} values Values.
|
||||||
* @param {function(this: S, T): *} callback Callback.
|
* @param {function(T): *} callback Callback.
|
||||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
|
||||||
* @private
|
* @private
|
||||||
* @return {*} Callback return value.
|
* @return {*} Callback return value.
|
||||||
* @template S
|
|
||||||
*/
|
*/
|
||||||
forEach_(values, callback, opt_this) {
|
forEach_(values, callback) {
|
||||||
let result;
|
let result;
|
||||||
for (let i = 0, l = values.length; i < l; i++) {
|
for (let i = 0, l = values.length; i < l; i++) {
|
||||||
result = callback.call(opt_this, values[i]);
|
result = callback(values[i]);
|
||||||
if (result) {
|
if (result) {
|
||||||
return 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() {
|
describe('getArea', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user