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() {
|
disconnectedCallback() {
|
||||||
for (const [el, entry] of getChildren(this) ?? []) {
|
for (const [el, type] of getChildren(this) ?? []) {
|
||||||
if (entry.type === 'popup') this.#obj?.unbindPopup();
|
if (type === 'popup') this.#obj?.unbindPopup();
|
||||||
else if (entry.type === 'tooltip') this.#obj?.unbindTooltip();
|
else if (type === 'tooltip') this.#obj?.unbindTooltip();
|
||||||
else if (entry.type === 'layer') this.#obj?.removeLayer(el as unknown as Layer);
|
else if (type === 'layer') this.#obj?.removeLayer(el as unknown as Layer);
|
||||||
}
|
}
|
||||||
unregisterChildren(this);
|
unregisterChildren(this);
|
||||||
this.#obj?.remove();
|
this.#obj?.remove();
|
||||||
|
|||||||
@ -37,10 +37,10 @@ export class LeafletGeoJSON extends WithProps(HTMLElement, PROPS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
for (const [el, entry] of getChildren(this) ?? []) {
|
for (const [el, type] of getChildren(this) ?? []) {
|
||||||
if (entry.type === 'popup') this.#obj?.unbindPopup();
|
if (type === 'popup') this.#obj?.unbindPopup();
|
||||||
else if (entry.type === 'tooltip') this.#obj?.unbindTooltip();
|
else if (type === 'tooltip') this.#obj?.unbindTooltip();
|
||||||
else if (entry.type === 'layer') this.#obj?.removeLayer(el as unknown as Layer);
|
else if (type === 'layer') this.#obj?.removeLayer(el as unknown as Layer);
|
||||||
}
|
}
|
||||||
unregisterChildren(this);
|
unregisterChildren(this);
|
||||||
this.#obj?.remove();
|
this.#obj?.remove();
|
||||||
|
|||||||
@ -15,10 +15,10 @@ export class LeafletLayerGroup extends HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
for (const [el, entry] of getChildren(this) ?? []) {
|
for (const [el, type] of getChildren(this) ?? []) {
|
||||||
if (entry.type === 'popup') this.#obj?.unbindPopup();
|
if (type === 'popup') this.#obj?.unbindPopup();
|
||||||
else if (entry.type === 'tooltip') this.#obj?.unbindTooltip();
|
else if (type === 'tooltip') this.#obj?.unbindTooltip();
|
||||||
else if (entry.type === 'layer') this.#obj?.removeLayer(el as unknown as Layer);
|
else if (type === 'layer') this.#obj?.removeLayer(el as unknown as Layer);
|
||||||
}
|
}
|
||||||
unregisterChildren(this);
|
unregisterChildren(this);
|
||||||
this.#obj?.remove();
|
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 --
|
// Tracks whether a child registered as a plain layer, popup, or tooltip --
|
||||||
// used by the controls panel and by cleanup logic.
|
// used by the controls panel and by cleanup logic.
|
||||||
type ChildEntry = {
|
type ChildEntry = 'layer' | 'popup' | 'tooltip';
|
||||||
type: 'layer' | 'popup' | 'tooltip';
|
|
||||||
};
|
|
||||||
|
|
||||||
// Builds the event handler for a given parent layer. On each
|
// Builds the event handler for a given parent layer. On each
|
||||||
// leaflet-register event from a descendant, it checks the Leaflet type:
|
// 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) {
|
if (obj instanceof Popup) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
layer.bindPopup(obj);
|
layer.bindPopup(obj);
|
||||||
children.set(el, { type: 'popup' });
|
children.set(el, 'popup');
|
||||||
} else if (obj instanceof Tooltip) {
|
} else if (obj instanceof Tooltip) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
layer.bindTooltip(obj);
|
layer.bindTooltip(obj);
|
||||||
children.set(el, { type: 'tooltip' });
|
children.set(el, 'tooltip');
|
||||||
} else if (obj instanceof Layer && 'addLayer' in layer) {
|
} else if (obj instanceof Layer && 'addLayer' in layer) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
(layer as unknown as LayerGroup).addLayer(obj);
|
(layer as unknown as LayerGroup).addLayer(obj);
|
||||||
children.set(el, { type: 'layer' });
|
children.set(el, 'layer');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user