This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
/**
|
|
* @module ol/functions
|
|
*/
|
|
|
|
import {equals as arrayEquals} from './array.js';
|
|
|
|
/**
|
|
* Always returns true.
|
|
* @returns {boolean} true.
|
|
*/
|
|
export function TRUE() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Always returns false.
|
|
* @returns {boolean} false.
|
|
*/
|
|
export function FALSE() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* A reusable function, used e.g. as a default for callbacks.
|
|
*
|
|
* @return {void} Nothing.
|
|
*/
|
|
export function VOID() {}
|
|
|
|
/**
|
|
* Wrap a function in another function that remembers the last return. If the
|
|
* returned function is called twice in a row with the same arguments and the same
|
|
* this object, it will return the value from the first call in the second call.
|
|
*
|
|
* @param {function(...any): ReturnType} fn The function to memoize.
|
|
* @return {function(...any): ReturnType} The memoized function.
|
|
* @template ReturnType
|
|
*/
|
|
export function memoizeOne(fn) {
|
|
let called = false;
|
|
|
|
/** @type {ReturnType} */
|
|
let lastResult;
|
|
|
|
/** @type {Array<any>} */
|
|
let lastArgs;
|
|
|
|
let lastThis;
|
|
|
|
return function () {
|
|
const nextArgs = Array.prototype.slice.call(arguments);
|
|
if (!called || this !== lastThis || !arrayEquals(nextArgs, lastArgs)) {
|
|
called = true;
|
|
lastThis = this;
|
|
lastArgs = nextArgs;
|
|
lastResult = fn.apply(this, arguments);
|
|
}
|
|
return lastResult;
|
|
};
|
|
}
|