Isolated each component schemas

This commit is contained in:
Roman Hotsiy 2016-01-09 22:31:39 +02:00
parent dce75ccd92
commit c2e712b039
2 changed files with 18 additions and 2 deletions

View File

@ -15,6 +15,22 @@ function safeConcat(a, b) {
return res.concat(b);
}
function snapshot(obj) {
if(obj == null || typeof(obj) != 'object') {
return obj;
}
var temp = new obj.constructor();
for(var key in obj) {
if (obj.hasOwnProperty(key)) {
temp[key] = snapshot(obj[key]);
}
}
return temp;
}
/**
* Class decorator
* Simplifies setup of component metainfo
@ -72,7 +88,7 @@ export class BaseComponent {
* onInit method is run by angular2 after all component inputs are resolved
*/
ngOnInit() {
this.componentSchema = this.schemaMgr.byPointer(this.pointer || '');
this.componentSchema = snapshot(this.schemaMgr.byPointer(this.pointer || ''));
this.prepareModel();
this.init();
}

View File

@ -26,7 +26,7 @@ describe('Redoc components', () => {
it('should set componentSchema based on pointer on ngOnInit', () => {
component.pointer = '/tags';
component.ngOnInit();
component.componentSchema.should.be.equal(schemaMgr._schema.tags);
component.componentSchema.should.be.deepEqual(schemaMgr._schema.tags);
});
it('should call prepareModel and init virtual methods after init', () => {