Skip to content

Commit 80a9cf3

Browse files
DataHelper: try extending the component from mixin instead of using inclide
1 parent aff53b6 commit 80a9cf3

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

packages/devextreme/js/__internal/data/m_data_helper.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { DataSource } from '@js/common/data/data_source/data_source';
22
import { normalizeDataSourceOptions } from '@js/common/data/data_source/utils';
33
import { extend } from '@js/core/utils/extend';
4-
import type { Controller } from '@ts/grids/grid_core/m_modules';
5-
import type { ModuleType } from '@ts/grids/grid_core/m_types';
64
import DataController from '@ts/ui/collection/m_data_controller';
75

86
const DATA_SOURCE_OPTIONS_METHOD = '_dataSourceOptions';
@@ -13,7 +11,8 @@ const DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD = '_dataSourceFromUrlLoadMode';
1311
const SPECIFIC_DATA_SOURCE_OPTION = '_getSpecificDataSourceOption';
1412
const NORMALIZE_DATA_SOURCE = '_normalizeDataSource';
1513

16-
export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => class DataHelperMixin extends Base {
14+
export type Constructor<T> = (new (...args: any[]) => T);
15+
export const DataHelperMixin = <T extends Constructor<object>>(Base: T) => class DataHelperMixin extends Base {
1716
public _dataSource: any;
1817

1918
protected _dataController: any;
@@ -31,6 +30,7 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl
3130
private readonly _dataSourceType: any;
3231

3332
public postCtor() {
33+
// @ts-expect-error ts-error
3434
this.on('disposing', () => {
3535
this._disposeDataSource();
3636
});
@@ -41,9 +41,11 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl
4141
this._loadDataSource();
4242
}
4343

44-
protected _initDataSource() {
44+
protected _initDataSource(): void {
4545
let dataSourceOptions = SPECIFIC_DATA_SOURCE_OPTION in this
46-
? (this[SPECIFIC_DATA_SOURCE_OPTION] as any)()
46+
// @ts-expect-error ts-error
47+
? this[SPECIFIC_DATA_SOURCE_OPTION]()
48+
// @ts-expect-error ts-error
4749
: this.option('dataSource');
4850

4951
let widgetDataSourceOptions;
@@ -57,29 +59,33 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl
5759
this._dataSource = dataSourceOptions;
5860
} else {
5961
widgetDataSourceOptions = DATA_SOURCE_OPTIONS_METHOD in this
60-
? (this[DATA_SOURCE_OPTIONS_METHOD] as any)()
62+
// @ts-expect-error ts-error
63+
? this[DATA_SOURCE_OPTIONS_METHOD]()
6164
: {};
6265

6366
dataSourceType = this._dataSourceType ? this._dataSourceType() : DataSource;
6467

6568
dataSourceOptions = normalizeDataSourceOptions(dataSourceOptions, {
66-
fromUrlLoadMode: (DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD in this) && (this[DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD] as any)(),
69+
// @ts-expect-error ts-error
70+
fromUrlLoadMode: (DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD in this) && this[DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD](),
6771
});
6872

6973
// eslint-disable-next-line new-cap
7074
this._dataSource = new dataSourceType(extend(true, {}, widgetDataSourceOptions, dataSourceOptions));
7175
}
7276

7377
if (NORMALIZE_DATA_SOURCE in this) {
74-
this._dataSource = (this[NORMALIZE_DATA_SOURCE] as any)(this._dataSource);
78+
// @ts-expect-error ts-error
79+
this._dataSource = this[NORMALIZE_DATA_SOURCE](this._dataSource);
7580
}
7681

7782
this._addDataSourceHandlers();
7883
this._initDataController();
7984
}
8085
}
8186

82-
private _initDataController() {
87+
protected _initDataController() {
88+
// @ts-expect-error
8389
const dataController = this.option?.('_dataController');
8490
const dataSource = this._dataSource;
8591

@@ -183,5 +189,3 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl
183189
return this._dataSource || null;
184190
}
185191
};
186-
187-
export default DataHelperMixin;

packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { getOuterHeight, getOuterWidth } from '@js/core/utils/size';
2626
import { findTemplates } from '@js/core/utils/template_manager';
2727
import { isDefined, isFunction, isPlainObject } from '@js/core/utils/type';
2828
import type { DataSourceOptions } from '@js/data/data_source';
29-
import DataHelperMixin from '@js/data_helper';
3029
import type {
3130
Cancelable, DxEvent, EventInfo, ItemInfo,
3231
} from '@js/events';
@@ -35,6 +34,7 @@ import { focusable } from '@js/ui/widget/selectors';
3534
import { getPublicElement } from '@ts/core/m_element';
3635
import type { OptionChanged } from '@ts/core/widget/types';
3736
import Widget from '@ts/core/widget/widget';
37+
import { DataHelperMixin } from '@ts/data/m_data_helper';
3838
import CollectionWidgetItem from '@ts/ui/collection/m_item';
3939

4040
const COLLECTION_CLASS = 'dx-collection';
@@ -91,7 +91,11 @@ export interface CollectionWidgetBaseProperties<
9191

9292
focusOnSelectedItem?: boolean;
9393

94+
encodeNoDataText?: boolean;
95+
9496
_itemAttributes?: Record<string, string>;
97+
98+
selectOnFocus?: boolean;
9599
}
96100

