From 301f223938f5186198a311c16b5dea14cb1b2a12 Mon Sep 17 00:00:00 2001 From: Buddy Date: Wed, 10 Jun 2026 21:57:06 -0700 Subject: [PATCH] refactor: simplify ChildEntry from object to union type Change ChildEntry from { type: 'layer'|'popup'|'tooltip' } to just the union string, eliminating the wrapper object. Update Map.set calls in createChildRegisterHandler and destructuring in leaflet-layer-group, leaflet-feature-group, and leaflet-geojson disconnectedCallback. --- src/components/leaflet-feature-group.ts | 8 ++++---- src/components/leaflet-geojson.ts | 8 ++++---- src/components/leaflet-layer-group.ts | 8 ++++---- src/core/register.ts | 10 ++++------ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/components/leaflet-feature-group.ts b/src/components/leaflet-feature-group.ts index 3f59d96..7d01480 100644 --- a/src/components/leaflet-feature-group.ts +++ b/src/components/leaflet-feature-group.ts @@ -15,10 +15,10 @@ export class LeafletFeatureGroup extends HTMLElement { } disconnectedCallback() { - for (const [el, entry] of getChildren(this) ?? []) { - if (entry.type === 'popup') this.#obj?.unbindPopup(); - else if (entry.type === 'tooltip') this.#obj?.unbindTooltip(); - else if (entry.type === 'layer') this.#obj?.removeLayer(el as unknown as Layer); + for (const [el, type] of getChildren(this) ?? []) { + if (type === 'popup') this.#obj?.unbindPopup(); + else if (type === 'tooltip') this.#obj?.unbindTooltip(); + else if (type === 'layer') this.#obj?.removeLayer(el as unknown as Layer); } unregisterChildren(this); this.#obj?.remove(); diff --git a/src/components/leaflet-geojson.ts b/src/components/leaflet-geojson.ts index 84b432a..df234aa 100644 --- a/src/components/leaflet-geojson.ts +++ b/src/components/leaflet-geojson.ts @@ -37,10 +37,10 @@ export class LeafletGeoJSON extends WithProps(HTMLElement, PROPS) { } disconnectedCallback() { - for (const [el, entry] of getChildren(this) ?? []) { - if (entry.type === 'popup') this.#obj?.unbindPopup(); - else if (entry.type === 'tooltip') this.#obj?.unbindTooltip(); - else if (entry.type === 'layer') this.#obj?.removeLayer(el as unknown as Layer); + for (const [el, type] of getChildren(this) ?? []) { + if (type === 'popup') this.#obj?.unbindPopup(); + else if (type === 'tooltip') this.#obj?.unbindTooltip(); + else if (type === 'layer') this.#obj?.removeLayer(el as unknown as Layer); } unregisterChildren(this); this.#obj?.remove(); diff --git a/src/components/leaflet-layer-group.ts b/src/components/leaflet-layer-group.ts index 74c768d..3d00542 100644 --- a/src/components/leaflet-layer-group.ts +++ b/src/components/leaflet-layer-group.ts @@ -15,10 +15,10 @@ export class LeafletLayerGroup extends HTMLElement { } disconnectedCallback() { - for (const [el, entry] of getChildren(this) ?? []) { - if (entry.type === 'popup') this.#obj?.unbindPopup(); - else if (entry.type === 'tooltip') this.#obj?.unbindTooltip(); - else if (entry.type === 'layer') this.#obj?.removeLayer(el as unknown as Layer); + for (const [el, type] of getChildren(this) ?? []) { + if (type === 'popup') this.#obj?.unbindPopup(); + else if (type === 'tooltip') this.#obj?.unbindTooltip(); + else if (type === 'layer') this.#obj?.removeLayer(el as unknown as Layer); } unregisterChildren(this); this.#obj?.remove(); diff --git a/src/core/register.ts b/src/core/register.ts index d32ce38..a4a22b1 100644 --- a/src/core/register.ts +++ b/src/core/register.ts @@ -33,9 +33,7 @@ export function emitIconChanged(el: HTMLElement, icon: Icon | null | undefined) // Tracks whether a child registered as a plain layer, popup, or tooltip -- // used by the controls panel and by cleanup logic. -type ChildEntry = { - type: 'layer' | 'popup' | 'tooltip'; -}; +type ChildEntry = 'layer' | 'popup' | 'tooltip'; // Builds the event handler for a given parent layer. On each // leaflet-register event from a descendant, it checks the Leaflet type: @@ -49,15 +47,15 @@ function createChildRegisterHandler(layer: Layer, children: Map