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

Update component docs to use angle bracket syntax #292

Merged
merged 10 commits into from
Aug 22, 2021

Conversation

mcfiredrill
Copy link
Contributor

I tried use ember-angle-brackets-codemod, but it didn't seem to work on
.js files. So I edited the doc comments manually.

I tried use ember-angle-brackets-codemod, but it didn't seem to work on
.js files. So I edited the doc comments manually.
Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Thanks a lot for updating. Seems we missed it on the last PRs.

I think you need to rebase after #291 has been merged.

I fear we missed some work to fully support angle bracket invocation. I see two ways to address it:

  1. Do not pass HTML attributes but arguments on component invocation or
  2. fix missing attributes forwarding before merging this one.

onfileadd=(action "uploadImage")}}
<FileUpload name="photos"
accept="image/*"
multiple=true
Copy link
Collaborator

Choose a reason for hiding this comment

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

multiple=true is not valid HTML, is it? I think it should be <FileUpload multiple />.

multiple=true
onfileadd=(action "uploadImage")}}
<FileUpload name="photos"
accept="image/*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I fear we don't support passing HTML attributes to <FileUpload> yet. It doesn't seem to pass them to <input>. At least I don't see a ...attributes in the template.

Copy link
Collaborator

Choose a reason for hiding this comment

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

...attributes are applied to the parent element unless tagName is set to a empty string.

<FileUpload name="photos"
accept="image/*"
multiple=true
@onfileadd={{action "uploadImage"}}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The coding style looks different than what I would expect. I'm used to this one:

<FileUpload
  @onfileadd={{action "uploadImage"}}
  name="photos"
  accept="image/*"
/>

So it's basically about this rules:

  • If there are multiple lines, each attribute or property should be on a new line
  • It should be intended by two spaces.
  • Arguments should be before HTML attributes.

I thought that's also what's used in Ember docs but noticed that Ember docs aren't consistent on these ones.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I usually do html attributes first and then args, usually actions last

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I wonder if there is any ember-template-lint rule about this...

Copy link
Member

Choose a reason for hiding this comment

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

@mcfiredrill I am glad you asked 😄
ember-template-lint/ember-template-lint#871
I requested this a while ago :)
ember-template-lint/ember-template-lint#684

Although it isn't exactly what @knownasilya mentioned

@mcfiredrill
Copy link
Contributor Author

I fear we missed some work to fully support angle bracket invocation. I see two ways to address it:

Do not pass HTML attributes but arguments on component invocation or
fix missing attributes forwarding before merging this one.

Sounds good, I'm using this addon with angle brackets in my app now so I will make another PR with those fixes before getting this merged.

@gilest
Copy link
Collaborator

gilest commented Nov 22, 2019

See file-upload-test.js for the angle-bracket API that is currently covered by integration tests.

It's not an absolutely ideal API (no html attribute support) but it does allow us to support a wide range of ember versions.

@Alonski
Copy link
Member

Alonski commented Nov 23, 2019

@Turbo87 gave me a few tips on this:

I would prefix everything with @
if you don't then the fact that the ...attributes element is the <input type="file"> becomes public API and I'm not sure you'll want that in this case
I generally prefer a defined public API instead of the "pass everything to some child element"
...attributes should still be on the top-level element though so that CSS classes can be applied from the outside, to e.g. add margins on the component
Hmm so we should explicitly use @ and then inside the component use <input name={{@name}}> or something?
yeah, I think so

@mcfiredrill
Copy link
Contributor Author

@Alonski Very good points! I didn't think about the basically becoming public API.

It seems like I got really hung up on getting the component to work with normal HTML attributes without really thinking about the tradeoffs or alternatives.

#292 (review)

I fear we missed some work to fully support angle bracket invocation. I see two ways to address it:

1 . Do not pass HTML attributes but arguments on component invocation or
2. fix missing attributes forwarding before merging this one.

Maybe @jelhan 's initial suggestion 1 here was a better idea after all. 🤔