97101
class CollectionWidget<
@@ -101,7 +105,7 @@ class CollectionWidget<
101105
TItem extends ItemLike = any,
102106
// eslint-disable-next-line @typescript-eslint/no-explicit-any
103107
TKey = any,
104-
> extends Widget<TProperties> {
108+
> extends DataHelperMixin(Widget)<TProperties> {
105109
private _focusedItemId?: string;
106110

107111
// eslint-disable-next-line no-restricted-globals
@@ -121,6 +125,8 @@ class CollectionWidget<
121125

122126
_itemFocusHandler?: () => void;
123127

128+
onFocusedItemChanged?: (event?: Partial<EventInfo<unknown> & ItemInfo<TItem>>) => void;
129+
124130
_inkRipple?: {
125131
showWave: (config: {
126132
element: dxElementWrapper;
@@ -234,14 +240,12 @@ class CollectionWidget<
234240

235241
_init(): void {
236242
this._compileDisplayGetter();
237-
// @ts-expect-error ts-error
238243
this._initDataController();
239244
super._init();
240245

241246
this._activeStateUnit = `.${ITEM_CLASS}`;
242247

243248
this._cleanRenderedItems();
244-
// @ts-expect-error ts-error
245249
this._refreshDataSource();
246250
}
247251

@@ -575,7 +579,7 @@ class CollectionWidget<
575579
this._updateFocusedItemState($target, true);
576580
// @ts-expect-error ts-error
577581
this.onFocusedItemChanged(this.getFocusedItemId());
578-
// @ts-expect-error ts-error
582+
579583
const { selectOnFocus } = this.option();
580584
const isTargetDisabled = this._isDisabled($target);
581585

@@ -683,7 +687,6 @@ class CollectionWidget<
683687
this._invalidate();
684688
break;
685689
case 'dataSource':
686-
// @ts-expect-error ts-error
687690
this._refreshDataSource();
688691
// @ts-expect-error ts-error
689692
this._renderEmptyMessage();
@@ -709,7 +712,6 @@ class CollectionWidget<
709712
this._attachContextMenuEvent();
710713
break;
711714
case 'onFocusedItemChanged':
712-
// @ts-expect-error ts-error
713715
this.onFocusedItemChanged = this._createActionByOption('onFocusedItemChanged');
714716
break;
715717
case 'selectOnFocus':
@@ -742,7 +744,6 @@ class CollectionWidget<
742744

743745
_loadNextPage(): Promise<unknown> {
744746
this._expectNextPageLoading();
745-
// @ts-expect-error ts-error
746747
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
747748
return this._dataController.loadNextPage();
748749
}
@@ -866,7 +867,6 @@ class CollectionWidget<
866867

867868
_initMarkup(): void {
868869
super._initMarkup();
869-
// @ts-expect-error ts-error
870870
this.onFocusedItemChanged = this._createActionByOption('onFocusedItemChanged');
871871

872872
this.$element().addClass(COLLECTION_CLASS);
@@ -1355,8 +1355,8 @@ class CollectionWidget<
13551355
_renderEmptyMessage(items: TItem[]): void {
13561356
// eslint-disable-next-line no-param-reassign
13571357
items = items || this.option('items');
1358-
const noDataText = this.option('noDataText');
1359-
// @ts-expect-error ts-error
1358+
const { noDataText } = this.option();
1359+
13601360
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
13611361
const hideNoData = !noDataText || (items && items.length) || this._dataController.isLoading();
13621362

@@ -1371,11 +1371,11 @@ class CollectionWidget<
13711371
this._$noData = this._$noData ?? $('<div>').addClass('dx-empty-message');
13721372
this._$noData.appendTo(this._emptyMessageContainer());
13731373

1374-
if (this.option('encodeNoDataText')) {
1375-
// @ts-expect-error ts-error
1374+
const { encodeNoDataText } = this.option();
1375+
1376+
if (encodeNoDataText) {
13761377
this._$noData.text(noDataText);
13771378
} else {
1378-
// @ts-expect-error ts-error
13791379
this._$noData.html(noDataText);
13801380
}
13811381
}
@@ -1483,9 +1483,6 @@ class CollectionWidget<
14831483
}
14841484
}
14851485

1486-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1487-
(CollectionWidget as any).include(DataHelperMixin);
1488-
14891486
// @ts-expect-error ts-error
14901487
CollectionWidget.ItemClass = CollectionWidgetItem;
14911488

packages/devextreme/js/__internal/ui/menu/m_menu.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ class Menu extends MenuBase {
427427
});
428428

429429
return extend(menuOptions, {
430-
// @ts-expect-error
431430
dataSource: this.getDataSource(),
432431
animationEnabled: !!this.option('animation'),
433432
onItemClick: this._treeviewItemClickHandler.bind(this),

0 commit comments

Comments
 (0)