@@ -29,6 +29,7 @@ import Selection from '@ts/ui/selection/m_selection';
2929
3030import type MenuBaseEditStrategy from '../context_menu/m_menu_base.edit.strategy' ;
3131import type GroupedEditStrategy from '../list/m_list.edit.strategy.grouped' ;
32+ import type DataController from './m_data_controller' ;
3233
3334const ITEM_DELETING_DATA_KEY = 'dxItemDeleting' ;
3435const SELECTED_ITEM_CLASS = 'dx-item-selected' ;
@@ -72,6 +73,10 @@ class CollectionWidget<
7273
7374 _rendering ?: boolean ;
7475
76+ _dataController ! : DataController ;
77+
78+ _keyGetter ! : ( item : TItem ) => TKey ;
79+
7580 _setOptionsByReference ( ) : void {
7681 super . _setOptionsByReference ( ) ;
7782
@@ -120,10 +125,13 @@ class CollectionWidget<
120125 }
121126
122127 _initKeyGetter ( ) : void {
123- // @ts -expect-error ts-error
124- this . _keyGetter = compileGetter ( this . option ( 'keyExpr' ) ) ;
128+ const { keyExpr } = this . option ( ) ;
129+
130+ // @ts -expect-error compileGetter
131+ this . _keyGetter = compileGetter ( keyExpr ) ;
125132 }
126133
134+ // eslint-disable-next-line class-methods-use-this
127135 _selectedItemClass ( ) : string {
128136 return SELECTED_ITEM_CLASS ;
129137 }
@@ -144,7 +152,7 @@ class CollectionWidget<
144152 } ) ;
145153 }
146154
147- _getKeysByItems ( selectedItems ) {
155+ _getKeysByItems ( selectedItems : TItem [ ] ) {
148156 return this . _editStrategy . getKeysByItems ( selectedItems ) ;
149157 }
150158
@@ -160,41 +168,39 @@ class CollectionWidget<
160168 return this . _editStrategy . getIndexByKey ( key ) ;
161169 }
162170
163- _getIndexByItemData ( itemData ) {
171+ _getIndexByItemData ( itemData ) : number {
164172 return this . _editStrategy . getIndexByItemData ( itemData ) ;
165173 }
166174
167- _isKeySpecified ( ) {
168- // @ts -expect-error ts-error
175+ _isKeySpecified ( ) : boolean {
169176 return ! ! this . _dataController . key ( ) ;
170177 }
171178
172179 _getCombinedFilter ( ) {
173- // @ts -expect-error ts-error
180+ // @ts -expect-error arguments
174181 return this . _dataController . filter ( ) ;
175182 }
176183
177- key ( ) {
184+ key ( ) : string | Function | undefined {
178185 const { keyExpr } = this . option ( ) ;
179- if ( keyExpr ) return keyExpr ;
180- // @ts -expect-error ts-error
181- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
186+
187+ if ( keyExpr ) {
188+ return keyExpr ;
189+ }
190+
182191 return this . _dataController . key ( ) ;
183192 }
184193
185- keyOf ( item ) {
186- let key = item ;
187-
194+ keyOf ( item : TItem ) {
188195 if ( this . option ( 'keyExpr' ) ) {
189- // @ts -expect-error ts-error
190- key = this . _keyGetter ( item ) ;
191- // @ts -expect-error ts-error
192- } else if ( this . _dataController . store ( ) ) {
193- // @ts -expect-error ts-error
194- key = this . _dataController . keyOf ( item ) ;
196+ return this . _keyGetter ( item ) ;
197+ }
198+
199+ if ( this . _dataController . store ( ) ) {
200+ return this . _dataController . keyOf ( item ) ;
195201 }
196202
197- return key ;
203+ return item ;
198204 }
199205
200206 // eslint-disable-next-line class-methods-use-this
@@ -233,18 +239,15 @@ class CollectionWidget<
233239 } ,
234240 filter : this . _getCombinedFilter . bind ( this ) ,
235241 totalCount : ( ) : number => {
236- const { items } = this . option ( ) ;
237- // @ts -expect-error ts-error
242+ const { items = [ ] } = this . option ( ) ;
238243 const totalCount : number = this . _dataController . totalCount ( ) ;
239244 return totalCount >= 0
240245 ? totalCount
241- // @ts -expect-error ts-error
242246 : this . _getItemsCount ( items ) ;
243247 } ,
244248 key : this . key . bind ( this ) ,
245249 keyOf : this . keyOf . bind ( this ) ,
246250 load ( options ) : DeferredObj < unknown > {
247- // @ts -expect-error ts-error
248251 const dataController = that . _dataController ;
249252 options . customQueryParams = dataController . loadOptions ( ) ?. customQueryParams ;
250253 options . userData = dataController . userData ( ) ;
@@ -254,27 +257,26 @@ class CollectionWidget<
254257 if ( that . _disposed ) {
255258 return ;
256259 }
257- // @ts -expect-error
260+ // @ts -expect-error arguments
258261 const items = normalizeLoadResult ( loadResult ) . data ;
259262
260263 dataController . applyMapFunction ( items ) ;
261264 } ) ;
262265 }
263266 return Deferred ( ) . resolve ( this . plainItems ( ) ) ;
264267 } ,
265- // @ts -expect-error ts-error
266268 dataFields : ( ) => this . _dataController . select ( ) ,
267269 plainItems : itemsGetter . bind ( this . _editStrategy ) ,
268270 } ) ;
269271 }
270272
271273 _getItemsCount ( items : TItem [ ] ) : number {
272- // @ts -expect-error ts-error
273- // eslint-disable-next-line no-return-assign
274- return items . reduce ( ( itemsCount , item ) => itemsCount += item . items
275- // @ts -expect-error ts-error
276- ? this . _getItemsCount ( item . items )
277- : 1 , 0 ) ;
274+ return items . reduce ( ( itemsCount , item ) => {
275+ // @ts -expect-error subItems
276+ const subItemsCount = item . items ? this . _getItemsCount ( item . items ) : 1 ;
277+
278+ return itemsCount + subItemsCount ;
279+ } , 0 ) ;
278280 }
279281
280282 _initEditStrategy ( ) : void {
@@ -303,7 +305,6 @@ class CollectionWidget<
303305
304306 _initMarkup ( ) : void {
305307 this . _rendering = true ;
306- // @ts -expect-error ts-error
307308 if ( ! this . _dataController . isLoading ( ) ) {
308309 this . _syncSelectionOptions ( ) . done ( ( ) => this . _normalizeSelectedItems ( ) ) ;
309310 }
@@ -438,7 +439,7 @@ class CollectionWidget<
438439 }
439440
440441 _normalizeSelectedItems ( ) : Promise < unknown > {
441- const { selectionMode, selectedItems, items } = this . option ( ) ;
442+ const { selectionMode, selectedItems = [ ] , items } = this . option ( ) ;
442443
443444 if ( selectionMode === 'none' ) {
444445 this . _setOptionWithoutOptionChange ( 'selectedItems' , [ ] ) ;
@@ -448,10 +449,8 @@ class CollectionWidget<
448449
449450 if ( newSelection . length > 1 || ! newSelection . length && this . option ( 'selectionRequired' ) && items ?. length ) {
450451 const currentSelection = this . _selection . getSelectedItems ( ) ;
451- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
452- let normalizedSelection = newSelection [ 0 ] === undefined
453- ? currentSelection [ 0 ]
454- : newSelection [ 0 ] ;
452+
453+ let normalizedSelection = newSelection [ 0 ] ?? currentSelection [ 0 ] ;
455454
456455 if ( normalizedSelection === undefined ) {
457456 // eslint-disable-next-line prefer-destructuring
@@ -470,7 +469,7 @@ class CollectionWidget<
470469 }
471470 this . _selection . setSelection ( this . _getKeysByItems ( newSelection ) ) ;
472471 } else {
473- const newKeys = this . _getKeysByItems ( this . option ( ' selectedItems' ) ) ;
472+ const newKeys = this . _getKeysByItems ( selectedItems ) ;
474473 const oldKeys = this . _selection . getSelectedItemKeys ( ) ;
475474 if ( ! this . _compareKeys ( oldKeys , newKeys ) ) {
476475 this . _selection . setSelection ( newKeys ) ;
@@ -516,7 +515,7 @@ class CollectionWidget<
516515 } else {
517516 const itemSelectPromise = this . selectItem ( e . currentTarget ) ;
518517
519- // @ts -expect-error ts-error
518+ // @ts -expect-error Promise DefferedObj
520519 // eslint-disable-next-line consistent-return
521520 return itemSelectPromise ?. promise ( ) ;
522521 }
@@ -555,23 +554,21 @@ class CollectionWidget<
555554
556555 if ( this . _rendered && ( addedItemKeys . length || removedItemKeys . length ) ) {
557556 if ( ! this . _rendering ) {
558- const addedSelection = [ ] ;
559- const removedSelection = [ ] ;
557+ const addedSelection : number [ ] = [ ] ;
558+ const removedSelection : number [ ] = [ ] ;
560559
561560 this . _editStrategy . beginCache ( ) ;
562561
563562 // eslint-disable-next-line @typescript-eslint/prefer-for-of
564563 for ( let i = 0 ; i < addedItemKeys . length ; i += 1 ) {
565564 const normalizedIndex = this . _getIndexByKey ( addedItemKeys [ i ] ) ;
566- // @ts -expect-error ts-error
567565 addedSelection . push ( normalizedIndex ) ;
568566 this . _addSelection ( normalizedIndex ) ;
569567 }
570568
571569 // eslint-disable-next-line @typescript-eslint/prefer-for-of
572570 for ( let i = 0 ; i < removedItemKeys . length ; i += 1 ) {
573571 const normalizedIndex = this . _getIndexByKey ( removedItemKeys [ i ] ) ;
574- // @ts -expect-error ts-error
575572 removedSelection . push ( normalizedIndex ) ;
576573 this . _removeSelection ( normalizedIndex ) ;
577574 }
@@ -616,7 +613,7 @@ class CollectionWidget<
616613
617614 if ( indexExists ( normalizedIndex ) ) {
618615 this . _processSelectableItem ( $itemElement , false ) ;
619- // @ts -expect-error ts-error
616+ // @ts -expect-error arguments
620617 eventsEngine . triggerHandler ( $itemElement , 'stateChanged' , false ) ;
621618 }
622619 }
@@ -626,7 +623,7 @@ class CollectionWidget<
626623
627624 if ( indexExists ( normalizedIndex ) ) {
628625 this . _processSelectableItem ( $itemElement , true ) ;
629- // @ts -expect-error ts-error
626+ // @ts -expect-error arguments
630627 eventsEngine . triggerHandler ( $itemElement , 'stateChanged' , true ) ;
631628 }
632629 }
@@ -644,7 +641,7 @@ class CollectionWidget<
644641 break ;
645642 case 'dataSource' :
646643
647- if ( ! args . value || Array . isArray ( args . value ) && ! args . value . length ) {
644+ if ( ! args . value || ( Array . isArray ( args . value ) && ! args . value . length ) ) {
648645 this . option ( 'selectedItemKeys' , [ ] ) ;
649646 }
650647
@@ -729,7 +726,6 @@ class CollectionWidget<
729726 }
730727
731728 _deleteItemFromDS ( $item : dxElementWrapper ) : Promise < unknown > | DeferredObj < unknown > {
732- // @ts -expect-error ts-error
733729 const dataController = this . _dataController ;
734730 const deferred = Deferred ( ) ;
735731 const disabledState = this . option ( 'disabled' ) ;
@@ -766,7 +762,7 @@ class CollectionWidget<
766762
767763 _tryRefreshLastPage ( ) : Promise < unknown > {
768764 const deferred = Deferred ( ) ;
769- // @ts -expect-error ts-error
765+ // @ts -expect-error mixin method
770766 if ( this . _isLastPage ( ) || this . option ( 'grouped' ) ) {
771767 deferred . resolve ( ) ;
772768 } else {
@@ -780,8 +776,7 @@ class CollectionWidget<
780776
781777 _refreshLastPage ( ) : DeferredObj < unknown > {
782778 this . _expectLastItemLoading ( ) ;
783- // @ts -expect-error ts-error
784- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
779+
785780 return this . _dataController . load ( ) ;
786781 }
787782
@@ -869,7 +864,6 @@ class CollectionWidget<
869864 $item : dxElementWrapper ,
870865 deletedActionArgs : ItemInfo < TItem > ,
871866 ) : void {
872- // @ts -expect-error ts-error
873867 const changingOption = this . _dataController . getDataSource ( )
874868 ? 'dataSource'
875869 : 'items' ;
@@ -890,15 +884,15 @@ class CollectionWidget<
890884 const itemResponseWaitClass = this . _itemResponseWaitClass ( ) ;
891885
892886 if ( indexExists ( index ) ) {
893- // @ts -expect-error ts-error
887+ // @ts -expect-error Promise DefferedObj
894888 this . _waitDeletingPrepare ( $item ) . done ( ( ) => {
895889 $item . addClass ( itemResponseWaitClass ) ;
896890 const deletedActionArgs = this . _extendActionArgs ( $item ) ;
897- // @ts -expect-error ts-error
891+ // @ts -expect-error Promise DefferedObj
898892 this . _deleteItemFromDS ( $item ) . done ( ( ) => {
899893 this . _deleteItemElementByIndex ( index ) ;
900894 this . _afterItemElementDeleted ( $item , deletedActionArgs ) ;
901- // @ts -expect-error ts-error
895+ // @ts -expect-error Promise DefferedObj
902896 this . _tryRefreshLastPage ( ) . done ( ( ) => {
903897 // @ts -expect-error ts-error
904898
@@ -932,7 +926,6 @@ class CollectionWidget<
932926 const $destinationItem = strategy . getItemElement ( toItemElement ) ;
933927 const movingIndex = strategy . getNormalizedIndex ( itemElement ) ;
934928 const destinationIndex = strategy . getNormalizedIndex ( toItemElement ) ;
935- // @ts -expect-error ts-error
936929 const changingOption = this . _dataController . getDataSource ( )
937930 ? 'dataSource'
938931 : 'items' ;
@@ -949,7 +942,7 @@ class CollectionWidget<
949942
950943 deferred . rejectWith ( this ) ;
951944 }
952- // @ts -expect-error ts-error
945+ // @ts -expect-error Promise DefferedObj
953946 // eslint-disable-next-line @typescript-eslint/no-unsafe-return
954947 return deferred . promise ( ) . done ( ( ) => {
955948 $destinationItem [ strategy . itemPlacementFunc ( movingIndex , destinationIndex ) ] ( $movingItem ) ;
0 commit comments