Skip to content

chore(snack-bar): switch to OnPush change detection #5515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/snack-bar/simple-snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Component, ViewEncapsulation} from '@angular/core';
import {Component, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
import {MdSnackBarRef} from './snack-bar-ref';


Expand All @@ -20,6 +20,7 @@ import {MdSnackBarRef} from './snack-bar-ref';
templateUrl: 'simple-snack-bar.html',
styleUrls: ['simple-snack-bar.css'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'class': 'mat-simple-snackbar',
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/snack-bar/snack-bar-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
OnDestroy,
Renderer2,
ElementRef,
ChangeDetectionStrategy,
} from '@angular/core';
import {
trigger,
Expand Down Expand Up @@ -52,13 +53,15 @@ export const HIDE_ANIMATION = '195ms cubic-bezier(0.0,0.0,0.2,1)';
selector: 'snack-bar-container',
templateUrl: 'snack-bar-container.html',
styleUrls: ['snack-bar-container.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'role': 'alert',
'[@state]': 'animationState',
'(@state.done)': 'onAnimationEnd($event)'
},
animations: [
trigger('state', [
state('void', style({transform: 'translateY(100%)'})),
state('initial', style({transform: 'translateY(100%)'})),
state('visible', style({transform: 'translateY(0%)'})),
state('complete', style({transform: 'translateY(100%)'})),
Expand Down
6 changes: 0 additions & 6 deletions src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ export class MdSnackBar {
let containerPortal = new ComponentPortal(MdSnackBarContainer, config.viewContainerRef);
let containerRef: ComponentRef<MdSnackBarContainer> = overlayRef.attach(containerPortal);
containerRef.instance.snackBarConfig = config;

// The snackbar animation needs the content to be resolved in order to transform the bar
// out of the view initially (so it can slide in). To make the content resolve, we manually
// detect changes.
containerRef.changeDetectorRef.detectChanges();

return containerRef.instance;
}

Expand Down