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

Fix timer callback triggering after timer is cleared #865

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Bug fixes**

- `EuiButton`, `EuiButtonEmpty`, and `EuiButtonIcon` now look and behave disabled when `isDisabled={true}` ([#862](https://github.com/elastic/eui/pull/862))
- `EuiGlobalToastList` no longer triggers `Uncaught TypeError: _this.callback is not a function` ([#865](https://github.com/elastic/eui/pull/865))

## [`0.0.49`](https://github.com/elastic/eui/tree/v0.0.49)

Expand Down
5 changes: 4 additions & 1 deletion src/services/time/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Timer {

resume = () => {
this.id = setTimeout(this.finish, this.timeRemaining);
this.finishTime = Date.now() + this.timeRemaining;
this.timeRemaining = undefined;
};

Expand All @@ -26,7 +27,9 @@ export class Timer {
};

finish = () => {
this.callback();
if (this.callback) {
this.callback();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I'm just wondering: these methods all look like they could benefit from some awaits or promise handling. Wherever Timer is used, there might be a need to chain events making sure the previous function finished executing. I'm just a little surprised looking through this class, that it doesn't await this.callback(). I guess nothing that calls finish needs to be chained with something else?

this.clear();
};
}