-
Notifications
You must be signed in to change notification settings - Fork 673
Grids: move _stateStoringController definition from base dataController #34752
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
Open
anna-shakhova
wants to merge
4
commits into
DevExpress:main
Choose a base branch
from
anna-shakhova:move_state_storing_main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 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
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/devextreme/js/__internal/grids/data_grid/module_not_extended/state_storing.ts
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
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
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
85 changes: 85 additions & 0 deletions
85
...me/js/__internal/grids/grid_core/state_storing/extenders/state_storing_data_controller.ts
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import type { Callback } from '@js/core/utils/callbacks'; | ||
| import type { DeferredObj } from '@js/core/utils/deferred'; | ||
| import { Deferred } from '@js/core/utils/deferred'; | ||
| import { isDefined } from '@js/core/utils/type'; | ||
| import type { DataController } from '@ts/grids/grid_core/data_controller/data_controller'; | ||
| import type { ModuleType } from '@ts/grids/grid_core/m_types'; | ||
|
|
||
| import type { StateStoringController } from '../m_state_storing_controller'; | ||
|
|
||
| export interface StateStoringDataControllerExtension { | ||
| stateLoaded: Callback<[]>; | ||
| } | ||
|
|
||
| export const stateStoringDataControllerExtender = ( | ||
| Base: ModuleType<DataController>, | ||
| ): ModuleType< | ||
| DataController & StateStoringDataControllerExtension | ||
| > => class StateStoringDataExtender extends Base { | ||
| public stateLoaded!: Callback<[]>; | ||
|
|
||
| protected _stateStoringController!: StateStoringController; | ||
|
|
||
| private _restoreStateTimeoutID?: ReturnType<typeof setTimeout> | null; | ||
|
|
||
| public init(): void { | ||
| this._stateStoringController = this.getController('stateStoring'); | ||
| super.init(); | ||
| } | ||
|
|
||
| public dispose(): void { | ||
| clearTimeout(this._restoreStateTimeoutID ?? undefined); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| protected callbackNames(): string[] { | ||
| return super.callbackNames().concat(['stateLoaded']); | ||
| } | ||
|
|
||
| protected _refreshDataSource(): DeferredObj<unknown> | undefined { | ||
| if (this._stateStoringController.isEnabled() && !this._stateStoringController.isLoaded()) { | ||
| clearTimeout(this._restoreStateTimeoutID ?? undefined); | ||
|
|
||
| const deferred = Deferred(); | ||
| // eslint-disable-next-line no-restricted-globals | ||
| this._restoreStateTimeoutID = setTimeout(() => { | ||
| this._stateStoringController.load() | ||
| .always(() => { | ||
| this._restoreStateTimeoutID = null; | ||
| }) | ||
| .done(() => { | ||
| super._refreshDataSource(); | ||
|
|
||
| this.stateLoaded.fire(); | ||
| deferred.resolve(); | ||
| }) | ||
| .fail((error: Error) => { | ||
| this.stateLoaded.fire(); | ||
| this.loadErrorHandler(error ?? 'Unknown error'); | ||
| deferred.reject(); | ||
| }); | ||
| }); | ||
|
|
||
| // @ts-expect-error promise() is typed as Promise but returns a Deferred-like value at runtime | ||
| return deferred.promise(); | ||
| } | ||
|
|
||
| if (!this.isStateLoading()) { | ||
| super._refreshDataSource(); | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| public isLoading(): boolean { | ||
| return super.isLoading() || this._stateStoringController.isLoading(); | ||
| } | ||
|
|
||
| private isStateLoading(): boolean { | ||
| return isDefined(this._restoreStateTimeoutID); | ||
| } | ||
|
|
||
| public isLoaded(): boolean { | ||
| return super.isLoaded() && !this.isStateLoading(); | ||
| } | ||
| }; | ||
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
39 changes: 39 additions & 0 deletions
39
packages/devextreme/js/__internal/grids/grid_core/state_storing/state_storing_module.ts
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import type { StateStoring } from '@js/common/grids'; | ||
|
|
||
| import { stateStoringDataControllerExtender } from './extenders/state_storing_data_controller'; | ||
| import { | ||
| columns, | ||
| rowsView, | ||
| selection, | ||
| stateStoring, | ||
| } from './m_state_storing'; | ||
| import { StateStoringController } from './m_state_storing_controller'; | ||
|
|
||
| export const stateStoringModule = { | ||
| defaultOptions(): { stateStoring: StateStoring } { | ||
| return { | ||
| stateStoring: { | ||
| enabled: false, | ||
| storageKey: undefined, | ||
| type: 'localStorage', | ||
| customLoad: undefined, | ||
| customSave: undefined, | ||
| savingTimeout: 2000, | ||
| }, | ||
| }; | ||
| }, | ||
| controllers: { | ||
| stateStoring: StateStoringController, | ||
| }, | ||
| extenders: { | ||
| views: { | ||
| rowsView, | ||
| }, | ||
| controllers: { | ||
| stateStoring, | ||
| columns, | ||
| data: stateStoringDataControllerExtender, | ||
| selection, | ||
| }, | ||
| }, | ||
| }; |
Oops, something went wrong.
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.