@@ -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,23 +209,23 @@ 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 . merge (
215- Observable . fromEvent ( this . _document , 'click' ) ,
216- Observable . fromEvent ( this . _document , 'touchend' )
217- ) . filter ( ( event : MouseEvent | TouchEvent ) => {
218- const clickTarget = event . target as HTMLElement ;
219- const inputContainer = this . _inputContainer ?
220- this . _inputContainer . _elementRef . nativeElement : null ;
221-
222- return this . _panelOpen &&
223- clickTarget !== this . _element . nativeElement &&
224- ( ! inputContainer || ! inputContainer . contains ( clickTarget ) ) &&
225- ( ! ! this . _overlayRef && ! this . _overlayRef . overlayElement . contains ( clickTarget ) ) ;
226- } ) ;
212+ if ( ! this . _document ) {
213+ return observableOf ( null ) ;
227214 }
228215
229- return Observable . of ( null ) ;
216+ return RxChain . from ( merge (
217+ fromEvent ( this . _document , 'click' ) ,
218+ fromEvent ( this . _document , 'touchend' )
219+ ) ) . call ( filter , ( event : MouseEvent | TouchEvent ) => {
220+ const clickTarget = event . target as HTMLElement ;
221+ const inputContainer = this . _inputContainer ?
222+ this . _inputContainer . _elementRef . nativeElement : null ;
223+
224+ return this . _panelOpen &&
225+ clickTarget !== this . _element . nativeElement &&
226+ ( ! inputContainer || ! inputContainer . contains ( clickTarget ) ) &&
227+ ( ! ! this . _overlayRef && ! this . _overlayRef . overlayElement . contains ( clickTarget ) ) ;
228+ } ) . result ( ) ;
230229 }
231230
232231 /**
@@ -335,17 +334,17 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
335334 */
336335 private _subscribeToClosingActions ( ) : void {
337336 // When the zone is stable initially, and when the option list changes...
338- Observable . merge ( this . _zone . onStable . first ( ) , this . autocomplete . options . changes )
339- // create a new stream of panelClosingActions, replacing any previous streams
340- // that were created, and flatten it so our stream only emits closing events...
341- . switchMap ( ( ) => {
342- this . _resetPanel ( ) ;
343- return this . panelClosingActions ;
344- } )
345- // when the first closing event occurs...
346- . first ( )
347- // set the value, close the panel, and complete.
348- . subscribe ( event => this . _setValueAndClose ( event ) ) ;
337+ RxChain . from ( merge ( first . call ( this . _zone . onStable ) , this . autocomplete . options . changes ) )
338+ // create a new stream of panelClosingActions, replacing any previous streams
339+ // that were created, and flatten it so our stream only emits closing events...
340+ . call ( switchMap , ( ) => {
341+ this . _resetPanel ( ) ;
342+ return this . panelClosingActions ;
343+ } )
344+ // when the first closing event occurs...
345+ . call ( first )
346+ // set the value, close the panel, and complete.
347+ . subscribe ( event => this . _setValueAndClose ( event ) ) ;
349348 }
350349
351350 /** Destroys the autocomplete suggestion panel. */
0 commit comments