Skip to content

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

Closed
wants to merge 2 commits into from
Closed

prevent start if already started - fixes #5 #6

wants to merge 2 commits into from

Conversation

SamVerschueren
Copy link
Contributor

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.

@@ -65,7 +65,7 @@ Ora.prototype.render = function () {
};

Ora.prototype.start = function () {
if (!this.enabled) {
if (!this.enabled || this.id) {
Copy link
Owner

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.

Copy link
Contributor Author

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.

@sindresorhus
Copy link
Owner

// @dylang

@dylang
Copy link

dylang commented Mar 27, 2016

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.');
}

@SamVerschueren
Copy link
Contributor Author

@dylang would be helpfull indeed. Will add it to the PR.

@SamVerschueren
Copy link
Contributor Author

Added tests

spinner.start();
const id = spinner.id;
spinner.start();
t.same(id, spinner.id);
Copy link
Owner

Choose a reason for hiding this comment

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

t.is()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch :)!

Copy link
Owner

Choose a reason for hiding this comment

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

Relevant: avajs/ava#686

@sindresorhus
Copy link
Owner

Thanks Sam :)

@SamVerschueren
Copy link
Contributor Author

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

on .start, don't start again if already running
3 participants