redoc/lib/components/base.ts

68 lines
1.1 KiB
TypeScript
Raw Normal View History

'use strict';
2016-08-22 12:12:13 +03:00
import { OnInit, OnDestroy } from '@angular/core';
2016-06-22 21:17:48 +03:00
import { SpecManager } from '../utils/SpecManager';
2016-08-22 12:12:13 +03:00
export { SpecManager };
2016-01-09 23:31:39 +03:00
function snapshot(obj) {
2016-06-13 20:54:24 +03:00
if(obj == undefined || typeof(obj) !== 'object') {
2016-01-09 23:31:39 +03:00
return obj;
}
var temp = new obj.constructor();
for(var key in obj) {
if (obj.hasOwnProperty(key)) {
temp[key] = snapshot(obj[key]);
}
}
return temp;
}
/**
* Generic Component
* @class
*/
export class BaseComponent implements OnInit, OnDestroy {
2016-07-26 12:03:15 +03:00
pointer: string;
2016-08-22 12:12:13 +03:00
componentSchema: any = null;
2016-06-22 19:13:57 +03:00
dereferencedCache = {};
2016-06-13 20:54:24 +03:00
constructor(public specMgr: SpecManager) {
}
/**
* onInit method is run by angular2 after all component inputs are resolved
*/
ngOnInit() {
2016-08-28 21:46:10 +03:00
this.preinit();
}
preinit() {
this.componentSchema = this.specMgr.byPointer(this.pointer || '');
2015-10-17 21:12:46 +03:00
this.init();
}
2015-12-21 22:35:57 +03:00
ngOnDestroy() {
this.destroy();
}
/**
* Used to initialize component
2015-10-17 21:12:46 +03:00
* @abstract
*/
2016-06-13 20:54:24 +03:00
init() {
// empty
}
2015-12-21 22:35:57 +03:00
/**
+ Used to destroy component
* @abstract
*/
2016-06-13 20:54:24 +03:00
destroy() {
// emtpy
}
}