Skip to content

Commit

Permalink
fix(module:code-editor): resolve memory leak (#6846)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt authored Jul 12, 2021
1 parent 5c09948 commit 6d43b6c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions components/code-editor/code-editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { BehaviorSubject, Observable, of as observableOf, Subject } from 'rxjs';
import { Inject, Injectable, OnDestroy } from '@angular/core';
import { BehaviorSubject, Observable, of as observableOf, Subject, Subscription } from 'rxjs';
import { map, tap } from 'rxjs/operators';

import { CodeEditorConfig, NzConfigService } from 'ng-zorro-antd/core/config';
Expand All @@ -29,13 +29,14 @@ function tryTriggerFunc(fn?: (...args: NzSafeAny[]) => NzSafeAny): (...args: NzS
@Injectable({
providedIn: 'root'
})
export class NzCodeEditorService {
export class NzCodeEditorService implements OnDestroy {
private document: Document;
private firstEditorInitialized = false;
private loaded$ = new Subject<boolean>();
private loadingStatus = NzCodeEditorLoadingStatus.UNLOAD;
private option: JoinedEditorOptions = {};
private config: CodeEditorConfig;
private subscription: Subscription | null;

option$ = new BehaviorSubject<JoinedEditorOptions>(this.option);

Expand All @@ -46,14 +47,19 @@ export class NzCodeEditorService {
this.config = { ...globalConfig };
this.option = this.config.defaultEditorOption || {};

this.nzConfigService.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME).subscribe(() => {
this.subscription = this.nzConfigService.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME).subscribe(() => {
const newGlobalConfig: NzSafeAny = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME);
if (newGlobalConfig) {
this._updateDefaultOption(newGlobalConfig.defaultEditorOption);
}
});
}

ngOnDestroy(): void {
this.subscription!.unsubscribe();
this.subscription = null;
}

private _updateDefaultOption(option: JoinedEditorOptions): void {
this.option = { ...this.option, ...option };
this.option$.next(this.option);
Expand Down

0 comments on commit 6d43b6c

Please sign in to comment.