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.
This commit is contained in:
parent
2a1b56c6e3
commit
301f223938
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<HTMLElement, Chi
|
||||
if (obj instanceof Popup) {
|
||||
e.stopPropagation();
|
||||
layer.bindPopup(obj);
|
||||
children.set(el, { type: 'popup' });
|
||||
children.set(el, 'popup');
|
||||
} else if (obj instanceof Tooltip) {
|
||||
e.stopPropagation();
|
||||
layer.bindTooltip(obj);
|
||||
children.set(el, { type: 'tooltip' });
|
||||
children.set(el, 'tooltip');
|
||||
} else if (obj instanceof Layer && 'addLayer' in layer) {
|
||||
e.stopPropagation();
|
||||
(layer as unknown as LayerGroup).addLayer(obj);
|
||||
children.set(el, { type: 'layer' });
|
||||
children.set(el, 'layer');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user