-
Notifications
You must be signed in to change notification settings - Fork 672
GridCore - DataHelperMixin - fix eslint & typescript errors #34656
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
Merged
+67
−67
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,3 @@ | ||
| // TODO: fix the rules disabled below | ||
| /* eslint-disable @stylistic/max-len */ | ||
| /* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
| /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
| /* eslint-disable @typescript-eslint/init-declarations */ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /* eslint-disable @typescript-eslint/no-shadow */ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
| /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
| /* eslint-disable no-param-reassign */ | ||
| 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'; | ||
|
|
@@ -24,25 +14,33 @@ const DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD = '_dataSourceFromUrlLoadMode'; | |
| const SPECIFIC_DATA_SOURCE_OPTION = '_getSpecificDataSourceOption'; | ||
| const NORMALIZE_DATA_SOURCE = '_normalizeDataSource'; | ||
|
|
||
| type ProxiedDataSourceHandler = (...args: unknown[]) => void; | ||
|
|
||
| // TODO Get rid of this mixin | ||
| export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => class DataHelperMixin extends Base { | ||
| public _dataSource: any; | ||
| // eslint-disable-next-line @stylistic/max-len | ||
| // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type | ||
| export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => class extends Base { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| public _dataSource?: any; | ||
|
|
||
| protected _dataController?: DataController; | ||
|
|
||
| protected _dataController: any; | ||
| protected readyWatcher?: (isLoading: boolean) => void; | ||
|
|
||
| protected readyWatcher: any; | ||
| // Optional hook implemented by Widget-based consumers (see Widget#_ready). | ||
| protected _ready?: (value?: boolean) => void; | ||
|
|
||
| private _proxiedDataSourceChangedHandler: any; | ||
| private _proxiedDataSourceChangedHandler?: ProxiedDataSourceHandler; | ||
|
|
||
| private _proxiedDataSourceLoadErrorHandler: any; | ||
| private _proxiedDataSourceLoadErrorHandler?: ProxiedDataSourceHandler; | ||
|
|
||
| private _proxiedDataSourceLoadingChangedHandler: any; | ||
| private _proxiedDataSourceLoadingChangedHandler?: ProxiedDataSourceHandler; | ||
|
|
||
| protected _isSharedDataSource: any; | ||
| protected _isSharedDataSource?: boolean; | ||
|
|
||
| private readonly _dataSourceType: any; | ||
| private readonly _dataSourceType?: () => typeof DataSource; | ||
|
|
||
| public postCtor() { | ||
| public postInit(): void { | ||
| this.on('disposing', () => { | ||
| this._disposeDataSource(); | ||
| }); | ||
|
|
@@ -51,50 +49,55 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl | |
| /** | ||
| * @extended: state_storing, virtual_scrolling | ||
| */ | ||
| protected _refreshDataSource() { | ||
| protected _refreshDataSource(): void { | ||
| this._initDataSource(); | ||
| this._loadDataSource(); | ||
| } | ||
|
|
||
| protected _initDataSource() { | ||
| protected _initDataSource(): void { | ||
| let dataSourceOptions = SPECIFIC_DATA_SOURCE_OPTION in this | ||
| ? (this[SPECIFIC_DATA_SOURCE_OPTION] as any)() | ||
| // @ts-expect-error dynamic mixin method | ||
| ? 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] as any)() | ||
| const widgetDataSourceOptions = DATA_SOURCE_OPTIONS_METHOD in this | ||
| // @ts-expect-error dynamic mixin method | ||
| ? this[DATA_SOURCE_OPTIONS_METHOD]() | ||
| : {}; | ||
|
|
||
| dataSourceType = this._dataSourceType ? this._dataSourceType() : DataSource; | ||
| const 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] as any)(), | ||
| fromUrlLoadMode: (DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD in this) | ||
| // @ts-expect-error dynamic mixin method | ||
| && this[DATA_SOURCE_FROM_URL_LOAD_MODE_METHOD](), | ||
| }); | ||
|
|
||
| // eslint-disable-next-line new-cap | ||
| this._dataSource = new dataSourceType(extend(true, {}, widgetDataSourceOptions, dataSourceOptions)); | ||
| this._dataSource = new DataSourceType( | ||
| extend(true, {}, widgetDataSourceOptions, dataSourceOptions), | ||
| ); | ||
| } | ||
|
|
||
| if (NORMALIZE_DATA_SOURCE in this) { | ||
| this._dataSource = (this[NORMALIZE_DATA_SOURCE] as any)(this._dataSource); | ||
| // @ts-expect-error dynamic mixin method | ||
| this._dataSource = this[NORMALIZE_DATA_SOURCE](this._dataSource); | ||
| } | ||
|
|
||
| this._addDataSourceHandlers(); | ||
| this._initDataController(); | ||
| } | ||
| } | ||
|
|
||
| private _initDataController() { | ||
| private _initDataController(): void { | ||
| const dataController = this.option?.('_dataController'); | ||
| const dataSource = this._dataSource; | ||
|
|
||
|
|
@@ -105,7 +108,7 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl | |
| } | ||
| } | ||
|
|
||
| private _addDataSourceHandlers() { | ||
| private _addDataSourceHandlers(): void { | ||
| if (DATA_SOURCE_CHANGED_METHOD in this) { | ||
| this._addDataSourceChangeHandler(); | ||
| } | ||
|
|
@@ -121,63 +124,59 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl | |
| this._addReadyWatcher(); | ||
| } | ||
|
|
||
| private _addReadyWatcher() { | ||
| this.readyWatcher = function (isLoading) { | ||
| this._ready && this._ready(!isLoading); | ||
| }.bind(this); | ||
| private _addReadyWatcher(): void { | ||
| this.readyWatcher = (isLoading: boolean): void => { | ||
| this._ready?.(!isLoading); | ||
| }; | ||
| this._dataSource.on('loadingChanged', this.readyWatcher); | ||
| } | ||
|
|
||
| private _addDataSourceChangeHandler() { | ||
| private _addDataSourceChangeHandler(): void { | ||
| const dataSource = this._dataSource; | ||
| this._proxiedDataSourceChangedHandler = function (e) { | ||
| this._proxiedDataSourceChangedHandler = (e): void => { | ||
| this[DATA_SOURCE_CHANGED_METHOD](dataSource.items(), e); | ||
| }.bind(this); | ||
| }; | ||
| dataSource.on('changed', this._proxiedDataSourceChangedHandler); | ||
| } | ||
|
|
||
| private _addDataSourceLoadErrorHandler() { | ||
| private _addDataSourceLoadErrorHandler(): void { | ||
| this._proxiedDataSourceLoadErrorHandler = this[DATA_SOURCE_LOAD_ERROR_METHOD].bind(this); | ||
| this._dataSource.on('loadError', this._proxiedDataSourceLoadErrorHandler); | ||
| } | ||
|
|
||
| private _addDataSourceLoadingChangedHandler() { | ||
| this._proxiedDataSourceLoadingChangedHandler = this[DATA_SOURCE_LOADING_CHANGED_METHOD].bind(this); | ||
| private _addDataSourceLoadingChangedHandler(): void { | ||
| this._proxiedDataSourceLoadingChangedHandler = this[DATA_SOURCE_LOADING_CHANGED_METHOD] | ||
| .bind(this); | ||
| this._dataSource.on('loadingChanged', this._proxiedDataSourceLoadingChangedHandler); | ||
| } | ||
|
|
||
| protected _loadDataSource() { | ||
| protected _loadDataSource(): void { | ||
| const dataSource = this._dataSource; | ||
| if (dataSource) { | ||
| if (dataSource.isLoaded()) { | ||
| this._proxiedDataSourceChangedHandler && this._proxiedDataSourceChangedHandler(); | ||
| if (this._proxiedDataSourceChangedHandler) { | ||
| this._proxiedDataSourceChangedHandler(); | ||
| } | ||
| } else { | ||
| dataSource.load(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private _loadSingle(key, value) { | ||
| key = key === 'this' ? this._dataSource.key() || 'this' : key; | ||
| return this._dataSource.loadSingle(key, value); | ||
| } | ||
|
|
||
| private _isLastPage() { | ||
| return !this._dataSource || this._dataSource.isLastPage() || !this._dataSource._pageSize; | ||
| } | ||
|
|
||
| private _isDataSourceLoading() { | ||
| return this._dataSource && this._dataSource.isLoading(); | ||
| } | ||
|
Comment on lines
-160
to
-171
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these methods were never used |
||
|
|
||
| protected _disposeDataSource() { | ||
| protected _disposeDataSource(): void { | ||
| 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._proxiedDataSourceChangedHandler) { | ||
| this._dataSource.off('changed', this._proxiedDataSourceChangedHandler); | ||
| } | ||
| if (this._proxiedDataSourceLoadErrorHandler) { | ||
| this._dataSource.off('loadError', this._proxiedDataSourceLoadErrorHandler); | ||
| } | ||
| if (this._proxiedDataSourceLoadingChangedHandler) { | ||
| this._dataSource.off('loadingChanged', this._proxiedDataSourceLoadingChangedHandler); | ||
| } | ||
|
|
||
| if (this._dataSource._eventsStrategy) { | ||
| this._dataSource._eventsStrategy.off('loadingChanged', this.readyWatcher); | ||
|
|
@@ -194,7 +193,8 @@ export const DataHelperMixin = <T extends ModuleType<Controller>>(Base: T) => cl | |
| } | ||
| } | ||
|
|
||
| protected getDataSource() { | ||
| return this._dataSource || null; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| protected getDataSource(): any | null { | ||
| return this._dataSource ?? null; | ||
| } | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.