Fix leaks (fixes #167)

This commit is contained in:
Roman Hotsiy 2016-12-19 17:13:39 +02:00
parent 95f2da8b97
commit 104bcb9cef
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 27 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import { ElementRef,
Input,
Component,
OnInit,
OnDestroy,
HostBinding
} from '@angular/core';
@ -26,7 +27,9 @@ import { LazyTasksService } from '../../shared/components/LazyFor/lazy-for';
export class Redoc extends BaseComponent implements OnInit {
static _preOptions: any;
private element: any;
private element: HTMLElement;
private $parent: Element;
private $refElem: Element;
error: any;
specLoaded: boolean;
@ -53,6 +56,9 @@ export class Redoc extends BaseComponent implements OnInit {
optionsMgr.options = Redoc._preOptions || {};
this.element = elementRef.nativeElement;
this.$parent = this.element.parentElement;
this.$refElem = this.element.nextElementSibling;
//parse options (top level component doesn't support inputs)
optionsMgr.parseOptions( this.element );
let scrollParent = detectScollParent( this.element );
@ -121,4 +127,9 @@ export class Redoc extends BaseComponent implements OnInit {
}
this.load();
}
ngOnDestroy() {
let $clone = this.element.cloneNode();
this.$parent.insertBefore($clone, this.$refElem);
}
}

View File

@ -1,6 +1,6 @@
'use strict';
import { Component, ElementRef, ChangeDetectorRef, OnInit } from '@angular/core';
import { Component, ElementRef, ChangeDetectorRef, OnInit, OnDestroy } from '@angular/core';
//import { global } from '@angular/core/src/facade/lang';
import { trigger, state, animate, transition, style } from '@angular/core';
@ -28,7 +28,7 @@ const global = window;
])
],
})
export class SideMenu extends BaseComponent implements OnInit {
export class SideMenu extends BaseComponent implements OnInit, OnDestroy {
activeCatCaption: string;
activeItemCaption: string;
categories: Array<MenuCategory>;
@ -123,6 +123,11 @@ export class SideMenu extends BaseComponent implements OnInit {
destroy() {
this.scrollService.unbind();
this.menuService.destroy();
}
ngOnDestroy() {
this.destroy();
}
ngOnInit() {

View File

@ -33,7 +33,6 @@ export function init(specUrl:string, options:any = {}) {
moduleRef = appRef;
console.log('ReDoc initialized!');
}).catch(err => {
//Redoc.displayError(err);
throw err;
});
};

View File

@ -1,5 +1,6 @@
'use strict';
import { Injectable, EventEmitter } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { ScrollService, INVIEW_POSITION } from './scroll.service';
import { Hash } from './hash.service';
@ -16,6 +17,8 @@ const CHANGE = {
@Injectable()
export class MenuService {
private _hashSubscription: Subscription;
changed: EventEmitter<any> = new EventEmitter();
ready: BehaviorSubject<boolean> = new BehaviorSubject(false);
categories: Array<MenuCategory>;
@ -39,7 +42,7 @@ export class MenuService {
//this.changeActive(CHANGE.INITIAL);
this.hash.value.subscribe((hash) => {
this._hashSubscription = this.hash.value.subscribe((hash) => {
if (hash == undefined) return;
this.setActiveByHash(hash);
if (!this.tasks.empty) {
@ -228,4 +231,8 @@ export class MenuService {
}
this.activate(catIdx, methodIdx);
}
destroy() {
this._hashSubscription.unsubscribe();
}
}