-
-
Notifications
You must be signed in to change notification settings - Fork 278
prevent start if already started - fixes #5 #6
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
Conversation
@@ -65,7 +65,7 @@ Ora.prototype.render = function () { | |||
}; | |||
|
|||
Ora.prototype.start = function () { | |||
if (!this.enabled) { | |||
if (!this.enabled || this.id) { |
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.
if (!(this.enabled && this.id)) {
Would be clearer.
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.
Those are not identical. The first time, enabled is false
and id is undefined
which will result in false
and because of the !
will result in true
and the spinner won't start. Did you mean
if (this.enabled && this.id) {
If the spinner is enabled AND we have an id, do nothing.
// @dylang |
Nice work @SamVerschueren, I was thinking the same idea for a fix for this. Do you think it would helpful to add a test for this that would fail without this fix? I'm not sure the best way to test, here's one idea: // psudocode-ish
spinner.start();
const idAfterFirstStart = spinner.id;
spinner.start();
const idAfterSecondStart = spinner.id;
if (idAfterFirstStart !== idAfterSecondStart) {
throw new Error('spinner was restarted instead of continuing from previous start.');
} |
@dylang would be helpfull indeed. Will add it to the PR. |
Added tests |
spinner.start(); | ||
const id = spinner.id; | ||
spinner.start(); | ||
t.same(id, spinner.id); |
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.
t.is()
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.
Good catch :)!
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.
Relevant: avajs/ava#686
Thanks Sam :) |
You're welcome! |
This small change fixes #5. At least, I think it does :). As long as the interval is running (and thus the spinner is spinning), multiple calls to
start
won't do a thing.