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

AG-11628 widgets tree shaking #7981

Merged
merged 45 commits into from
May 21, 2024
Merged

Conversation

StephenCooper
Copy link
Member

@StephenCooper StephenCooper commented May 17, 2024

The main goal of these changes to remove the static registration of all widgets in the grid.ts file. Instead each component provides the widgets that are required for its own template. This is a similar pattern to Angular's standalone components.

I have also made the selector name explicit in each of the component and that name is used to match against the tags in templates. So for example you will now find the string ag-grid-body on the GridBodyComp class. This has also enabled us to strongly type the complete list of component tags.

This improves type safety when in React we see if components are registered to check for the presence of feature modules.

Each feature module automatically registers all its own components as the assumption is that they will all be required. This is also required to make the React optional registration work.

A number of enterprise only widgets have now been moved to ag-grid-enterprise/core and imported from there if used in multiple enterprise features.

The initial result of this work is a 7% drop in bundle size. However, as Editing and Filtering are still included by default those widgets are maintained even if filtering and editing is not enabled.

@@ -355,40 +333,6 @@ export class GridCoreCreator {
return seed;
}

private createAgStackComponentsList(registeredModules: Module[]): any[] {
Copy link
Member Author

Choose a reason for hiding this comment

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

No longer required as we register widgets / ag stack components alongside with the templates that they are used.

@@ -1,9 +1,5 @@
import { _getFunctionName } from '../utils/function';

export function QuerySelector(selector?: string): Function {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not used anywhere so removed.

continue;
}
// each component must have a unique selector
let name = comp.selector.toUpperCase();
Copy link
Member

Choose a reason for hiding this comment

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

Upper case is only being applied on the set, it's not used on the has check here, or in the getComponent method.

Why do we need to upper case at all? Can't we keep everything lower case?

Copy link
Member Author

Choose a reason for hiding this comment

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

The value returned from const key = element.nodeName; in createComponentFromElement is uppercase so we are matching that.

Copy link
Member

Choose a reason for hiding this comment

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

Don't we need thehas check to also use uppercase then?

Can we add a comment explaining why one is uppercase and the other isn't?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Just made all the selectors uppercase so no need to do any work at runtime.

import { RefSelector } from '../../widgets/componentAnnotations';
import { AgPromise } from '../../utils/promise';
import { _clearElement } from '../../utils/dom';
import { LayoutCssClasses, LayoutFeature, LayoutView, UpdateLayoutClassesParams } from "../../styling/layoutFeature";

import { OverlayService } from './overlayService';

export class OverlayWrapperComponent extends Component implements LayoutView {
export class AgOverlayWrapper extends Component implements LayoutView {
Copy link
Member

Choose a reason for hiding this comment

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

File name doesn't match the class name now

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I reverted a lot of these but missed this. Will put back to its current name as I was aiming to reduce noise in the PR.

@@ -224,31 +246,23 @@ export class Component extends BeanStub {
elements.forEach(el => el.setAttribute('tabindex', tabIndex.toString()));
}

public setTemplate(template: string | null | undefined, paramsMap?: { [key: string]: any; }): void {
public setTemplate(template: string | null | undefined, components: ComponentClass[], paramsMap?: { [key: string]: any; }): void {
Copy link
Member

Choose a reason for hiding this comment

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

components should be optional

Copy link
Member Author

Choose a reason for hiding this comment

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

made components optional and removed umpty arrays.

// if(!current){
// (this as any)[elementRef] = newComponent ?? element;
// }
// }
Copy link
Member

Choose a reason for hiding this comment

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

Should this still be here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed for now.


export interface AgInputTextFieldParams extends AgInputFieldParams {
allowedCharPattern?: string;
}

export class AgInputTextField<TConfig extends AgInputTextFieldParams = AgInputTextFieldParams> extends AgAbstractInputField<HTMLInputElement, string, TConfig> {
static readonly selector: AgComponentSelector = 'ag-input-text-field';
Copy link
Member

Choose a reason for hiding this comment

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

This is extended by other widgets, which have different selectors, e.g AgInputNumberField and AgInputDateField

Copy link
Member Author

Choose a reason for hiding this comment

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

Have added the selectors to the extending classes

'ag-watermark' |
'ag-fill-handle' |
'ag-range-handle' |
'ag-color-picker' |
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that we're referring to module widgets in core

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 is just for the typing. This means that we now get type checking in React where it looks up components via their tags in gridComp.tsx

We already have other interfaces in core that contain enterprise level features.

@peterjrreynolds peterjrreynolds merged commit b9b8675 into latest May 21, 2024
@peterjrreynolds peterjrreynolds deleted the AG-11628-widgets-treeshaking branch May 21, 2024 10:23
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.

None yet

2 participants