Skip to content

Commit

Permalink
Remove div wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
fboeller committed Mar 7, 2021
1 parent 3a09a43 commit 08a367a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div #loadedRef [hidden]="hideLoadedNgContent">
<ng-content></ng-content>
</div>
<ng-container *ngIf="hideLoadedNgContent">
<ng-content *ngIf="showNgContent"></ng-content>
<ng-container *ngIf="!showNgContent">
<ng-container
*ngTemplateOutlet="
templateRef ? templateRef : content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function loadableTemplateContext(loadable: Loadable<unknown>): object {
export type TemplateRefs = {
idle?: TemplateRef<void>;
loading?: TemplateRef<void>;
loaded?: TemplateRef<{ value: any }>;
error?: TemplateRef<{ error: any }>;
};

Expand All @@ -61,20 +60,15 @@ export class LoadableComponent implements OnChanges {
@ViewChild('content', { read: ViewContainerRef })
content?: ViewContainerRef;

@ViewChild('loadedRef')
loadedRef?: any;

defaultComponentRef?: ComponentRef<unknown>;
templateRef?: TemplateRef<unknown>;
hideLoadedNgContent = true;
showNgContent = false;
templateContext?: object;

constructor(
private resolver: ComponentFactoryResolver,
@Inject(DEFAULT_COMPONENTS) private defaultComponents: DefaultComponents
) {
console.log(this.defaultComponents);
}
) {}

updateContent(loadable: Loadable<unknown>): void {
const defaultComponent = this.defaultComponents[getLoadingState(loadable)];
Expand All @@ -86,26 +80,22 @@ export class LoadableComponent implements OnChanges {
}
}

isNgContentHidden(loadable: Loadable<unknown>): boolean {
return (
this.loadedRef?.nativeElement?.children?.length === 0 ||
!isLoaded(loadable)
);
}

ngOnChanges(changes: SimpleChanges): void {
if ('loadable' in changes) {
this.hideLoadedNgContent = this.isNgContentHidden(this.loadable);
this.showNgContent = isLoaded(this.loadable);
this.templateContext = {
...loadableTemplateContext(this.loadable),
type: this.loadable.type,
};
}
if ('loadable' in changes || 'templates' in changes) {
this.templateRef = this.templates[getLoadingState(this.loadable)];
this.defaultComponentRef?.destroy();
if (!this.templateRef) {
this.updateContent(this.loadable);
const loadingState = getLoadingState(this.loadable);
if (loadingState !== 'loaded') {
this.templateRef = this.templates[loadingState];
if (!this.templateRef) {
this.updateContent(this.loadable);
}
}
}
}
Expand Down

0 comments on commit 08a367a

Please sign in to comment.