Add destroy handler to BaseComponent

This commit is contained in:
Roman Hotsiy 2015-12-21 21:35:57 +02:00
parent a98a8b61dd
commit 6276a2cd55

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
import {Component, View, OnInit, ChangeDetectionStrategy} from 'angular2/core'; import {Component, View, OnInit, OnDestroy, ChangeDetectionStrategy} from 'angular2/core';
import {CORE_DIRECTIVES, JsonPipe} from 'angular2/common'; import {CORE_DIRECTIVES, JsonPipe} from 'angular2/common';
import SchemaManager from '../utils/SchemaManager'; import SchemaManager from '../utils/SchemaManager';
import JsonPointer from '../utils/JsonPointer'; import JsonPointer from '../utils/JsonPointer';
@ -41,7 +41,7 @@ export function RedocComponent(options) {
selector: options.selector, selector: options.selector,
inputs: inputs, inputs: inputs,
outputs: options.outputs, outputs: options.outputs,
lifecycle: [OnInit], lifecycle: [OnInit, OnDestroy],
providers: options.providers, providers: options.providers,
changeDetection: options.changeDetection || ChangeDetectionStrategy.Detached changeDetection: options.changeDetection || ChangeDetectionStrategy.Detached
}); });
@ -77,6 +77,10 @@ export class BaseComponent {
this.init(); this.init();
} }
ngOnDestroy() {
this.destroy();
}
/** /**
* simple in-place schema dereferencing. Schema is already bundled so no need in global dereferencing. * simple in-place schema dereferencing. Schema is already bundled so no need in global dereferencing.
* TODO: doesn't support circular references * TODO: doesn't support circular references
@ -151,5 +155,11 @@ export class BaseComponent {
* @abstract * @abstract
*/ */
init() {} init() {}
/**
+ Used to destroy component
* @abstract
*/
destroy() {}
} }
BaseComponent.parameters = [[SchemaManager]]; BaseComponent.parameters = [[SchemaManager]];