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

Conditional logic: Bool ? 'str' : '' can be simplified to Bool && 'str' #1

Closed
kyleoliveiro opened this issue May 28, 2018 · 4 comments

Comments

@kyleoliveiro
Copy link

const message = 'hello friend';
const showMessage = true;

${showMessage
    ? html`The message is: ${message}`
    : ''}

// The above is the same as:

${showMessage && html`The message is ${message}`}
@motss
Copy link

motss commented May 29, 2018

@kyleoliveiro Is this a question? This does not work as expected. It will returned undefined if it evaluates to false.

@kyleoliveiro
Copy link
Author

@motss Whoops, was supposed to be a suggestion. But you're right. It returns false if showMessage evaluates to false.

@LarsDenBakker
Copy link
Owner

@kyleoliveiro You might be right, I think lit-html doesn't render undefined so yours might be a shorter syntax

@kyleoliveiro
Copy link
Author

I tested, but it renders out "false" if showMessage evals to false. Sorry for the confusion.

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

No branches or pull requests

3 participants