diff --git a/packages/devextreme/js/__internal/core/m_class.ts b/packages/devextreme/js/__internal/core/m_class.ts index d6717599258..6f5efe98a97 100644 --- a/packages/devextreme/js/__internal/core/m_class.ts +++ b/packages/devextreme/js/__internal/core/m_class.ts @@ -40,6 +40,7 @@ const redefine = function (members) { }; const include = function (...args) { + debugger; const classObj = this; let argument; let name; diff --git a/packages/devextreme/js/__internal/data/m_data_helper.ts b/packages/devextreme/js/__internal/data/m_data_helper.ts index 255fce44846..b9499ff9641 100644 --- a/packages/devextreme/js/__internal/data/m_data_helper.ts +++ b/packages/devextreme/js/__internal/data/m_data_helper.ts @@ -1,8 +1,7 @@ - -import { DataSource } from '../../common/data/data_source/data_source'; -import { extend } from '../../core/utils/extend'; -import { normalizeDataSourceOptions } from '../../common/data/data_source/utils'; -import DataController from '../ui/collection/m_data_controller'; +import { DataSource } from '@js/common/data/data_source/data_source'; +import { normalizeDataSourceOptions } from '@js/common/data/data_source/utils'; +import { extend } from '@js/core/utils/extend'; +import DataController from '@ts/ui/collection/m_data_controller'; const DATA_SOURCE_OPTIONS_METHOD = '_dataSourceOptions'; const DATA_SOURCE_CHANGED_METHOD = '_dataSourceChangedHandler'; @@ -12,155 +11,159 @@ const DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD = '_dataSourceFromUrlLoadMode'; const SPECIFIC_DATA_SOURCE_OPTION = '_getSpecificDataSourceOption'; const NORMALIZE_DATA_SOURCE = '_normalizeDataSource'; +export const DataHelperMixin = { + postCtor(): void { + this.on('disposing', () => { + this._disposeDataSource(); + }); + }, + + _refreshDataSource(): void { + this._initDataSource(); + this._loadDataSource(); + }, + + _initDataSource(): void { + let dataSourceOptions = SPECIFIC_DATA_SOURCE_OPTION in this + ? this[SPECIFIC_DATA_SOURCE_OPTION]() + : this.option('dataSource'); + + let widgetDataSourceOptions; + let dataSourceType; + + this._disposeDataSource(); + + if (dataSourceOptions) { + if (dataSourceOptions instanceof DataSource) { + this._isSharedDataSource = true; + this._dataSource = dataSourceOptions; + } else { + widgetDataSourceOptions = DATA_SOURCE_OPTIONS_METHOD in this + ? this[DATA_SOURCE_OPTIONS_METHOD]() + : {}; + + dataSourceType = this._dataSourceType ? this._dataSourceType() : DataSource; + + dataSourceOptions = normalizeDataSourceOptions(dataSourceOptions, { + fromUrlLoadMode: (DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD in this) && this[DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD](), + }); + + // eslint-disable-next-line new-cap + this._dataSource = new dataSourceType(extend(true, {}, widgetDataSourceOptions, dataSourceOptions)); + } + + if (NORMALIZE_DATA_SOURCE in this) { + this._dataSource = this[NORMALIZE_DATA_SOURCE](this._dataSource); + } + + this._addDataSourceHandlers(); + this._initDataController(); + } + }, -const DataHelperMixin = { - - postCtor: function() { - this.on('disposing', function() { - this._disposeDataSource(); - }.bind(this)); - }, - - _refreshDataSource: function() { - this._initDataSource(); - this._loadDataSource(); - }, - - _initDataSource: function() { - let dataSourceOptions = (SPECIFIC_DATA_SOURCE_OPTION in this) ? this[SPECIFIC_DATA_SOURCE_OPTION]() : this.option('dataSource'); - let widgetDataSourceOptions; - let dataSourceType; + _initDataController(): void { + const dataController = this.option?.('_dataController'); + const dataSource = this._dataSource; - this._disposeDataSource(); + if (dataController) { + this._dataController = dataController; + } else { + this._dataController = new DataController(dataSource); + } + }, - if(dataSourceOptions) { - if(dataSourceOptions instanceof DataSource) { - this._isSharedDataSource = true; - this._dataSource = dataSourceOptions; - } else { - widgetDataSourceOptions = (DATA_SOURCE_OPTIONS_METHOD in this) ? this[DATA_SOURCE_OPTIONS_METHOD]() : {}; - dataSourceType = this._dataSourceType ? this._dataSourceType() : DataSource; + _addDataSourceHandlers(): void { + if (DATA_SOURCE_CHANGED_METHOD in this) { + this._addDataSourceChangeHandler(); + } - dataSourceOptions = normalizeDataSourceOptions(dataSourceOptions, { - fromUrlLoadMode: (DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD in this) && this[DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD]() - }); + if (DATA_SOURCE_LOAD_ERROR_METHOD in this) { + this._addDataSourceLoadErrorHandler(); + } - this._dataSource = new dataSourceType(extend(true, {}, widgetDataSourceOptions, dataSourceOptions)); - } + if (DATA_SOURCE_LOADING_CHANGED_METHOD in this) { + this._addDataSourceLoadingChangedHandler(); + } - if(NORMALIZE_DATA_SOURCE in this) { - this._dataSource = this[NORMALIZE_DATA_SOURCE](this._dataSource); - } + this._addReadyWatcher(); + }, + + _addReadyWatcher(): void { + this.readyWatcher = function (isLoading) { + this._ready && this._ready(!isLoading); + }.bind(this); + this._dataSource.on('loadingChanged', this.readyWatcher); + }, + + _addDataSourceChangeHandler(): void { + const dataSource = this._dataSource; + this._proxiedDataSourceChangedHandler = function (e) { + this[DATA_SOURCE_CHANGED_METHOD](dataSource.items(), e); + }.bind(this); + dataSource.on('changed', this._proxiedDataSourceChangedHandler); + }, + + _addDataSourceLoadErrorHandler(): void { + this._proxiedDataSourceLoadErrorHandler = this[DATA_SOURCE_LOAD_ERROR_METHOD].bind(this); + this._dataSource.on('loadError', this._proxiedDataSourceLoadErrorHandler); + }, + + _addDataSourceLoadingChangedHandler(): void { + this._proxiedDataSourceLoadingChangedHandler = this[DATA_SOURCE_LOADING_CHANGED_METHOD].bind(this); + this._dataSource.on('loadingChanged', this._proxiedDataSourceLoadingChangedHandler); + }, + + _loadDataSource(): void { + const dataSource = this._dataSource; + if (dataSource) { + if (dataSource.isLoaded()) { + this._proxiedDataSourceChangedHandler && this._proxiedDataSourceChangedHandler(); + } else { + dataSource.load(); + } + } + }, - this._addDataSourceHandlers(); - this._initDataController(); - } - }, + _loadSingle(key, value) { + key = key === 'this' ? this._dataSource.key() || 'this' : key; + return this._dataSource.loadSingle(key, value); + }, - _initDataController: function() { - const dataController = this.option?.('_dataController'); - const dataSource = this._dataSource; + _isLastPage(): boolean { + return !this._dataSource || this._dataSource.isLastPage() || !this._dataSource._pageSize; + }, - if(dataController) { - this._dataController = dataController; - } else { - this._dataController = new DataController(dataSource); - } - }, + _isDataSourceLoading() { + return this._dataSource && this._dataSource.isLoading(); + }, - _addDataSourceHandlers: function() { - if(DATA_SOURCE_CHANGED_METHOD in this) { - this._addDataSourceChangeHandler(); - } + _disposeDataSource(): void { + if (this._dataSource) { + if (this._isSharedDataSource) { + delete this._isSharedDataSource; - if(DATA_SOURCE_LOAD_ERROR_METHOD in this) { - this._addDataSourceLoadErrorHandler(); - } + this._proxiedDataSourceChangedHandler && this._dataSource.off('changed', this._proxiedDataSourceChangedHandler); + this._proxiedDataSourceLoadErrorHandler && this._dataSource.off('loadError', this._proxiedDataSourceLoadErrorHandler); + this._proxiedDataSourceLoadingChangedHandler && this._dataSource.off('loadingChanged', this._proxiedDataSourceLoadingChangedHandler); - if(DATA_SOURCE_LOADING_CHANGED_METHOD in this) { - this._addDataSourceLoadingChangedHandler(); + if (this._dataSource._eventsStrategy) { + this._dataSource._eventsStrategy.off('loadingChanged', this.readyWatcher); } + } else { + this._dataSource.dispose(); + } - this._addReadyWatcher(); - }, - - _addReadyWatcher: function() { - this.readyWatcher = (function(isLoading) { - this._ready && this._ready(!isLoading); - }).bind(this); - this._dataSource.on('loadingChanged', this.readyWatcher); - }, - - _addDataSourceChangeHandler: function() { - const dataSource = this._dataSource; - this._proxiedDataSourceChangedHandler = (function(e) { - this[DATA_SOURCE_CHANGED_METHOD](dataSource.items(), e); - }).bind(this); - dataSource.on('changed', this._proxiedDataSourceChangedHandler); - }, - - _addDataSourceLoadErrorHandler: function() { - this._proxiedDataSourceLoadErrorHandler = this[DATA_SOURCE_LOAD_ERROR_METHOD].bind(this); - this._dataSource.on('loadError', this._proxiedDataSourceLoadErrorHandler); - }, - - _addDataSourceLoadingChangedHandler: function() { - this._proxiedDataSourceLoadingChangedHandler = this[DATA_SOURCE_LOADING_CHANGED_METHOD].bind(this); - this._dataSource.on('loadingChanged', this._proxiedDataSourceLoadingChangedHandler); - }, - - _loadDataSource: function() { - const dataSource = this._dataSource; - if(dataSource) { - if(dataSource.isLoaded()) { - this._proxiedDataSourceChangedHandler && this._proxiedDataSourceChangedHandler(); - } else { - dataSource.load(); - } - } - }, - - _loadSingle: function(key, value) { - key = key === 'this' ? this._dataSource.key() || 'this' : key; - return this._dataSource.loadSingle(key, value); - }, - - _isLastPage: function() { - return !this._dataSource || this._dataSource.isLastPage() || !this._dataSource._pageSize; - }, - - _isDataSourceLoading: function() { - return this._dataSource && this._dataSource.isLoading(); - }, - - _disposeDataSource: function() { - if(this._dataSource) { - if(this._isSharedDataSource) { - delete this._isSharedDataSource; - - this._proxiedDataSourceChangedHandler && this._dataSource.off('changed', this._proxiedDataSourceChangedHandler); - this._proxiedDataSourceLoadErrorHandler && this._dataSource.off('loadError', this._proxiedDataSourceLoadErrorHandler); - this._proxiedDataSourceLoadingChangedHandler && this._dataSource.off('loadingChanged', this._proxiedDataSourceLoadingChangedHandler); - - if(this._dataSource._eventsStrategy) { - this._dataSource._eventsStrategy.off('loadingChanged', this.readyWatcher); - } - } else { - this._dataSource.dispose(); - } - - delete this._dataSource; - - delete this._proxiedDataSourceChangedHandler; - delete this._proxiedDataSourceLoadErrorHandler; - delete this._proxiedDataSourceLoadingChangedHandler; - } - }, + delete this._dataSource; - getDataSource: function() { - return this._dataSource || null; + delete this._proxiedDataSourceChangedHandler; + delete this._proxiedDataSourceLoadErrorHandler; + delete this._proxiedDataSourceLoadingChangedHandler; } + }, + getDataSource() { + return this._dataSource || null; + }, }; export default DataHelperMixin; diff --git a/packages/devextreme/js/__internal/scheduler/m_scheduler.ts b/packages/devextreme/js/__internal/scheduler/m_scheduler.ts index f4a4354f5e7..b07f185b3f0 100644 --- a/packages/devextreme/js/__internal/scheduler/m_scheduler.ts +++ b/packages/devextreme/js/__internal/scheduler/m_scheduler.ts @@ -1,7 +1,6 @@ import { triggerResizeEvent } from '@js/common/core/events/visibility_change'; import dateLocalization from '@js/common/core/localization/date'; import messageLocalization from '@js/common/core/localization/message'; -import DataHelperMixin from '@ts/data/m_data_helper'; import registerComponent from '@js/core/component_registrator'; import config from '@js/core/config'; import devices from '@js/core/devices'; @@ -30,6 +29,7 @@ import { isString, } from '@js/core/utils/type'; import { hasWindow } from '@js/core/utils/window'; +import DataHelperMixin from '@js/data_helper'; import { custom as customDialog } from '@js/ui/dialog'; import type { AppointmentTooltipShowingEvent, ViewType } from '@js/ui/scheduler'; import { isMaterial, isMaterialBased } from '@js/ui/themes'; diff --git a/packages/devextreme/js/__internal/ui/chat/chat.ts b/packages/devextreme/js/__internal/ui/chat/chat.ts index 4308d907628..fa9b0b4f20b 100644 --- a/packages/devextreme/js/__internal/ui/chat/chat.ts +++ b/packages/devextreme/js/__internal/ui/chat/chat.ts @@ -1,11 +1,11 @@ import { Guid } from '@js/common'; import messageLocalization from '@js/common/core/localization/message'; import type { DataSourceOptions } from '@js/common/data'; -import DataHelperMixin from '@ts/data/m_data_helper'; import registerComponent from '@js/core/component_registrator'; import type { dxElementWrapper } from '@js/core/renderer'; import $ from '@js/core/renderer'; import { isDefined } from '@js/core/utils/type'; +import DataHelperMixin from '@js/data_helper'; import type { Message, MessageEnteredEvent, diff --git a/packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts b/packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts index 224a297208b..e3893da4f76 100644 --- a/packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts +++ b/packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts @@ -26,6 +26,7 @@ import { getOuterHeight, getOuterWidth } from '@js/core/utils/size'; import { findTemplates } from '@js/core/utils/template_manager'; import { isDefined, isFunction, isPlainObject } from '@js/core/utils/type'; import type { DataSourceOptions } from '@js/data/data_source'; +import DataHelperMixin from '@js/data_helper'; import type { Cancelable, DxEvent, EventInfo, ItemInfo, } from '@js/events'; @@ -34,7 +35,6 @@ import { focusable } from '@js/ui/widget/selectors'; import { getPublicElement } from '@ts/core/m_element'; import type { OptionChanged } from '@ts/core/widget/types'; import Widget from '@ts/core/widget/widget'; -import DataHelperMixin from '@ts/data/m_data_helper'; import CollectionWidgetItem from '@ts/ui/collection/m_item'; const COLLECTION_CLASS = 'dx-collection'; diff --git a/packages/devextreme/js/__internal/ui/editor/m_data_expression.ts b/packages/devextreme/js/__internal/ui/editor/m_data_expression.ts index 8e84dc2aed5..369fb532d86 100644 --- a/packages/devextreme/js/__internal/ui/editor/m_data_expression.ts +++ b/packages/devextreme/js/__internal/ui/editor/m_data_expression.ts @@ -1,5 +1,4 @@ import ArrayStore from '@js/common/data/array_store'; -import DataHelperMixin from '@ts/data/m_data_helper'; import DataSource from '@js/common/data/data_source'; import { ensureDefined, noop } from '@js/core/utils/common'; import { @@ -12,6 +11,7 @@ import { isDefined, isFunction, isObject as isObjectType, isString, } from '@js/core/utils/type'; import variableWrapper from '@js/core/utils/variable_wrapper'; +import DataHelperMixin from '@js/data_helper'; const DataExpressionMixin = extend({}, DataHelperMixin, { diff --git a/packages/devextreme/js/data_helper.js b/packages/devextreme/js/data_helper.js index 6af09beb52c..c571549071c 100644 --- a/packages/devextreme/js/data_helper.js +++ b/packages/devextreme/js/data_helper.js @@ -1,3 +1,3 @@ -import { DataHelperMixin } from './common/data'; +import { DataHelperMixin } from './__internal/data/m_data_helper'; export default DataHelperMixin; diff --git a/packages/devextreme/js/viz/core/data_source.js b/packages/devextreme/js/viz/core/data_source.js index c7a4b6d2be4..5f33a3c1ee9 100644 --- a/packages/devextreme/js/viz/core/data_source.js +++ b/packages/devextreme/js/viz/core/data_source.js @@ -1,5 +1,5 @@ import { noop } from '../../core/utils/common'; -import DataHelperMixin from '../../__internal/data/m_data_helper'; +import DataHelperMixin from '../../data_helper'; const postCtor = DataHelperMixin.postCtor; let name; const members = {