@mcfiredrill
Copy link
Contributor Author

@gilest Thank you, I didn't even realize that was in the tests! 😅

@jelhan
Copy link
Collaborator

jelhan commented Nov 24, 2019

@Alonski I'm not sure if I agree. Designing this component from scratch using an outer-html approach, would we really end up with this as best API?

<label ...attributes>
  <input>
</label>

I've the feeling that we would have done something like:

{{#if (has-block)}}
  {{yield
    (hash
      fileChanged=(action "change")
    )
  }}
{{else}}
  <label
    for={{inputId}}
  >
  <input
    id={{inputId}}
    type="file"
    onchange={{action "change"  value="target.files"}}
   ...attributes
  >
{{(/if}}

@Turbo87
Copy link

Turbo87 commented Nov 24, 2019

@jelhan if you implement it that way you would have no way of controlling the margins around the component from the outside without adding another unnecessary wrapper component. I would consider the fact that the component is using a native input element inside an implementation detail that should not be relied upon.

@mcfiredrill
Copy link
Contributor Author

mcfiredrill commented Nov 28, 2019

Hmm so we should explicitly use @ and then inside the component use <input name={{@name}}> or something?

Using @ for all arguments seems to be supported already according to this test:
https://github.com/adopted-ember-addons/ember-file-upload/blob/master/tests/integration/components/file-upload-test.js

So I think if I just change all the arguments in the docs to be @ prefixed, would this PR be merge-able?

<input name={{@name}}>

I think we could leave the templates as is without @ prefixing the arguments in the template. This will keep them backwards compability with {{}} curly components, if I understand correctly?

I renamed my related PR to "Support html attributes in angle bracket components", since angle bracket components technically already work.

@mcfiredrill
Copy link
Contributor Author

So I think if I just change all the arguments in the docs to be @ prefixed, would this PR be merge-able?

Done in aa98e71

Hmm build is failing...I haven't changed any code in this PR however. Someone want to try running it again for me? 🛠

@mcfiredrill
Copy link
Contributor Author

bump...anyone know why my build failed? :)

@Alonski
Copy link
Member

Alonski commented Dec 21, 2019

@mcfiredrill Restarted. Ping me on Discord if it fails again please 🙂

@gilest
Copy link
Collaborator

gilest commented Jun 12, 2021

@mcfiredrill 👋 Hello from the future. Care to rebase this so the CI can run again?

@mcfiredrill
Copy link
Contributor Author

Hi there, it's been awhile! I just merged master into this branch.

@gilest gilest self-requested a review June 15, 2021 04:35
Copy link
Collaborator

@gilest gilest left a comment

Choose a reason for hiding this comment

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

LGTM.

@jelhan Your requested changes had been addressed – yes?

Copy link
Collaborator

@gilest gilest left a comment

Choose a reason for hiding this comment

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

Since (#476) onfileadd has been deprecated in favour of onFileAdd.

Also found a > was missing.

Also suggest we:

  • Drop action helper from examples
  • Use fn helper to pass arguments to callbacks

Please rebase 😅

@gilest gilest changed the title update docs to use angle bracket syntax Update component docs to use angle bracket syntax Jun 22, 2021
@mcfiredrill
Copy link
Contributor Author

Sorry for the delay, I have merged master.

Also suggest we:

Drop action helper from examples
Use fn helper to pass arguments to callbacks

I could try to address these here, or that could be another PR?

@gilest
Copy link
Collaborator

gilest commented Jul 11, 2021

Drop action helper from examples
Use fn helper to pass arguments to callbacks

I could try to address these here, or that could be another PR?

Looks like you addressed these in 71d3298

Copy link
Collaborator

@gilest gilest left a comment

Choose a reason for hiding this comment

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

LGTM. Believe this syntax is correct for the current version.

@gilest
Copy link
Collaborator

gilest commented Jul 11, 2021

@jelhan I think this can be merged now. Let me know if you still need changes

@gilest gilest merged commit 1c1f146 into adopted-ember-addons:master Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants