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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(engine-core): Remove duplicate Component type definition #2157

Merged
merged 5 commits into from Jan 12, 2021

Conversation

pmdartus
Copy link
Member

@pmdartus pmdartus commented Jan 6, 2021

Details

While investigating the MacroElement proposal I realized that the @lwc/engine contains competing type definition for the LightningElement class: LightElement interface and Component interface. This PR removes Component interface definition. It also fixes #1291.

Does this PR introduce breaking changes?

  • No, it does not introduce breaking changes.

If yes, please describe the impact and migration path for existing applications.

The PR fulfills these requirements:

  • Have tests for the proposed changes been added? ✅
  • Have you followed these instructions to clearly describe the issue being fixed or feature enhanced? ✅

@pmdartus
Copy link
Member Author

pmdartus commented Jan 6, 2021

Note: This PR move certain import to use import type instead of import. The interesting aspect of import type is that it doesn't impact Rollup dependency graph. As discussed in #2025, @lwc/engine-core doesn't have evaluation order issues. IMO, moving to import type when possible would remove the evaluation order issue.

What is the rest of the team's opinion on this? @ekashida @ravijayaramappa @jodarove @caridy
I am ok am fine reverting to plain import and discuss introducing import type in another PR.

import { Template, isUpdatingTemplate, getVMBeingRendered } from './template';

export type ErrorCallback = (error: any, stack: string) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect no one was using this one, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was used in a single place. I replaced it with the LightningElement['errorCallback'] type.

readonly delegatesFocus?: boolean;
}

export interface ComponentMeta {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this used by anyone?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't used at all.


export interface ComponentConstructor extends LightningElementConstructor {
readonly name: string;
readonly labels?: string[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall name and labels usage, any insight here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmdartus what about these ones?

Copy link
Member Author

@pmdartus pmdartus Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed your comment. I did some archeology, and those 2 fields have been introduced with SnabbDOM v2 refactor: #47. I don't recall us ever using those fields either.

@caridy
Copy link
Contributor

caridy commented Jan 7, 2021

I am ok am fine reverting to plain import and discuss introducing import type in another PR.

I certainly will like to see that discussed outside of the context of this PR, unless that this refactor introduces another circular ref for types that makes it hard or impossible to achieve.

The reasons why I'm a little concern about import type is that TS team usually recommends against it, unless of very specific circustances.

@pmdartus pmdartus force-pushed the pmdartus/remove-duplicate-types branch from 2ff1399 to 31fdc5a Compare January 8, 2021 06:24
@pmdartus pmdartus requested a review from caridy January 8, 2021 06:31
@pmdartus
Copy link
Member Author

pmdartus commented Jan 8, 2021

Reverted the import type. Ready for another round of review @caridy.

Comment on lines 124 to 131
new (): LightningElement;
readonly prototype: LightningElement;
readonly CustomElementConstructor: HTMLElementConstructor;

delegatesFocus?: boolean;
}

export declare let LightningElement: LightningElementConstructor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lifting LightningElementConstructor and LightningElement type definition to a separate module will reduce the cyclic dependencies between modules quite a bit.

@pmdartus pmdartus merged commit 22cd29d into master Jan 12, 2021
@pmdartus pmdartus deleted the pmdartus/remove-duplicate-types branch January 12, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[engine] define the entire component interface
4 participants