Skip to content

Commit

Permalink
Fix leaks (fixes #167)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Dec 19, 2016
1 parent 95f2da8 commit 104bcb9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/components/Redoc/redoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ElementRef,
Input,
Component,
OnInit,
OnDestroy,
HostBinding
} from '@angular/core';

Expand All @@ -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;
Expand All @@ -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 );
Expand Down Expand Up @@ -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);
}
}
9 changes: 7 additions & 2 deletions lib/components/SideMenu/side-menu.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -123,6 +123,11 @@ export class SideMenu extends BaseComponent implements OnInit {

destroy() {
this.scrollService.unbind();
this.menuService.destroy();
}

ngOnDestroy() {
this.destroy();
}

ngOnInit() {
Expand Down
1 change: 0 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export function init(specUrl:string, options:any = {}) {
moduleRef = appRef;
console.log('ReDoc initialized!');
}).catch(err => {
//Redoc.displayError(err);
throw err;
});
};
Expand Down
9 changes: 8 additions & 1 deletion lib/services/menu.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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>;
Expand All @@ -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) {
Expand Down Expand Up @@ -228,4 +231,8 @@ export class MenuService {
}
this.activate(catIdx, methodIdx);
}

destroy() {
this._hashSubscription.unsubscribe();
}
}

0 comments on commit 104bcb9

Please sign in to comment.