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

passing true or false for an argument #26

Closed
bgentry opened this issue Jul 11, 2018 · 4 comments
Closed

passing true or false for an argument #26

bgentry opened this issue Jul 11, 2018 · 4 comments

Comments

@bgentry
Copy link

bgentry commented Jul 11, 2018

I noticed today that passing an argument as @fade=true actually results in a string value, i.e. "true" rather than the boolean true. I suppose this aligns with the RFC (emberjs/rfcs#311), though it doesn't explicitly mention bools:

If the argument value is a constant string, it can appear verbatim after the
equal sign, i.e. <FooBar @foo="some constant string" />. Other values should
be enclosed in curlies, i.e. <FooBar @foo={{123}} @bar={{this.bar}} />.
Helpers can also be used, as in <FooBar @foo={{capitalize this.bar}} />.

In order to pass a bool to my component, I need to do @fade={{true}}. I'm willing to be that a lot of people will be tripped up on this. I also couldn't find any record of it being discussed in the RFC PR.

Is it possible to allow users to directly pass true or false without curly brackets? Is that desirable?

Perhaps the RFC itself could be amended to clarify this point. While it's technically covered by "Other values", it's probably a common enough case to document explicitly either way. (cc @chancancode)

@rwjblue
Copy link
Member

rwjblue commented Jul 12, 2018

The current behavior is intentional, though I agree that it could seem a bit counter-intuitive. In the template context we are writing "html" which effectively only understands strings, if we want to pass anything else it must be inside curlies.

A very similar thing happens with normal HTML attributes (e.g. <div data-foo=something></div> ends up as data-foo="something").

@rwjblue
Copy link
Member

rwjblue commented Jul 12, 2018

I think the best solution here is:

  • add a linting rule to forbid quoteless strings (this would have made @foo=something a linting failure, pointing out to you that it should either be in curlies or quoted)
  • ensure that the learning team is aware of this issue, and incorporates some verbiage in the guides.emberjs.com revamp to use angle bracket invocation (once it lands in a stable release)

@rwjblue
Copy link
Member

rwjblue commented Jul 23, 2018

Created ember-template-lint/ember-template-lint#456 to track adding the new linting rule for this.

@rwjblue
Copy link
Member

rwjblue commented Apr 8, 2019

The linting rule was created and enabled over in ember-template-lint/ember-template-lint#461.

@rwjblue rwjblue closed this as completed Apr 8, 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

No branches or pull requests

2 participants