Skip to content

Commit afbda1f

Browse files
authored
feat: support removeChild from parent on destroy (#275)
1 parent eadfe29 commit afbda1f

File tree

36 files changed

+211
-0
lines changed

36 files changed

+211
-0
lines changed

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-clusterer/y-map-clusterer.directive.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,15 @@ describe('YMapClustererDirective', () => {
156156

157157
expect(clustererInstance.update).toHaveBeenCalledWith(expect.objectContaining(props));
158158
});
159+
160+
it('should remove entity on destroy', async () => {
161+
fixture.detectChanges();
162+
163+
// ymaps3.import is async, wait for it
164+
await new Promise(process.nextTick);
165+
166+
fixture.destroy();
167+
168+
expect(mapInstance.removeChild).toHaveBeenCalledWith(clustererInstance);
169+
});
159170
});

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-clusterer/y-map-clusterer.directive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ export class YMapClustererDirective implements AfterContentInit, OnDestroy, OnCh
183183
}
184184

185185
ngOnDestroy() {
186+
if (this.clusterer) {
187+
this.yMapComponent.map$.value?.removeChild(this.clusterer);
188+
}
189+
186190
this.destroy$.next();
187191
this.destroy$.complete();
188192
}

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-default-marker/y-map-default-marker.directive.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,15 @@ describe('YMapDefaultMarkerDirective', () => {
125125

126126
expect(markerInstance.update).toHaveBeenCalledWith(props);
127127
});
128+
129+
it('should remove entity on destroy', async () => {
130+
fixture.detectChanges();
131+
132+
// ymaps3.import is async, wait for it
133+
await new Promise(process.nextTick);
134+
135+
fixture.destroy();
136+
137+
expect(mapInstance.removeChild).toHaveBeenCalledWith(markerInstance);
138+
});
128139
});

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-default-marker/y-map-default-marker.directive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ export class YMapDefaultMarkerDirective implements OnInit, OnDestroy, OnChanges
9999
}
100100

101101
ngOnDestroy() {
102+
if (this.marker) {
103+
this.yMapComponent.map$.value?.removeChild(this.marker);
104+
}
105+
102106
this.destroy$.next();
103107
this.destroy$.complete();
104108
}

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-feature-data-source/y-map-feature-data-source.directive.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,11 @@ describe('YMapFeatureDataSourceDirective', () => {
106106

107107
expect(sourceInstance.update).toHaveBeenCalledWith(props);
108108
});
109+
110+
it('should remove entity on destroy', async () => {
111+
fixture.detectChanges();
112+
fixture.destroy();
113+
114+
expect(mapInstance.removeChild).toHaveBeenCalledWith(sourceInstance);
115+
});
109116
});

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-feature-data-source/y-map-feature-data-source.directive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export class YMapFeatureDataSourceDirective implements OnInit, OnDestroy, OnChan
7777
}
7878

7979
ngOnDestroy() {
80+
if (this.source) {
81+
this.yMapComponent.map$.value?.removeChild(this.source);
82+
}
83+
8084
this.destroy$.next();
8185
this.destroy$.complete();
8286
}

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-feature/y-map-feature.directive.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,11 @@ describe('YMapFeatureDirective', () => {
118118

119119
expect(featureInstance.update).toHaveBeenCalledWith(props);
120120
});
121+
122+
it('should remove entity on destroy', async () => {
123+
fixture.detectChanges();
124+
fixture.destroy();
125+
126+
expect(mapInstance.removeChild).toHaveBeenCalledWith(featureInstance);
127+
});
121128
});

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-feature/y-map-feature.directive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export class YMapFeatureDirective implements OnInit, OnDestroy, OnChanges {
9898
}
9999

100100
ngOnDestroy() {
101+
if (this.feature) {
102+
this.yMapComponent.map$.value?.removeChild(this.feature);
103+
}
104+
101105
this.destroy$.next();
102106
this.destroy$.complete();
103107
}

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-hint/y-map-hint.directive.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,15 @@ describe('YMapHintDirective', () => {
134134

135135
expect(hintInstance.update).toHaveBeenCalledWith(props);
136136
});
137+
138+
it('should remove entity on destroy', async () => {
139+
fixture.detectChanges();
140+
141+
// ymaps3.import is async, wait for it
142+
await new Promise(process.nextTick);
143+
144+
fixture.destroy();
145+
146+
expect(mapInstance.removeChild).toHaveBeenCalledWith(hintInstance);
147+
});
137148
});

libs/angular-yandex-maps-v3/src/lib/components/common/y-map-hint/y-map-hint.directive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ export class YMapHintDirective implements AfterContentInit, OnChanges, OnDestroy
137137
}
138138

139139
ngOnDestroy() {
140+
if (this.hint) {
141+
this.yMapComponent.map$.value?.removeChild(this.hint);
142+
}
143+
140144
this.destroy$.next();
141145
this.destroy$.complete();
142146
}

0 commit comments

Comments
 (0)