Skip to content

change osmEntity.key() from a static method to a instance method#12212

Open
k-yle wants to merge 1 commit intodevelopfrom
kh/osmEntity7
Open

change osmEntity.key() from a static method to a instance method#12212
k-yle wants to merge 1 commit intodevelopfrom
kh/osmEntity7

Conversation

@k-yle
Copy link
Copy Markdown
Collaborator

@k-yle k-yle commented Apr 16, 2026

part 7 of #10909.

this is the last PR for the preëmptive work ! after that is should be easy to convert osmEntity it to an ES6 Class. i might try this tonight.


in this PR: we replace a static function osmEntity.key(...) with a class method, so that:

  • it matches every other class method
  • we don't need to import osmEntity is as many files
  • it removes another random thing which was attached to this abstract class, to make it easier to refactor this file in the next PR

@k-yle k-yle added the chore Improvements to the iD development experience or codebase label Apr 16, 2026
Comment thread modules/svg/points.js Outdated
// Avoid exit/enter if we're just moving stuff around.
// The node will get a new version but we only need to run the update selection.
function fastEntityKey(d) {
if (typeof d === 'number') return d;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to add this line, because there was an minor "bug": this function was being passed a number sometimes, which caused osmEntity.key() to return "undefinedv0".

same reason for adding the instanceof guard added in the file above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function was being passed a number sometimes

I tried to find out how/when this would be the case, but could not find any reason why it would ever be anything else than an osm entity. Any hints about how to trigger this "bug"?

@k-yle k-yle marked this pull request as draft April 16, 2026 12:33
@k-yle k-yle marked this pull request as ready for review April 16, 2026 12:50
Copy link
Copy Markdown
Member

@tyrasd tyrasd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it matches every other class method

I believe that the method was implemented as a static method on purpose to make using it with d3's .data easier: .data(…, osmEntity.key). I'm actually not sure if it is better suited as a instance method or for as a static function somewhere. Speaking of it: I see that this method is currently also present in the new osmIdManager, but never used. Maybe it can also live there (either by renaming the manager to osmEntityManager to reflect the more generic usage, or factoring it out to a simple exported function getOsmEntityD3Key that only does that)? Anyway, one of the two methods should be removed.

Another thing: The naming of this method as key was IMHO quite unfortunate, as the association with the OSM term "tag key" is potentially confusing. Here it is not as quite as bad, but there are some other modules (e.g. ui/fields/combo.js) where it is super perplexing that the key property is assigned to a tag value: when in half of that line, key is meant to be an index for d3, and in the other half on is talking about key-values pairs of a tag. 🤷

As we're touching all of the occurrences of this method here anyway: what do you think about renaming this to something a little less confusing. Maybe index could work? Or d3_key??

Comment thread modules/svg/points.js Outdated
// Avoid exit/enter if we're just moving stuff around.
// The node will get a new version but we only need to run the update selection.
function fastEntityKey(d) {
if (typeof d === 'number') return d;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function was being passed a number sometimes

I tried to find out how/when this would be the case, but could not find any reason why it would ever be anything else than an osm entity. Any hints about how to trigger this "bug"?

@tyrasd
Copy link
Copy Markdown
Member

tyrasd commented May 7, 2026

small ping @k-yle ⬆️ 😊

@k-yle k-yle force-pushed the kh/osmEntity7 branch from ff96c0f to 585542c Compare May 8, 2026 13:24
@k-yle
Copy link
Copy Markdown
Collaborator Author

k-yle commented May 8, 2026

sorry, i missed this notification amongst the dependabot spam 😆

I've simplified this to use the identical method from osmIdManager. then we can deal with the undefinedv0 issue in a seperate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Improvements to the iD development experience or codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants