Skip to content

Commit 8fe836b

Browse files
committed
nit
1 parent ed8e07b commit 8fe836b

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/lib/list/selection-list.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,22 @@
99
import {
1010
AfterContentInit,
1111
Component,
12-
ContentChild,
1312
ContentChildren,
14-
Directive,
1513
ElementRef,
1614
Input,
1715
Optional,
18-
QueryList,
19-
Renderer2,
2016
ViewEncapsulation,
2117
ChangeDetectionStrategy,
2218
OnDestroy,
23-
EventEmitter,
24-
Output,
25-
ChangeDetectorRef
19+
EventEmitter
2620
} from '@angular/core';
27-
import {coerceBooleanProperty, MdLine, MdLineSetter, SelectionModel} from '../core';
21+
import {coerceBooleanProperty, SelectionModel} from '../core';
2822
import {FocusKeyManager} from '../core/a11y/focus-key-manager';
2923
import {Subscription} from 'rxjs/Subscription';
3024
import {SPACE} from '../core/keyboard/keycodes';
3125
import {Focusable} from '../core/a11y/focus-key-manager';
3226
import {MdListOption} from './list-option';
3327
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';
34-
import {RxChain, switchMap, first, filter} from '../core/rxjs/index';
3528
import 'rxjs/add/observable/merge';
3629
import 'rxjs/add/observable/fromEvent';
3730
import 'rxjs/add/operator/filter';
@@ -71,11 +64,11 @@ export class MdSelectionList extends _MdSelectionListMixinBase
7164
/** Subscription to tabbing out from the selection-list. */
7265
private _tabOutSubscription: Subscription;
7366

74-
/** Subscription to option changes from the selection-list. */
75-
private _optionsChangeSubscription: Subscription;
76-
67+
/** Subscription to all list options' onFocus events */
7768
private _optionsChangeSubscriptionOnFocus: Subscription;
78-
private _optionsChangeSubscriptionDestory: Subscription;
69+
70+
/** Subscription to all list options' destroy events */
71+
private _optionsChangeSubscriptionDestroy: Subscription;
7972

8073
/** The FocusKeyManager which handles focus. */
8174
_keyManager: FocusKeyManager;
@@ -106,25 +99,32 @@ export class MdSelectionList extends _MdSelectionListMixinBase
10699
}
107100

108101
this._optionsChangeSubscriptionOnFocus = this.onFocusSubscription();
109-
this._optionsChangeSubscriptionDestory = this.onDestorySubscription();
102+
this._optionsChangeSubscriptionDestroy = this.onDestorySubscription();
110103
}
111104

112105
ngOnDestroy(): void {
113106
if (this._tabOutSubscription) {
114107
this._tabOutSubscription.unsubscribe();
115108
}
116109

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();
119116
}
120117
}
121118

122119
focus() {
123120
this._element.nativeElement.focus();
124121
}
125122

123+
/**
124+
* Map all the options' destroy event subscriptions and merge them into one stream.
125+
*/
126126
onDestorySubscription(): Subscription {
127-
return this.options.changes.startWith(this.options).switchMap((options) => {
127+
let subscription = this.options.changes.startWith(this.options).switchMap((options) => {
128128
return Observable.merge(...options.map(option => option.destroy));
129129
}).subscribe(e => {
130130
let optionIndex: number = this.options.toArray().indexOf(e.option);
@@ -138,15 +138,20 @@ export class MdSelectionList extends _MdSelectionListMixinBase
138138
}
139139
e.option.destroy.unsubscribe();
140140
});
141+
return subscription;
141142
}
142143

144+
/**
145+
* Map all the options' onFocus event subscriptions and merge them into one stream.
146+
*/
143147
onFocusSubscription(): Subscription {
144-
return this.options.changes.startWith(this.options).switchMap((options) => {
148+
let subscription = this.options.changes.startWith(this.options).switchMap((options) => {
145149
return Observable.merge(...options.map(option => option.onFocus));
146150
}).subscribe(e => {
147151
let optionIndex: number = this.options.toArray().indexOf(e.option);
148152
this._keyManager.updateActiveItemIndex(optionIndex);
149153
});
154+
return subscription;
150155
}
151156

152157
/** Passes relevant key presses to our key manager. */

0 commit comments

Comments
 (0)