Skip to content

Commit

Permalink
Merge branch 'generify-component-loaders_contribute-7.6' into generif…
Browse files Browse the repository at this point in the history
…y-component-loaders_contribute-main
  • Loading branch information
alexandrevryghem committed Dec 19, 2023
2 parents d8be26d + 7942c90 commit e071b7f
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, ComponentRef, Input, OnChanges, OnDestroy, OnInit, SimpleCha
import { Context } from '../../core/shared/context.model';
import { ThemeService } from '../theme-support/theme.service';
import { GenericConstructor } from '../../core/shared/generic-constructor';
import { hasNoValue, hasValue, isNotEmpty } from '../empty.util';
import { hasValue, isNotEmpty } from '../empty.util';
import { Subscription } from 'rxjs';
import { DynamicComponentLoaderDirective } from './dynamic-component-loader.directive';

Expand Down Expand Up @@ -57,21 +57,15 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
* Set up the dynamic child component
*/
ngOnInit(): void {
if (hasNoValue(this.compRef)) {
this.instantiateComponent();
}
this.instantiateComponent();
}

/**
* Whenever the inputs change, update the inputs of the dynamic component
*/
ngOnChanges(changes: SimpleChanges): void {
if (hasNoValue(this.compRef)) {
// sometimes the component has not been initialized yet, so it first needs to be initialized
// before being called again
this.instantiateComponent();
} else {
if (this.inputNamesDependentForComponent.some((name: any) => hasValue(changes[name]) && changes[name].previousValue !== changes[name].currentValue)) {
if (hasValue(this.compRef)) {
if (this.inputNamesDependentForComponent.some((name: keyof this & string) => hasValue(changes[name]) && changes[name].previousValue !== changes[name].currentValue)) {
// Recreate the component when the @Input()s used by getComponent() aren't up-to-date anymore
this.destroyComponentInstance();
this.instantiateComponent();

Check warning on line 71 in src/app/shared/abstract-component-loader/abstract-component-loader.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/abstract-component-loader/abstract-component-loader.component.ts#L70-L71

Added lines #L70 - L71 were not covered by tests
Expand Down Expand Up @@ -123,7 +117,7 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC

/**
* Connect the inputs and outputs of this component to the dynamic component,
* to ensure they're in sync
* to ensure they're in sync, the ngOnChanges method will automatically be called by setInput
*/
public connectInputsAndOutputs(): void {
if (isNotEmpty(this.inputNames) && hasValue(this.compRef) && hasValue(this.compRef.instance)) {
Expand Down

0 comments on commit e071b7f

Please sign in to comment.