<commit_before>import { Control, IControl } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import {
  AfterContentInit,
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  Input,
  OnDestroy,
  ViewChild,
} from '@angular/core';

export class CustomControl implements IControl {
  constructor(
    private container: HTMLElement
  ) {
  }

  onAdd() {
    return this.container;
  }

  onRemove() {
    return this.container.parentNode!.removeChild(this.container);
  }

  getDefaultPosition() {
    return 'top-right';
  }
}

@Component({
  selector: 'mgl-control',
  template: '<div class="mapboxgl-ctrl" #content><ng-content></ng-content></div>',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ControlComponent implements OnDestroy, AfterContentInit {
  /* Init inputs */
  @Input() position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';

  @ViewChild('content') content: ElementRef;

  control: Control | IControl;

  constructor(
    private MapService: MapService
  ) { }

  ngAfterContentInit() {
    if (this.content.nativeElement.childNodes.length) {
      this.control = new CustomControl(this.content.nativeElement);
      this.MapService.mapCreated$.subscribe(() => {
        this.MapService.addControl(this.control!, this.position);
      });
    }
  }

  ngOnDestroy() {
    this.MapService.removeControl(this.control);
  }
}<commit_msg>fix(control): add safety check to ngOnDestroy<commit_after>import { Control, IControl } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import {
  AfterContentInit,
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  Input,
  OnDestroy,
  ViewChild,
} from '@angular/core';

export class CustomControl implements IControl {
  constructor(
    private container: HTMLElement
  ) {
  }

  onAdd() {
    return this.container;
  }

  onRemove() {
    return this.container.parentNode!.removeChild(this.container);
  }

  getDefaultPosition() {
    return 'top-right';
  }
}

@Component({
  selector: 'mgl-control',
  template: '<div class="mapboxgl-ctrl" #content><ng-content></ng-content></div>',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ControlComponent implements OnDestroy, AfterContentInit {
  /* Init inputs */
  @Input() position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';

  @ViewChild('content') content: ElementRef;

  control: Control | IControl;

  constructor(
    private MapService: MapService
  ) { }

  ngAfterContentInit() {
    if (this.content.nativeElement.childNodes.length) {
      this.control = new CustomControl(this.content.nativeElement);
      this.MapService.mapCreated$.subscribe(() => {
        this.MapService.addControl(this.control!, this.position);
      });
    }
  }

  ngOnDestroy() {
    if (this.control) {
      this.MapService.removeControl(this.control);
    }
  }
}
{'fraction_non_alphanumeric': 0.13740458015267176, 'fraction_numerical': 0.0, 'mean_word_length': 3.829145728643216, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691125', 'n_tokens_mistral': 897, 'n_tokens_neox': 881, 'n_words': 169}