@@ -31,11 +31,10 @@ import {ENTER, UP_ARROW, DOWN_ARROW, ESCAPE} from '../core/keyboard/keycodes';
3131import { Directionality } from '../core/bidi/index' ;
3232import { MdInputContainer } from '../input/input-container' ;
3333import { Subscription } from 'rxjs/Subscription' ;
34- import 'rxjs/add/observable/merge' ;
35- import 'rxjs/add/observable/fromEvent' ;
36- import 'rxjs/add/operator/filter' ;
37- import 'rxjs/add/operator/switchMap' ;
38- import 'rxjs/add/observable/of' ;
34+ import { merge } from 'rxjs/observable/merge' ;
35+ import { fromEvent } from 'rxjs/observable/fromEvent' ;
36+ import { of as observableOf } from 'rxjs/observable/of' ;
37+ import { RxChain , switchMap , first , filter } from '../core/rxjs/index' ;
3938
4039/**
4140 * The following style constants are necessary to save here in order
@@ -187,7 +186,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
187186 * when an option is selected, on blur, and when TAB is pressed.
188187 */
189188 get panelClosingActions ( ) : Observable < MdOptionSelectionChange > {
190- return Observable . merge (
189+ return merge (
191190 this . optionSelections ,
192191 this . autocomplete . _keyManager . tabOut ,
193192 this . _outsideClickStream
@@ -196,7 +195,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
196195
197196 /** Stream of autocomplete option selections. */
198197 get optionSelections ( ) : Observable < MdOptionSelectionChange > {
199- return Observable . merge ( ...this . autocomplete . options . map ( option => option . onSelectionChange ) ) ;
198+ return merge ( ...this . autocomplete . options . map ( option => option . onSelectionChange ) ) ;
200199 }
201200
202201 /** The currently active option, coerced to MdOption type. */
@@ -210,20 +209,20 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
210209
211210 /** Stream of clicks outside of the autocomplete panel. */
212211 private get _outsideClickStream ( ) : Observable < any > {
213- if ( this . _document ) {
214- return Observable . fromEvent ( this . _document , 'click' ) . filter ( ( event : MouseEvent ) => {
215- const clickTarget = event . target as HTMLElement ;
216- const inputContainer = this . _inputContainer ?
217- this . _inputContainer . _elementRef . nativeElement : null ;
218-
219- return this . _panelOpen &&
220- clickTarget !== this . _element . nativeElement &&
221- ( ! inputContainer || ! inputContainer . contains ( clickTarget ) ) &&
222- ( ! ! this . _overlayRef && ! this . _overlayRef . overlayElement . contains ( clickTarget ) ) ;
223- } ) ;
212+ if ( ! this . _document ) {
213+ return observableOf ( null ) ;
224214 }
225215
226- return Observable . of ( null ) ;
216+ return filter . call ( fromEvent ( this . _document , 'click' ) , ( event : MouseEvent ) => {
217+ const clickTarget = event . target as HTMLElement ;
218+ const inputContainer = this . _inputContainer ?
219+ this . _inputContainer . _elementRef . nativeElement : null ;
220+
221+ return this . _panelOpen &&
222+ clickTarget !== this . _element . nativeElement &&
223+ ( ! inputContainer || ! inputContainer . contains ( clickTarget ) ) &&
224+ ( ! ! this . _overlayRef && ! this . _overlayRef . overlayElement . contains ( clickTarget ) ) ;
225+ } ) ;
227226 }
228227
229228 /**
@@ -332,17 +331,17 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
332331 */
333332 private _subscribeToClosingActions ( ) : void {
334333 // When the zone is stable initially, and when the option list changes...
335- Observable . merge ( this . _zone . onStable . first ( ) , this . autocomplete . options . changes )
336- // create a new stream of panelClosingActions, replacing any previous streams
337- // that were created, and flatten it so our stream only emits closing events...
338- . switchMap ( ( ) => {
339- this . _resetPanel ( ) ;
340- return this . panelClosingActions ;
341- } )
342- // when the first closing event occurs...
343- . first ( )
344- // set the value, close the panel, and complete.
345- . subscribe ( event => this . _setValueAndClose ( event ) ) ;
334+ RxChain . from ( merge ( first . call ( this . _zone . onStable ) , this . autocomplete . options . changes ) )
335+ // create a new stream of panelClosingActions, replacing any previous streams
336+ // that were created, and flatten it so our stream only emits closing events...
337+ . call ( switchMap , ( ) => {
338+ this . _resetPanel ( ) ;
339+ return this . panelClosingActions ;
340+ } )
341+ // when the first closing event occurs...
342+ . call ( first )
343+ // set the value, close the panel, and complete.
344+ . subscribe ( event => this . _setValueAndClose ( event ) ) ;
346345 }
347346
348347 /** Destroys the autocomplete suggestion panel. */
0 commit comments