From 6e6a675c67a95a3af9634e24eea4c607105ffddf Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Jun 2019 16:49:26 -0400 Subject: [PATCH] tweak docs a bit --- site/content/docs/01-component-format.md | 73 +++++++++++++++--------- site/content/docs/02-template-syntax.md | 12 +++- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index ddd2667075..b60457d5af 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -28,41 +28,60 @@ A ` +``` + +--- + +You can specify a default value, which will be used if the component's consumer doesn't specify a prop. + +In development mode (see the [compiler options](docs#svelte_compile)), a warning will be printed if no default is provided and the consumer does not specify a value. To squelch this warning, ensure that a default is specified, even if it is `undefined`. + +```html + +``` + +--- - // you can use export { ... as ... } to have - // props whose names are reserved keywords - let clazz; - export { clazz as class }; +If you export a `const`, `class` or `function`, it is readonly from outside the component. Function *expressions* are valid props, however. - // this property is readonly externally - export const buzz = 'buzz'; +```html + +``` + +--- + +You can use reserved words as prop names. + +```html + ``` @@ -81,8 +100,8 @@ Because Svelte's reactivity is based on assignments, using array methods like `. let count = 0; function handleClick () { - // calling this function will trigger a re-render - // if the markup references `count` + // calling this function will trigger an + // update if the markup references `count` count = count + 1; } diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index ceaa19a398..981224fc14 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -20,7 +20,7 @@ A lowercase tag, like `
`, denotes a regular HTML element. A capitalised tag ``` -### Attributes +### Attributes and props --- @@ -76,6 +76,16 @@ When the attribute name and value match (`name={name}`), they can be replaced wi --- +By convention, values passed to components are referred to as *properties* or *props* rather than *attributes*, which are a feature of the DOM. + +As with elements, `name={name}` can be replaced with the `{name}` shorthand. + +```html + +``` + +--- + *Spread attributes* allow many attributes or properties to be passed to an element or component at once. An element or component can have multiple spread attributes, interspersed with regular ones.