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,19 +35,23 @@ export class JsonSchemaLazy {
return schema && schema.$ref || this.pointer; return schema && schema.$ref || this.pointer;
} }
_loadAfterSelf() {
return this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => {
this.initComponent(compRef);
if (compRef.changeDetectorRef) {
compRef.changeDetectorRef.detectChanges();
} else {
compRef.hostView.changeDetectorRef.detectChanges();
}
return compRef;
});
}
load() { load() {
if (this.optionsService.options.disableLazySchemas) return; if (this.optionsService.options.disableLazySchemas) return;
if (this.loaded) return; if (this.loaded) return;
if (this.pointer) { if (this.pointer) {
this.dcl.loadNextToLocation(JsonSchema, this.viewRef).then((compRef) => { this._loadAfterSelf();
this.initComponent(compRef);
// trigger change detection
if (compRef.changeDetectorRef) {
compRef.changeDetectorRef.detectChanges();
} else {
compRef.hostView.changeDetectorRef.detectChanges();
}
});
} }
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;
});
} }
} }