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