Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate using host directives in Angular 15 #1032

Closed
mollykreis opened this issue Feb 7, 2023 · 3 comments
Closed

Evaluate using host directives in Angular 15 #1032

mollykreis opened this issue Feb 7, 2023 · 3 comments
Assignees

Comments

@mollykreis
Copy link
Contributor

馃Ч Tech Debt

Once we upgrade to Angular 15, we should evaluate using HostDirectives as a way to simplify our Angular code. Some ideas/questions are:

  • Can we stop extending Angular's directives in some places, such as the RouterLinkWithHref
  • Can we consolidate repeated code? For example, can we create a "button base" or "drop down base" directives that would allow us to not have to repeat configuration that is shared in base classes within nimble-components?
@mollykreis mollykreis added tech debt triage New issue that needs to be reviewed labels Feb 7, 2023
@m-akinc m-akinc added blocked Blocked on a third-party issue and removed triage New issue that needs to be reviewed labels Feb 7, 2023
@m-akinc m-akinc removed the blocked Blocked on a third-party issue label Sep 26, 2023
@m-akinc
Copy link
Contributor

m-akinc commented Sep 27, 2023

Can we stop extending Angular's directives in some places, such as the RouterLinkWithHref?

For RouterLinkWithHref specifically, we can potentially switch to using hostDirectives instead of extending it. RouterLink is standalone, so that works. However, we need to re-examine the way we implement RouterLink support since Angular made significant changes to its implementation in v15 (see #1570). As for other Angular directives that we extend (e.g. various CVAs), I did not find any that were standalone, meaning we cannot use hostDirectives for them. We will have to address #732 some other way.

Can we consolidate repeated code?

We could split off common parts of the interface into a separate directive (that was then brought along via hostDirectives), but then we would not have the full interface exposed by a single directive. I don't think we want to make that tradeoff. We would end up redefining the shared API on the main component directive, which would negate the benefit of splitting out that API in the first place. Here's an example of what it would look like:

@Directive({
    standalone: true
})
export class NimbleButtonCommonDirective {
    public get appearance(): ButtonAppearance {
        return this.elementRef.nativeElement.appearance;
    }

    @Input() public set appearance(value: ButtonAppearance) {
        this.renderer.setProperty(this.elementRef.nativeElement, 'appearance', value);
    }
    ...
}

@Directive({
    selector: 'nimble-button',
    hostDirectives: [{
        directive: NimbleButtonCommonDirective,
        inputs: ['appearance', ...]
    }]
}
export class NimbleButtonDirective {
    private readonly buttonCommon: NimbleButtonCommonDirective = inject(NimbleButtonCommonDirective, { self: true });

    public get appearance(): ButtonAppearance {
        return this.buttonCommon.appearance;
    }

    public set appearance(value: ButtonAppearance) {
        this.buttonCommon.appearance = value;
    }
    ...
}   

I did not find any other potential uses for host directives in nimble-angular.

@m-akinc m-akinc self-assigned this Sep 27, 2023
@m-akinc
Copy link
Contributor

m-akinc commented Oct 25, 2023

@rajsite I remember you pushing back some about this being a closed issue, but I don't remember details. Do you still have reservations, or specific things you think merit further investigation?

@rajsite
Copy link
Member

rajsite commented Oct 25, 2023

Think Molly had split the discussion and this one is fine to close

@rajsite rajsite closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants