Skip to content

Commit 74235ab

Browse files
committed
fix: types for slotted children
1 parent ccbc228 commit 74235ab

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

leaflet-map.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ interface FeatureElement extends LeafletBase {
1919
layer: L.LayerGroup | L.Layer;
2020
}
2121

22-
const isFeatureElement = (
22+
function isFeatureElement(
2323
x: Node & Partial<FeatureElement>
24-
): x is Node & FeatureElement => x && 'feature' in x;
24+
): x is FeatureElement {
25+
return x && (x.tagName.startsWith('LEAFLET-') || 'feature' in x);
26+
}
2527

26-
function isSlot(node: ChildNode): node is HTMLSLotElement {
28+
function isSlot(node: ChildNode): node is HTMLSlotElement {
2729
return node instanceof HTMLSlotElement;
2830
}
2931

@@ -364,14 +366,16 @@ export class LeafletMap extends LeafletBase {
364366
return L.latLng(this.latitude, this.longitude);
365367
}
366368

367-
private get elements(): ChildNode[] {
368-
return [...this.children].reduce(
369-
(acc, child) => [
370-
...acc,
371-
...(isSlot(child) ? child.assignedElements() : [child]),
372-
],
373-
[]
374-
);
369+
private get elements(): FeatureElement[] {
370+
return [...this.children]
371+
.reduce(
372+
(acc, child) => [
373+
...acc,
374+
...(isSlot(child) ? child.assignedElements() : [child]),
375+
],
376+
[]
377+
)
378+
.filter(isFeatureElement);
375379
}
376380

377381
_ignoreViewChange: boolean;
@@ -400,7 +404,7 @@ export class LeafletMap extends LeafletBase {
400404

401405
async fitToMarkersChanged() {
402406
if (this.map && this.fitToMarkers) {
403-
const elements = this.elements.filter(isFeatureElement);
407+
const { elements } = this;
404408
if (!elements.length) return;
405409
await Promise.race([
406410
new Promise(r => setTimeout(r, 100)),

0 commit comments

Comments
 (0)