enable intellisense for the main classes (#10618)

This commit is contained in:
Kyℓe Hensel
2025-02-17 21:35:50 +11:00
committed by GitHub
parent 083d6d04fe
commit f513ccd03d
12 changed files with 87 additions and 20 deletions
+2
View File
@@ -67,12 +67,14 @@ _Breaking developer changes, which may affect downstream projects or sites that
* Fix walkthrough from not correctly registering deleted ways in "Lines" step ([#10776])
#### :rocket: Presets
#### :hammer: Development
* enable Intellisense (IDE auto-completion) for the main classes ([#10618], thanks [@k-yle])
[#7381]: https://github.com/openstreetmap/iD/issues/7381
[#8911]: https://github.com/openstreetmap/iD/pull/8911
[#9634]: https://github.com/openstreetmap/iD/pull/9634
[#9635]: https://github.com/openstreetmap/iD/pull/9635
[#10003]: https://github.com/openstreetmap/iD/pull/10003
[#10618]: https://github.com/openstreetmap/iD/pull/10618
[#10648]: https://github.com/openstreetmap/iD/pull/10648
[#10720]: https://github.com/openstreetmap/iD/issues/10720
[#10722]: https://github.com/openstreetmap/iD/pull/10722
+2 -2
View File
@@ -25,7 +25,7 @@ import { utilKeybinding, utilRebind, utilStringQs, utilCleanOsmString } from '..
export function coreContext() {
const dispatch = d3_dispatch('enter', 'exit', 'change');
let context = utilRebind({}, dispatch, 'on');
const context = {};
let _deferred = new Set();
context.version = packageJSON.version;
@@ -591,5 +591,5 @@ export function coreContext() {
}
};
return context;
return utilRebind(context, dispatch, 'on');
}
+2 -2
View File
@@ -39,7 +39,7 @@ export function coreUploader(context) {
.then(function(d) { _discardTags = d; })
.catch(function() { /* ignore */ });
var uploader = utilRebind({}, dispatch, 'on');
const uploader = {};
uploader.isSaving = function() {
return _isSaving;
@@ -402,5 +402,5 @@ export function coreUploader(context) {
};
return uploader;
return utilRebind(uploader, dispatch, 'on');
}
+2 -2
View File
@@ -10,7 +10,7 @@ import * as Validations from '../validations/index';
export function coreValidator(context) {
let dispatch = d3_dispatch('validated', 'focusedIssue');
let validator = utilRebind({}, dispatch, 'on');
const validator = {};
let _rules = {};
let _disabledRules = {};
@@ -784,7 +784,7 @@ export function coreValidator(context) {
}
return validator;
return utilRebind(validator, dispatch, 'on');
}
+24
View File
@@ -7,6 +7,30 @@ declare global {
declare var before: typeof beforeEach;
declare var after: typeof afterEach;
declare var VITEST: true;
declare type Tags = { [key: string]: string };
declare namespace iD {
export type Context = ReturnType<typeof iD.coreContext>;
export type Graph = InstanceType<typeof iD.coreGraph>;
export type OsmNode = import('./osm/node').OsmNode;
export type OsmWay = import('./osm/way').OsmWay;
export type OsmRelation = import('./osm/relation').OsmRelation;
export type AbstractEntity = InstanceType<typeof iD.osmEntity>;
export type OsmEntity = OsmNode | OsmWay | OsmRelation;
}
declare namespace d3 {
export type Selection<T = any> = import('d3').Selection<
T,
unknown,
unknown,
unknown
>;
}
}
export {};
+1
View File
@@ -80,6 +80,7 @@ osmEntity.deprecatedTagValuesByKey = function(dataDeprecated) {
osmEntity.prototype = {
/** @type {Tags} */
tags: {},
+7 -2
View File
@@ -21,6 +21,10 @@ export const cardinal = {
northnorthwest: 337, nnw: 337
};
/**
* @typedef {typeof prototype & iD.AbstractEntity} OsmNode
* @returns {OsmNode}
*/
export function osmNode() {
if (!(this instanceof osmNode)) {
return (new osmNode()).initialize(arguments);
@@ -33,7 +37,7 @@ osmEntity.node = osmNode;
osmNode.prototype = Object.create(osmEntity.prototype);
Object.assign(osmNode.prototype, {
const prototype = {
type: 'node',
loc: [9999, 9999],
@@ -243,4 +247,5 @@ Object.assign(osmNode.prototype, {
coordinates: this.loc
};
}
});
};
Object.assign(osmNode.prototype, prototype);
+7 -3
View File
@@ -4,7 +4,10 @@ import { osmEntity } from './entity';
import { osmJoinWays } from './multipolygon';
import { geoExtent, geoPolygonContainsPolygon, geoPolygonIntersectsPolygon } from '../geo';
/**
* @typedef {typeof prototype & iD.AbstractEntity} OsmRelation
* @returns {OsmRelation}
*/
export function osmRelation() {
if (!(this instanceof osmRelation)) {
return (new osmRelation()).initialize(arguments);
@@ -28,7 +31,7 @@ osmRelation.creationOrder = function(a, b) {
};
Object.assign(osmRelation.prototype, {
const prototype = {
type: 'relation',
members: [],
@@ -363,4 +366,5 @@ Object.assign(osmRelation.prototype, {
return result;
}
});
};
Object.assign(osmRelation.prototype, prototype);
+7 -3
View File
@@ -6,7 +6,10 @@ import { osmLanes } from './lanes';
import { osmTagSuggestingArea, osmRightSideIsInsideTags, osmRemoveLifecyclePrefix, osmOneWayBiDirectionalTags, osmOneWayBackwardTags, osmOneWayForwardTags, osmOneWayTags } from './tags';
import { utilArrayUniq, utilCheckTagDictionary } from '../util';
/**
* @typedef {typeof prototype & iD.AbstractEntity} OsmWay
* @returns {OsmWay}
*/
export function osmWay() {
if (!(this instanceof osmWay)) {
return (new osmWay()).initialize(arguments);
@@ -21,7 +24,7 @@ osmEntity.way = osmWay;
osmWay.prototype = Object.create(osmEntity.prototype);
Object.assign(osmWay.prototype, {
const prototype = {
type: 'way',
nodes: [],
@@ -536,7 +539,8 @@ Object.assign(osmWay.prototype, {
return isNaN(area) ? 0 : area;
});
}
});
};
Object.assign(osmWay.prototype, prototype);
// Filter function to eliminate consecutive duplicates.
+2 -2
View File
@@ -8,7 +8,7 @@ import { utilArrayGroupBy, utilArrayUnion, utilQsString, utilStringQs } from '..
export function rendererFeatures(context) {
var dispatch = d3_dispatch('change', 'redraw');
var features = utilRebind({}, dispatch, 'on');
const features = {};
var _deferred = new Set();
var traffic_roads = {
@@ -616,5 +616,5 @@ export function rendererFeatures(context) {
});
return features;
return utilRebind(features, dispatch, 'on');
}
+12 -4
View File
@@ -1,8 +1,16 @@
// Copies a variable number of methods from source to target.
export function utilRebind(target, source) {
var i = 1, n = arguments.length, method;
while (++i < n) {
target[method = arguments[i]] = d3_rebind(target, source, source[method]);
/**
* @template T
* @template S
* @template {keyof S} Args
* @param {T} target
* @param {S} source
* @param {...Args} args
* @returns {T & Pick<S, Args>}
*/
export function utilRebind(target, source, ...args) {
for (const method of args) {
target[method] = d3_rebind(target, source, source[method]);
}
return target;
}
+19
View File
@@ -0,0 +1,19 @@
describe('utilRebind', () => {
it('copies methods from source to target', () => {
const target = { original: 123 };
const source = new class {
value = 456;
method() {
return this.value;
}
};
const copied = iD.utilRebind(target, source, 'method');
expect(copied).toStrictEqual({
original: 123,
method: expect.any(Function)
});
expect(copied.method()).toBe(456);
});
});