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

Hide prefixText when it's an empty string #124

Merged
merged 2 commits into from
Sep 22, 2019

Conversation

stroncium
Copy link
Contributor

@stroncium stroncium commented Sep 13, 2019

Fixes #122

@sindresorhus
Copy link
Owner

I think it would be better to fix the JS code to also accept an empty string, without adding the padding. I prefer to keep TS types as simple as possible.

@stroncium
Copy link
Contributor Author

@sindresorhus But we will have inconsistency then.

'  ' => '   spinner'
' '  => '  spinner'
''   => 'spinner'

and no way to put just one space in.

@stroncium
Copy link
Contributor Author

Also, as it can be undefined from beginning, it makes sense to me we should be able to assign undefined to it(I actually thought it was the case from the start, but weirdly enough, optional field can be undefined, but can't be assigned undefined).

@sindresorhus
Copy link
Owner

Good point. I missed your comment in the issue. Ignore my previous comment.

@sindresorhus
Copy link
Owner

Can you document in words that setting it to undefined will hide the prefix? In the readme too.

@sindresorhus
Copy link
Owner

sindresorhus commented Sep 14, 2019

Hmm, actually, thinking about this more, would anyone actually want an empty space before the spinner? Seems logical to me that the empty space is just a joiner, so when prefixText is empty, there's no space. prefixText is not meant to create indentation, we have the indent option for that.

@sindresorhus
Copy link
Owner

Hmm, actually, thinking about this more, would anyone actually want an empty space before the spinner? Seems logical to me that the empty space is just a joiner, so when prefixText is empty, there's no space. prefixText is not meant to create indentation, we have the indent option for that.

@stroncium ⬆️

@stroncium
Copy link
Contributor Author

stroncium commented Sep 16, 2019

@sindresorhus Feels weird to introduce additional code so that instead of just setting something to empty string and getting predictable result he'd set it to empty string, get unpredictable result and need to set up another option in order for result to get to what was predicted, no?

@ngocdaothanh
Copy link

One way to fix the mess is to force users (by redesigning the APIs?) to create a new instance of ora every time, instead of allowing users to reuse an existing ora instance (immutable vs mutable).

@stroncium
Copy link
Contributor Author

@sindresorhus I wait for your final word on this.
Allowing undefined vs special case for empty string.

Pros:

  • no additional code/logic
  • consistent results with any string supplied
  • setting undefined mirrors behavior for not defining

Cons:

  • setting empty string may be thought by some as equal to "removing" the value, in which case the behavior might seem weird to them

@sindresorhus
Copy link
Owner

@ngocdaothanh It's not a "mess". It's just a tiny API quirk. And I don't think immutability would solve any problems in this case (I'm saying that as someone that loves immutability in other languages).

@sindresorhus
Copy link
Owner

@stroncium I'm gonna go with "special case for empty string". Thinking about it more, it doesn't look like a special-case to me, but more like expected behavior. As long as we document it it, there should be no problems with this.

Can you also give the PR a descriptive title?

@stroncium stroncium changed the title Solves #122 Handle empty string prefixText as disabled Sep 21, 2019
@stroncium stroncium changed the title Handle empty string prefixText as disabled Handle empty string prefixText as disabled, solves #122 Sep 21, 2019
@stroncium
Copy link
Contributor Author

@sindresorhus changed to handle empty string

@sindresorhus sindresorhus changed the title Handle empty string prefixText as disabled, solves #122 Hide prefixText when it's an empty string Sep 22, 2019
@sindresorhus sindresorhus merged commit 8bcde17 into sindresorhus:master Sep 22, 2019
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.

Undesirable space before spinner symbol when prefixText is empty string
3 participants