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

[docs] Update text.md #7533

Closed
wants to merge 1 commit into from
Closed

[docs] Update text.md #7533

wants to merge 1 commit into from

Conversation

lrgalego
Copy link

Remove inaccurate description.

Not sure if this was a limitation on a previous version. but calling this without a callback function just worked in the tutorial page

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

Remove inaccurate description.

Not sure if this was a limitation on a previous version. but calling this without a callback function just worked in the tutorial page
@jhubbardsf
Copy link

jhubbardsf commented May 15, 2022

I believe the arrow syntax is only required if the function takes a parameter that has to be specified (not the event). So if you had

<script>
let count = 0;

const add = (x) => {
    count += x;
}
</script>

<button on:click={add(1)}>
add one
</button>

The above would cause an unintended issue. The add function would be called on page load and count would equal 1 before the user ever clicked on button. This could be confusing for some. Changing button to

<button on:click={() => add(1)}>

would fix the issue and count will be 0 until the user clicks the button. So in the example you modified, you're right, it isn't necessarily needed. But it doesn't hurt anything either. There are cases where the arrow syntax is necessary.

Edit: I didn't notice that function focus() was a classic function. So in fact by changing () => field.focus() to field.focus it does have one subtle difference. You're implicitly passing the event to the focus function in the second case. You can check that by checking console.log(arguments) in the function. Where as () => field.focus() explicitly doesn't pass anything. Again, doesn't actually hurt anything or change anything, but small difference. And we implicitly pass event all the time. I'd agree with you it's not necessary to use the arrows syntax here.

@Conduitry
Copy link
Member

There's been another PR a while ago that made this same change and that we didn't merge, but I don't fully remember what the reasoning was then.

@bluwy
Copy link
Member

bluwy commented May 16, 2022

Yeah it's a duplicate of #6852 with explanation there. Closing as this as so.

@bluwy bluwy closed this May 16, 2022
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.

4 participants