@@ -218,7 +218,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
218
218
*/
219
219
getItemIndex ( item : CdkDrag ) : number {
220
220
return this . _dragging ?
221
- this . _positionCache . items . findIndex ( currentItem => currentItem . drag === item ) :
221
+ findIndex ( this . _positionCache . items , currentItem => currentItem . drag === item ) :
222
222
this . _draggables . toArray ( ) . indexOf ( item ) ;
223
223
}
224
224
@@ -244,7 +244,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
244
244
}
245
245
246
246
const isHorizontal = this . orientation === 'horizontal' ;
247
- const currentIndex = siblings . findIndex ( currentItem => currentItem . drag === item ) ;
247
+ const currentIndex = findIndex ( siblings , currentItem => currentItem . drag === item ) ;
248
248
const siblingAtNewPosition = siblings [ newIndex ] ;
249
249
const currentPosition = siblings [ currentIndex ] . clientRect ;
250
250
const newPosition = siblingAtNewPosition . clientRect ;
@@ -389,7 +389,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
389
389
390
390
const isHorizontal = this . orientation === 'horizontal' ;
391
391
392
- return this . _positionCache . items . findIndex ( ( { drag, clientRect} , _ , array ) => {
392
+ return findIndex ( this . _positionCache . items , ( { drag, clientRect} , _ , array ) => {
393
393
if ( drag === item ) {
394
394
// If there's only one item left in the container, it must be
395
395
// the dragged item itself so we use it as a reference.
@@ -428,3 +428,22 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
428
428
pointerX > left - xThreshold && pointerX < right + xThreshold ;
429
429
}
430
430
}
431
+
432
+
433
+ /**
434
+ * Finds the index of an item that matches a predicate function. Used as an equivalent
435
+ * of `Array.prototype.find` which isn't part of the standard Google typings.
436
+ * @param array Array in which to look for matches.
437
+ * @param predicate Function used to determine whether an item is a match.
438
+ */
439
+ function findIndex < T > ( array : T [ ] ,
440
+ predicate : ( value : T , index : number , obj : T [ ] ) => boolean ) : number {
441
+
442
+ for ( let i = 0 ; i < array . length ; i ++ ) {
443
+ if ( predicate ( array [ i ] , i , array ) ) {
444
+ return i ;
445
+ }
446
+ }
447
+
448
+ return - 1 ;
449
+ }
0 commit comments