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 wording to include prop behaviour #4460

Merged
merged 86 commits into from
Feb 28, 2020

Conversation

jesseskinner
Copy link
Contributor

In regards to #4442, this adds wording to explain that props are set to undefined when they are removed by the consumer.

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

  • It's really useful if your PR relates to an outstanding issue, so please reference it in your PR, or create an explanatory one for discussion. In many cases features are absent for a reason.
  • This message body should clearly illustrate what problems it solves. If there are related issues, remember to reference them.
  • Ideally, include a test that fails without this PR but passes with it. PRs will only be merged once they pass CI. (Remember to npm run lint!)

Tests

  • Run the tests tests with npm test or yarn test)

In regards to sveltejs#4442, this adds wording to explain that props are set to undefined when they are removed by the consumer.
Copy link
Member

@mindrones mindrones left a comment

Choose a reason for hiding this comment

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

Apart from the suggested change, it would be good to merge to me.

@jesseskinner
Copy link
Contributor Author

@mindrones Not sure about "instancing" as a verb. What about: "It will be used if the component's consumer doesn't specify the prop when the component is instantiated." ?

@jesseskinner
Copy link
Contributor Author

Alternatively, "It will be used if the component's consumer doesn't specify the prop when instantiating the component." ?

@mindrones
Copy link
Member

mindrones commented Feb 27, 2020

Sorry wrote in a hurry (also not native :), they're both OK to me, thanks!

@mindrones
Copy link
Member

Re: #4442 (comment)

I'm not sure if we want to add that kind of suggestion in the reference. I tend to agree, but I'd prefer using something like:

export let prop;

$: prop = prop || 'default';

@jesseskinner
Copy link
Contributor Author

@mindrones Won't that cause a warning in development though?

@mindrones
Copy link
Member

mindrones commented Feb 27, 2020

It would, but I'm not sure I'd want to see the form you suggested in the docs, although correct it's pretty long. Since this is a personal opinion I'd like to hear from others too :)

@jesseskinner
Copy link
Contributor Author

@mindrones Agreed, this whole section is getting pretty long as it is :)

Hm I rebased master in my branch and now all those extra commits are here. Not sure what I need to do to fix it if anything.

@mindrones
Copy link
Member

mindrones commented Feb 27, 2020

Hm, not sure.. I'd try something like this:

  • copy the current changes in that branch somewhere locally,
  • locally, delete patch-1
  • checkout master, pull
  • checkout a new branch patch-1 from master
  • apply the change in this branch and commit
  • git push --force

@Conduitry
Copy link
Member

Don't worry about all the extra commits - this will be squashed anyway when it is merged.

I think this clarification sounds reasonable, thanks!

@Conduitry Conduitry merged commit 20e0790 into sveltejs:master Feb 28, 2020
sthagen added a commit to sthagen/sveltejs-svelte that referenced this pull request Feb 28, 2020
docs: clarify default prop behaviour (sveltejs#4460)
@tanhauhau
Copy link
Member

tanhauhau commented Mar 2, 2020

export let prop;

$: prop = prop || 'default';

Probably we should add a tutorial or guide on recommend how to provide a fallback value to props if it is undefined (technically falsey)?

@mindrones
Copy link
Member

@tanhauhau agree, this would be good for a mini guide, see also #4442 (comment). Only problem the snippet suggested by @jesseskinner although correct isn't very attractive/sveltey, while the above one will give warnings.

hontas added a commit to hontas/svelte that referenced this pull request Mar 6, 2020
* 'master' of https://github.com/sveltejs/svelte: (137 commits)
  -> v3.19.2
  fix lazy code breaks in build
  fit bitmask overflow initial dirty value in 'if' blocks (sveltejs#4507)
  add dev runtime warning for unknown slot names (sveltejs#4501)
  fix render fallback slot content due to whitespace (sveltejs#4500)
  docs: describe falsy and nullish attribute behavior (sveltejs#4498)
  in spread, distinguish never-updating and always-updating props (sveltejs#4487)
  chore: more specific typings, and add README note about Yarn (sveltejs#4483)
  update changelog
  check for unknown props even if component doesn't have writable props (sveltejs#4454)
  Bump codecov from 3.5.0 to 3.6.5 (sveltejs#4433)
  fix bitmask overflow for slot (sveltejs#4485)
  mark module variables as mutated or reassigned (sveltejs#4469)
  docs: referenced_from_script var value (sveltejs#4486)
  docs: clarify default prop behaviour (sveltejs#4460)
  site: turn fancybutton into custombutton (sveltejs#4476)
  update changelog
  exclude global variables from $capture_state (sveltejs#4475)
  -> v3.19.1
  don't treat $$-names as stores during invalidation (sveltejs#4453)
  ...
taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
@StagnantIce
Copy link

If you dont want dublicate your defaults, will be better like this:

export let prop1 = 's';
exprot let prop2 = [];

const defaultValues = {prop1, prop2};

$: prop1 ??= defaultValues.prop1;
$: prop2 ??= defaultValues.prop1;

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.