Skip to content

Commit 1e5c26b

Browse files
refactor nested dxi components. Group by props names
1 parent abdce80 commit 1e5c26b

1,453 files changed

Lines changed: 14912 additions & 6478 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/devextreme-angular/src/core/component.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
createNgModule,
2020
inject,
2121
Injector,
22-
ContentChildren,
2322
} from '@angular/core';
2423

2524
import { isPlatformServer } from '@angular/common';
@@ -38,8 +37,8 @@ import {
3837
ICollectionNestedOption,
3938
ICollectionNestedOptionContainer,
4039
CollectionNestedOptionContainerImpl,
41-
_updateNestedItems,
42-
NESTED_ITEM_TOKEN,
40+
checkIncompatibleNestedItems,
41+
4342
} from './nested-option';
4443

4544
import { DxIntegrationModule } from './integration';
@@ -64,27 +63,14 @@ export const getServerStateKey = () => {
6463
})
6564
export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterContentChecked, AfterViewInit, AfterViewChecked,
6665
INestedOptionContainer, ICollectionNestedOptionContainer, IDxTemplateHost {
66+
protected _dxClassName = 'DxComponent';
67+
6768
private _initialOptions: any = {};
6869

6970
protected _optionsToUpdate: any = {};
7071

7172
private readonly _collectionContainerImpl: ICollectionNestedOptionContainer;
7273

73-
private _currentNestedOptions:Map<string, any> = new Map();
74-
75-
@ContentChildren(NESTED_ITEM_TOKEN)
76-
set _nestedItems(value: QueryList<{ propertyName: string; className: string; component: ICollectionNestedOption }>) {
77-
_updateNestedItems(
78-
value,
79-
this.setChildren.bind(this),
80-
{
81-
componentClassName: this.constructor.name,
82-
legacyClassNames: this.getLegacyClassNames(),
83-
currentOptions: this._currentNestedOptions
84-
},
85-
);
86-
}
87-
8874
eventHelper: EmitterHelper;
8975

9076
optionChangedHandlers: EventEmitter<any> = new EventEmitter();
@@ -104,7 +90,20 @@ export abstract class DxComponent implements OnChanges, OnInit, DoCheck, AfterCo
10490
widgetUpdateLocked = false;
10591

10692
templateUpdateRequired = false;
93+
94+
95+
protected _setChildren(propertyName: string, items: QueryList<ICollectionNestedOption>) {
96+
const hasIncopatibleNestedItems = checkIncompatibleNestedItems(
97+
items,
98+
this._dxClassName,
99+
this.getLegacyClassNames()[propertyName]
100+
);
107101

102+
if (!hasIncopatibleNestedItems) {
103+
this.setChildren(propertyName, items);
104+
}
105+
}
106+
108107
private _updateTemplates() {
109108
if (this.templates.length && this.templateUpdateRequired) {
110109
const updatedTemplates = {};

packages/devextreme-angular/src/core/nested-option.ts

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,25 @@ export interface INestedOptionContainer {
2424

2525
export type IOptionPathGetter = () => string;
2626

27-
/* const warnAboutIncompatibleNestedItems = (containerClassName: string, itemClassName: string, anotherItemClassName: string) => {
28-
if (console && console.warn) {
27+
export const checkIncompatibleNestedItems = (
28+
items: QueryList<ICollectionNestedOption>,
29+
containerClassName,
30+
legacyClassNames,
31+
) => {
32+
/* if (console && console.warn) {
2933
console.warn(`In ${containerClassName},
3034
the nested ${itemClassName} and ${anotherItemClassName} components are incompatible.
3135
Ensure that all nested components in the content area match.`);
32-
}
33-
}; */
34-
35-
export const _updateNestedItems = (
36-
items: QueryList<{ propertyName: string; className: string; component: ICollectionNestedOption }>,
37-
setChildrenFn: (propertyName: string, items: QueryList<ICollectionNestedOption>) => void,
38-
{
39-
componentClassName,
40-
legacyClassNames,
41-
currentOptions,
42-
}: { componentClassName: string; legacyClassNames: Record<string, string[]>, currentOptions: Map<string, any> },
43-
) => {
44-
const hasLegacy = {};
45-
const groupedItems = {};
46-
47-
for (let index = 0; index < items.length; index++) {
48-
const { propertyName, className, component } = items.get(index);
49-
50-
groupedItems[propertyName] = groupedItems[propertyName] || [];
51-
groupedItems[propertyName].push(component);
52-
53-
if (legacyClassNames?.[propertyName]) {
54-
const isLegacyClassName = legacyClassNames[propertyName].includes(className);
55-
56-
if (index === 0) {
57-
hasLegacy[propertyName] = isLegacyClassName;
58-
} else if (hasLegacy[propertyName] !== isLegacyClassName) {
59-
// warnAboutIncompatibleNestedItems(componentClassName, items.get(0).className, className);
60-
// return;
61-
}
62-
}
63-
}
64-
65-
Object.entries(groupedItems).forEach(([propertyName, components]: [string, ICollectionNestedOption[]]) => {
66-
const queryList = new QueryList<ICollectionNestedOption>();
67-
68-
queryList.reset(components);
69-
currentOptions.set(propertyName, true);
70-
setChildrenFn(propertyName, queryList);
71-
});
36+
}*/
37+
return false;
38+
};
7239

73-
currentOptions.forEach((updated, propertyName) => {
74-
if (!updated) {
75-
setChildrenFn(propertyName, new QueryList<ICollectionNestedOption>());
76-
}
77-
currentOptions.set(propertyName, false);
78-
})
79-
};
8040

8141
@Component({
8242
template: '',
8343
})
8444
export abstract class BaseNestedOption implements INestedOptionContainer, ICollectionNestedOptionContainer {
45+
protected _dxClassName = 'BaseNestedOption';
8546
protected _host: INestedOptionContainer;
8647

8748
protected _hostOptionPath: IOptionPathGetter;
@@ -93,25 +54,22 @@ export abstract class BaseNestedOption implements INestedOptionContainer, IColle
9354
protected abstract get _optionPath(): string;
9455
protected abstract _fullOptionPath(): string;
9556

96-
private _currentNestedOptions:Map<string, any> = new Map();
97-
9857
constructor() {
9958
this._collectionContainerImpl = new CollectionNestedOptionContainerImpl(this._setOption.bind(this), this._filterItems.bind(this));
10059
}
10160

102-
@ContentChildren(NESTED_ITEM_TOKEN)
103-
set _nestedItems(value: QueryList<{ propertyName: string; className: string; component: ICollectionNestedOption }>) {
104-
_updateNestedItems(
105-
value,
106-
this.setChildren.bind(this),
107-
{
108-
componentClassName: this.constructor.name,
109-
legacyClassNames: null,
110-
currentOptions: this._currentNestedOptions
111-
},
61+
protected _setChildren(propertyName: string, items: QueryList<ICollectionNestedOption>) {
62+
const hasIncopatibleNestedItems = checkIncompatibleNestedItems(
63+
items,
64+
this._dxClassName,
65+
null
11266
);
67+
68+
if (!hasIncopatibleNestedItems) {
69+
this.setChildren(propertyName, items);
70+
}
11371
}
114-
72+
11573
protected _optionChangedHandler(e: any) {
11674
const fullOptionPath = this._fullOptionPath();
11775

packages/devextreme-angular/src/ui/accordion/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
EventEmitter,
1717
OnChanges,
1818
DoCheck,
19-
SimpleChanges
19+
SimpleChanges,
20+
ContentChildren,
21+
QueryList,
2022
} from '@angular/core';
2123

2224
export { ExplicitTypes } from 'devextreme/ui/accordion';
@@ -36,13 +38,19 @@ import {
3638
DxTemplateModule,
3739
NestedOptionHost,
3840
IterableDifferHelper,
39-
WatcherHelper
41+
WatcherHelper,
42+
ICollectionNestedOption,
4043
} from 'devextreme-angular/core';
4144

4245
import { DxiItemModule } from 'devextreme-angular/ui/nested';
4346

4447
import { DxiAccordionItemModule } from 'devextreme-angular/ui/accordion/nested';
4548

49+
import {
50+
PROPERTY_TOKEN_items,
51+
} from 'devextreme-angular/ui/nested/tokens';
52+
53+
4654

4755
/**
4856
* [descr:dxAccordion]
@@ -62,6 +70,13 @@ import { DxiAccordionItemModule } from 'devextreme-angular/ui/accordion/nested';
6270
]
6371
})
6472
export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent implements OnDestroy, OnChanges, DoCheck {
73+
protected _dxClassName = 'DxAccordionComponent';
74+
75+
@ContentChildren(PROPERTY_TOKEN_items)
76+
set _itemsNestedItems(value: QueryList<ICollectionNestedOption>) {
77+
this._setChildren('items', value);
78+
}
79+
6580
instance: DxAccordion<TItem, TKey> = null;
6681

6782
/**
@@ -708,16 +723,16 @@ export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent i
708723

709724
protected getLegacyClassNames = () => {
710725
const legacyClassNames = {};
711-
726+
712727
const getLegacyClassNamesForPropertyName = (propName) => {
713728
legacyClassNames[propName] = legacyClassNames[propName] || [];
714729
return legacyClassNames[propName];
715730
};
716-
731+
717732

718733
getLegacyClassNamesForPropertyName('items').push('DxiItemComponent');
719734

720-
735+
721736
return legacyClassNames || {};
722737
};
723738

packages/devextreme-angular/src/ui/accordion/nested/item-dxi.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,26 @@ import {
1010
Inject,
1111
AfterViewInit,
1212
SkipSelf,
13-
Input
13+
Input,
1414
} from '@angular/core';
1515

1616
import { DOCUMENT } from '@angular/common';
1717

1818

1919

2020
import {
21-
NESTED_ITEM_TOKEN,
2221
DxIntegrationModule,
2322
NestedOptionHost,
2423
extractTemplate,
2524
DxTemplateDirective,
2625
IDxTemplateHost,
27-
DxTemplateHost
26+
DxTemplateHost,
2827
} from 'devextreme-angular/core';
2928
import { CollectionNestedOption } from 'devextreme-angular/core';
3029

30+
import { PROPERTY_TOKEN_items } from 'devextreme-angular/ui/nested/tokens';
31+
32+
3133
@Component({
3234
selector: 'dxi-accordion-item',
3335
standalone: true,
@@ -38,18 +40,16 @@ import { CollectionNestedOption } from 'devextreme-angular/core';
3840
NestedOptionHost,
3941
DxTemplateHost,
4042
{
41-
provide: NESTED_ITEM_TOKEN,
42-
useFactory: (component: DxiAccordionItemComponent) => ({
43-
propertyName: 'items',
44-
className: 'DxiAccordionItemComponent',
45-
component
46-
}),
47-
deps: [DxiAccordionItemComponent],
43+
provide: PROPERTY_TOKEN_items,
44+
useExisting: DxiAccordionItemComponent,
4845
}
4946
],
5047
})
5148
export class DxiAccordionItemComponent extends CollectionNestedOption implements AfterViewInit,
52-
IDxTemplateHost {
49+
IDxTemplateHost {
50+
protected _dxClassName = 'DxiAccordionItemComponent';
51+
52+
5353
@Input()
5454
get disabled(): boolean {
5555
return this._getOption('disabled');
@@ -154,4 +154,4 @@ export class DxiAccordionItemComponent extends CollectionNestedOption implements
154154
DxiAccordionItemComponent
155155
],
156156
})
157-
export class DxiAccordionItemModule { }
157+
export class DxiAccordionItemModule { }

packages/devextreme-angular/src/ui/action-sheet/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
EventEmitter,
1717
OnChanges,
1818
DoCheck,
19-
SimpleChanges
19+
SimpleChanges,
20+
ContentChildren,
21+
QueryList,
2022
} from '@angular/core';
2123

2224
export { ExplicitTypes } from 'devextreme/ui/action_sheet';
@@ -36,13 +38,19 @@ import {
3638
DxTemplateModule,
3739
NestedOptionHost,
3840
IterableDifferHelper,
39-
WatcherHelper
41+
WatcherHelper,
42+
ICollectionNestedOption,
4043
} from 'devextreme-angular/core';
4144

4245
import { DxiItemModule } from 'devextreme-angular/ui/nested';
4346

4447
import { DxiActionSheetItemModule } from 'devextreme-angular/ui/action-sheet/nested';
4548

49+
import {
50+
PROPERTY_TOKEN_items,
51+
} from 'devextreme-angular/ui/nested/tokens';
52+
53+
4654

4755
/**
4856
* [descr:dxActionSheet]
@@ -62,6 +70,13 @@ import { DxiActionSheetItemModule } from 'devextreme-angular/ui/action-sheet/nes
6270
]
6371
})
6472
export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent implements OnDestroy, OnChanges, DoCheck {
73+
protected _dxClassName = 'DxActionSheetComponent';
74+
75+
@ContentChildren(PROPERTY_TOKEN_items)
76+
set _itemsNestedItems(value: QueryList<ICollectionNestedOption>) {
77+
this._setChildren('items', value);
78+
}
79+
6580
instance: DxActionSheet<TItem, TKey> = null;
6681

6782
/**
@@ -500,16 +515,16 @@ export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent
500515

501516
protected getLegacyClassNames = () => {
502517
const legacyClassNames = {};
503-
518+
504519
const getLegacyClassNamesForPropertyName = (propName) => {
505520
legacyClassNames[propName] = legacyClassNames[propName] || [];
506521
return legacyClassNames[propName];
507522
};
508-
523+
509524

510525
getLegacyClassNamesForPropertyName('items').push('DxiItemComponent');
511526

512-
527+
513528
return legacyClassNames || {};
514529
};
515530

0 commit comments

Comments
 (0)