@@ -24,9 +24,8 @@ import {
24
24
Observable ,
25
25
Subject ,
26
26
Subscription ,
27
- throwError ,
28
27
} from 'rxjs' ;
29
- import { debounceTime , filter , map , switchMap , take , tap } from 'rxjs/operators' ;
28
+ import { debounceTime , filter , map , take , tap } from 'rxjs/operators' ;
30
29
31
30
const DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL_MS = 200 ;
32
31
@@ -322,44 +321,36 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
322
321
private _setTypeAhead ( debounceInterval : number ) {
323
322
this . _typeaheadSubscription . unsubscribe ( ) ;
324
323
324
+ if (
325
+ ( typeof ngDevMode === 'undefined' || ngDevMode ) &&
326
+ this . _items . length &&
327
+ this . _items . some ( item => typeof item . getLabel !== 'function' )
328
+ ) {
329
+ throw new Error (
330
+ 'TreeKeyManager items in typeahead mode must implement the `getLabel` method.' ,
331
+ ) ;
332
+ }
333
+
325
334
// Debounce the presses of non-navigational keys, collect the ones that correspond to letters
326
335
// and convert those letters back into a string. Afterwards find the first item that starts
327
336
// with that string and select it.
328
- this . _typeaheadSubscription = this . _getItems ( )
337
+ this . _typeaheadSubscription = this . _letterKeyStream
329
338
. pipe (
330
- switchMap ( items => {
331
- if (
332
- ( typeof ngDevMode === 'undefined' || ngDevMode ) &&
333
- items . length &&
334
- items . some ( item => typeof item . getLabel !== 'function' )
335
- ) {
336
- return throwError (
337
- new Error (
338
- 'TreeKeyManager items in typeahead mode must implement the `getLabel` method.' ,
339
- ) ,
340
- ) ;
341
- }
342
- return observableOf ( items ) as Observable < Array < T & { getLabel ( ) : string } > > ;
343
- } ) ,
344
- switchMap ( items => {
345
- return this . _letterKeyStream . pipe (
346
- tap ( letter => this . _pressedLetters . push ( letter ) ) ,
347
- debounceTime ( debounceInterval ) ,
348
- filter ( ( ) => this . _pressedLetters . length > 0 ) ,
349
- map ( ( ) => [ this . _pressedLetters . join ( '' ) , items ] as const ) ,
350
- ) ;
351
- } ) ,
339
+ tap ( letter => this . _pressedLetters . push ( letter ) ) ,
340
+ debounceTime ( debounceInterval ) ,
341
+ filter ( ( ) => this . _pressedLetters . length > 0 ) ,
342
+ map ( ( ) => this . _pressedLetters . join ( '' ) ) ,
352
343
)
353
- . subscribe ( ( [ inputString , items ] ) => {
344
+ . subscribe ( inputString => {
354
345
// Start at 1 because we want to start searching at the item immediately
355
346
// following the current active item.
356
- for ( let i = 1 ; i < items . length + 1 ; i ++ ) {
357
- const index = ( this . _activeItemIndex + i ) % items . length ;
358
- const item = items [ index ] ;
347
+ for ( let i = 1 ; i < this . _items . length + 1 ; i ++ ) {
348
+ const index = ( this . _activeItemIndex + i ) % this . _items . length ;
349
+ const item = this . _items [ index ] ;
359
350
360
351
if (
361
352
! this . _skipPredicateFn ( item ) &&
362
- item . getLabel ( ) . toUpperCase ( ) . trim ( ) . indexOf ( inputString ) === 0
353
+ item . getLabel ?. ( ) . toUpperCase ( ) . trim ( ) . indexOf ( inputString ) === 0
363
354
) {
364
355
this . _setActiveItem ( index ) ;
365
356
break ;
0 commit comments