-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Clear duration timeout after dismiss #4860
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
@jelbourn from my point of view this is ready to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs a unit test that verifies the problem it aims to resolve no longer occurs.
src/lib/snack-bar/snack-bar-ref.ts
Outdated
@@ -31,6 +31,9 @@ export class MdSnackBarRef<T> { | |||
/** Subject for notifying the user that the snack bar action was called. */ | |||
private _onAction: Subject<any> = new Subject(); | |||
|
|||
/** Timeout handle for the dismiss timeout cleanup. */ | |||
private _dismissTimeoutHandle: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this durationTimeoutId
with comment:
/**
* Timeout ID for the duration setTimeout call. Used to clear the timeout if the snackbar is
* dismissed before the duration passes.
*/
private _durationTimeoutId: number;
src/lib/snack-bar/snack-bar-ref.ts
Outdated
} | ||
|
||
/** Dismisses the snack bar after some duration */ | ||
dismissAfter(duration: number): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an private method. If it were a public API and someone called it in combination with setting a duration, the earlier timeout ID would be lost and the issue this PR aims to resolve would still occur.
85caa54
to
575a6ef
Compare
Hi @jelbourn, Thanks for reveiw. I did the requested changes, but the tests seem to fail, since Do you have any idea how to fix this or test the behavior differently? |
@svi3c it('should clear the dismiss timeout when dismissed before timeout expiration', fakeAsync(() => {
let config = new MdSnackBarConfig();
config.duration = 1000;
snackBar.open('content', 'test', config);
setTimeout(() => snackBar.dismiss(), 500);
tick(600);
viewContainerFixture.detectChanges();
flushMicrotasks();
expect(viewContainerFixture.isStable()).toBe(true);
})); |
Hi @jelbourn, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
When a duration is passed to MdSnackBar.prototype.openFromComponent(), a timeout is created. This timeout is now cleared when dismissing the snackbar. Fixes angular#4859
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes #4859