Minor refactoring in json-schema-lazy

This commit is contained in:
Roman Hotsiy 2016-05-20 19:28:16 +03:00
parent c40de56a71
commit 18c3f605a0

View File

@ -35,20 +35,24 @@ export class JsonSchemaLazy {
return schema && schema.$ref || this.pointer; return schema && schema.$ref || this.pointer;
} }
load() { _loadAfterSelf() {
if (this.optionsService.options.disableLazySchemas) return; return this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {
if (this.loaded) return;
if (this.pointer) {
this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {
this.initComponent(compRef); this.initComponent(compRef);
// trigger change detection
if (compRef.changeDetectorRef) { if (compRef.changeDetectorRef) {
compRef.changeDetectorRef.detectChanges(); compRef.changeDetectorRef.detectChanges();
} else { } else {
compRef.hostView.changeDetectorRef.detectChanges(); compRef.hostView.changeDetectorRef.detectChanges();
} }
return compRef;
}); });
} }
load() {
if (this.optionsService.options.disableLazySchemas) return;
if (this.loaded) return;
if (this.pointer) {
this._loadAfterSelf();
}
this.loaded = true; this.loaded = true;
} }
@ -63,29 +67,13 @@ export class JsonSchemaLazy {
// skip caching view with tabs inside (discriminator) as it needs attached controller // skip caching view with tabs inside (discriminator) as it needs attached controller
// FIXME: get rid of dependency on selector // FIXME: get rid of dependency on selector
if ($element.querySelector('.discriminator-wrap')) { if ($element.querySelector('.discriminator-wrap')) {
this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {
this.initComponent(compRef);
if (compRef.changeDetectorRef) {
compRef.changeDetectorRef.detectChanges();
} else {
compRef.hostView.changeDetectorRef.detectChanges();
}
});
return; return;
} }
insertAfter($element.cloneNode(true), this.elementRef.nativeElement); insertAfter($element.cloneNode(true), this.elementRef.nativeElement);
} ); } );
}); });
} else { } else {
cache[this.pointer] = this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => { cache[this.pointer] = this._loadAfterSelf();
this.initComponent(compRef);
if (compRef.changeDetectorRef) {
compRef.changeDetectorRef.detectChanges();
} else {
compRef.hostView.changeDetectorRef.detectChanges();
}
return compRef;
});
} }
} }