@@ -28,8 +28,9 @@ import {animate, state, style, transition, trigger, AnimationEvent} from '@angul
28
28
import { Directionality , coerceBooleanProperty } from '../core' ;
29
29
import { FocusTrapFactory , FocusTrap } from '../core/a11y/focus-trap' ;
30
30
import { ESCAPE } from '../core/keyboard/keycodes' ;
31
- import { first } from '../core/rxjs/index' ;
31
+ import { first , takeUntil , startWith } from '../core/rxjs/index' ;
32
32
import { DOCUMENT } from '@angular/platform-browser' ;
33
+ import { merge } from 'rxjs/observable/merge' ;
33
34
34
35
35
36
/** Throws an exception when two MdSidenav are matching the same side. */
@@ -336,13 +337,13 @@ export class MdSidenavContainer implements AfterContentInit {
336
337
}
337
338
338
339
ngAfterContentInit ( ) {
339
- // On changes, assert on consistency.
340
- this . _sidenavs . changes . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
341
- this . _sidenavs . forEach ( ( sidenav : MdSidenav ) => {
342
- this . _watchSidenavToggle ( sidenav ) ;
343
- this . _watchSidenavAlign ( sidenav ) ;
340
+ startWith . call ( this . _sidenavs . changes , null ) . subscribe ( ( ) => {
341
+ this . _validateDrawers ( ) ;
342
+ this . _sidenavs . forEach ( ( sidenav : MdSidenav ) => {
343
+ this . _watchSidenavToggle ( sidenav ) ;
344
+ this . _watchSidenavAlign ( sidenav ) ;
345
+ } ) ;
344
346
} ) ;
345
- this . _validateDrawers ( ) ;
346
347
}
347
348
348
349
/** Calls `open` of both start and end sidenavs */
@@ -361,16 +362,17 @@ export class MdSidenavContainer implements AfterContentInit {
361
362
* is properly hidden.
362
363
*/
363
364
private _watchSidenavToggle ( sidenav : MdSidenav ) : void {
364
- sidenav . _animationStarted . subscribe ( ( ) => {
365
- // Set the transition class on the container so that the animations occur. This should not
366
- // be set initially because animations should only be triggered via a change in state.
367
- this . _renderer . addClass ( this . _element . nativeElement , 'mat-sidenav-transition' ) ;
368
- this . _changeDetectorRef . markForCheck ( ) ;
369
- } ) ;
365
+ takeUntil . call ( sidenav . _animationStarted , this . _sidenavs . changes )
366
+ . subscribe ( ( ) => {
367
+ // Set the transition class on the container so that the animations occur. This should not
368
+ // be set initially because animations should only be triggered via a change in state.
369
+ this . _renderer . addClass ( this . _element . nativeElement , 'mat-sidenav-transition' ) ;
370
+ this . _changeDetectorRef . markForCheck ( ) ;
371
+ } ) ;
370
372
371
373
if ( sidenav . mode !== 'side' ) {
372
- sidenav . onOpen . subscribe ( ( ) => this . _setContainerClass ( true ) ) ;
373
- sidenav . onClose . subscribe ( ( ) => this . _setContainerClass ( false ) ) ;
374
+ takeUntil . call ( merge ( sidenav . onOpen , sidenav . onClose ) , this . _sidenavs . changes ) . subscribe ( ( ) =>
375
+ this . _setContainerClass ( sidenav . opened ) ) ;
374
376
}
375
377
}
376
378
@@ -384,7 +386,7 @@ export class MdSidenavContainer implements AfterContentInit {
384
386
}
385
387
// NOTE: We need to wait for the microtask queue to be empty before validating,
386
388
// since both drawers may be swapping sides at the same time.
387
- sidenav . onAlignChanged . subscribe ( ( ) =>
389
+ takeUntil . call ( sidenav . onAlignChanged , this . _sidenavs . changes ) . subscribe ( ( ) =>
388
390
first . call ( this . _ngZone . onMicrotaskEmpty ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ) ;
389
391
}
390
392
0 commit comments