Skip to content
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

perf(ripple): avoid triggering change detection #3066

Merged
merged 2 commits into from
Feb 17, 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
12 changes: 6 additions & 6 deletions src/lib/core/ripple/ripple-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ export class RippleRenderer {

if (element) {
// If the element is not null, register all event listeners on the trigger element.
this._triggerEvents.forEach((fn, type) => element.addEventListener(type, fn));
this._ngZone.runOutsideAngular(() => {
this._triggerEvents.forEach((fn, type) => element.addEventListener(type, fn));
});
}

this._triggerElement = element;
}

/** Listener being called on mousedown event. */
private onMousedown(event: MouseEvent) {
if (this.rippleDisabled) {
return;
if (!this.rippleDisabled) {
this._isMousedown = true;
this.fadeInRipple(event.pageX, event.pageY, this.rippleConfig);
}

this._isMousedown = true;
this.fadeInRipple(event.pageX, event.pageY, this.rippleConfig);
}

/** Listener being called on mouseup event. */
Expand Down
17 changes: 14 additions & 3 deletions src/lib/core/ripple/ripple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ describe('MdRipple', () => {
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
});

it('does not run events inside the NgZone', () => {
const spy = jasmine.createSpy('zone unstable callback');
const subscription = fixture.ngZone.onUnstable.subscribe(spy);

dispatchMouseEvent('mousedown');
dispatchMouseEvent('mouseup');

expect(spy).not.toHaveBeenCalled();
subscription.unsubscribe();
});

describe('when page is scrolled', () => {
const startingWindowWidth = window.innerWidth;
const startingWindowHeight = window.innerHeight;
Expand Down Expand Up @@ -374,7 +385,7 @@ describe('MdRipple', () => {

@Component({
template: `
<div id="container" mat-ripple [mdRippleSpeedFactor]="0"
<div id="container" mat-ripple [mdRippleSpeedFactor]="0"
style="position: relative; width:300px; height:200px;">
</div>
`,
Expand All @@ -387,7 +398,7 @@ class BasicRippleContainer {
template: `
<div id="container" style="position: relative; width:300px; height:200px;"
mat-ripple
[mdRippleSpeedFactor]="0"
[mdRippleSpeedFactor]="0"
[mdRippleTrigger]="trigger"
[mdRippleCentered]="centered"
[mdRippleRadius]="radius"
Expand All @@ -406,7 +417,7 @@ class RippleContainerWithInputBindings {
@ViewChild(MdRipple) ripple: MdRipple;
}

@Component({ template: `<div id="container" mat-ripple [mdRippleSpeedFactor]="0"
@Component({ template: `<div id="container" mat-ripple [mdRippleSpeedFactor]="0"
*ngIf="!isDestroyed"></div>` })
class RippleContainerWithNgIf {
@ViewChild(MdRipple) ripple: MdRipple;
Expand Down