9
9
import {
10
10
AfterContentInit ,
11
11
Component ,
12
- ContentChild ,
13
12
ContentChildren ,
14
- Directive ,
15
13
ElementRef ,
16
14
Input ,
17
15
Optional ,
18
- QueryList ,
19
- Renderer2 ,
20
16
ViewEncapsulation ,
21
17
ChangeDetectionStrategy ,
22
18
OnDestroy ,
23
- EventEmitter ,
24
- Output ,
25
- ChangeDetectorRef
19
+ EventEmitter
26
20
} from '@angular/core' ;
27
- import { coerceBooleanProperty , MdLine , MdLineSetter , SelectionModel } from '../core' ;
21
+ import { coerceBooleanProperty , SelectionModel } from '../core' ;
28
22
import { FocusKeyManager } from '../core/a11y/focus-key-manager' ;
29
23
import { Subscription } from 'rxjs/Subscription' ;
30
24
import { SPACE } from '../core/keyboard/keycodes' ;
31
25
import { Focusable } from '../core/a11y/focus-key-manager' ;
32
26
import { MdListOption } from './list-option' ;
33
27
import { CanDisable , mixinDisabled } from '../core/common-behaviors/disabled' ;
34
- import { RxChain , switchMap , first , filter } from '../core/rxjs/index' ;
35
28
import 'rxjs/add/observable/merge' ;
36
29
import 'rxjs/add/observable/fromEvent' ;
37
30
import 'rxjs/add/operator/filter' ;
@@ -71,11 +64,11 @@ export class MdSelectionList extends _MdSelectionListMixinBase
71
64
/** Subscription to tabbing out from the selection-list. */
72
65
private _tabOutSubscription : Subscription ;
73
66
74
- /** Subscription to option changes from the selection-list. */
75
- private _optionsChangeSubscription : Subscription ;
76
-
67
+ /** Subscription to all list options' onFocus events */
77
68
private _optionsChangeSubscriptionOnFocus : Subscription ;
78
- private _optionsChangeSubscriptionDestory : Subscription ;
69
+
70
+ /** Subscription to all list options' destroy events */
71
+ private _optionsChangeSubscriptionDestroy : Subscription ;
79
72
80
73
/** The FocusKeyManager which handles focus. */
81
74
_keyManager : FocusKeyManager ;
@@ -106,25 +99,32 @@ export class MdSelectionList extends _MdSelectionListMixinBase
106
99
}
107
100
108
101
this . _optionsChangeSubscriptionOnFocus = this . onFocusSubscription ( ) ;
109
- this . _optionsChangeSubscriptionDestory = this . onDestorySubscription ( ) ;
102
+ this . _optionsChangeSubscriptionDestroy = this . onDestorySubscription ( ) ;
110
103
}
111
104
112
105
ngOnDestroy ( ) : void {
113
106
if ( this . _tabOutSubscription ) {
114
107
this . _tabOutSubscription . unsubscribe ( ) ;
115
108
}
116
109
117
- if ( this . _optionsChangeSubscription ) {
118
- this . _optionsChangeSubscription . unsubscribe ( ) ;
110
+ if ( this . _optionsChangeSubscriptionDestroy ) {
111
+ this . _optionsChangeSubscriptionDestroy . unsubscribe ( ) ;
112
+ }
113
+
114
+ if ( this . _optionsChangeSubscriptionOnFocus ) {
115
+ this . _optionsChangeSubscriptionOnFocus . unsubscribe ( ) ;
119
116
}
120
117
}
121
118
122
119
focus ( ) {
123
120
this . _element . nativeElement . focus ( ) ;
124
121
}
125
122
123
+ /**
124
+ * Map all the options' destroy event subscriptions and merge them into one stream.
125
+ */
126
126
onDestorySubscription ( ) : Subscription {
127
- return this . options . changes . startWith ( this . options ) . switchMap ( ( options ) => {
127
+ let subscription = this . options . changes . startWith ( this . options ) . switchMap ( ( options ) => {
128
128
return Observable . merge ( ...options . map ( option => option . destroy ) ) ;
129
129
} ) . subscribe ( e => {
130
130
let optionIndex : number = this . options . toArray ( ) . indexOf ( e . option ) ;
@@ -138,15 +138,20 @@ export class MdSelectionList extends _MdSelectionListMixinBase
138
138
}
139
139
e . option . destroy . unsubscribe ( ) ;
140
140
} ) ;
141
+ return subscription ;
141
142
}
142
143
144
+ /**
145
+ * Map all the options' onFocus event subscriptions and merge them into one stream.
146
+ */
143
147
onFocusSubscription ( ) : Subscription {
144
- return this . options . changes . startWith ( this . options ) . switchMap ( ( options ) => {
148
+ let subscription = this . options . changes . startWith ( this . options ) . switchMap ( ( options ) => {
145
149
return Observable . merge ( ...options . map ( option => option . onFocus ) ) ;
146
150
} ) . subscribe ( e => {
147
151
let optionIndex : number = this . options . toArray ( ) . indexOf ( e . option ) ;
148
152
this . _keyManager . updateActiveItemIndex ( optionIndex ) ;
149
153
} ) ;
154
+ return subscription ;
150
155
}
151
156
152
157
/** Passes relevant key presses to our key manager. */
0 commit comments