diff --git a/site/content/guide/00-introduction.md b/site/content/guide/00-introduction.md
index 6892832989..04ec1b7a8c 100644
--- a/site/content/guide/00-introduction.md
+++ b/site/content/guide/00-introduction.md
@@ -6,7 +6,7 @@ title: Introduction
Svelte is a tool for building fast web applications.
-It is similar to JavaScript frameworks such as React, Angular, Vue, and Ractive, which all share a goal of making it easy to build slick interactive user interfaces.
+It is similar to JavaScript frameworks such as React and Vue, which share a goal of making it easy to build slick interactive user interfaces.
But there's a crucial difference: Svelte converts your app into ideal JavaScript at *build time*, rather than interpreting your application code at *run time*. This means you don't pay the performance cost of the framework's abstractions, and you don't incur a penalty when your app first loads.
@@ -17,9 +17,7 @@ You can build your entire app with Svelte, or you can add it incrementally to an
### Understanding Svelte components
-In Svelte, an application is composed from one or more *components*. A component is a reusable self-contained block of code that encapsulates markup, styles and behaviours that belong together.
-
-Like Ractive and Vue, Svelte promotes the concept of *single-file components*: a component is just an `.html` file. Here's a simple example:
+In Svelte, an application is composed from one or more _components_. A component is a reusable self-contained block of code that encapsulates markup, styles and behaviours that belong together, written into an `.html` file. Here's a simple example:
```html
@@ -42,15 +40,15 @@ Svelte turns this into a JavaScript module that you can import into your app:
import App from './App.html';
const app = new App({
- target: document.querySelector('main'),
- data: { name: 'world' }
+ target: document.querySelector('main'),
+ props: { name: 'world' },
});
-// change the data associated with the template
-app.set({ name: 'everybody' });
+// change the component's "name" prop. We'll learn about props (aka properties) below
+app.name = 'everybody';
// detach the component and clean everything up
-app.destroy();
+app.$destroy();
```
Congratulations, you've just learned about half of Svelte's API!
@@ -60,7 +58,7 @@ Congratulations, you've just learned about half of Svelte's API!
Normally, this is the part where the instructions might tell you to add the framework to your page as a `
+
{#await promise}
wait for it...
{:then answer}
@@ -247,18 +230,6 @@ You can represent the three states of a [Promise](https://developer.mozilla.org/
{:catch error}
well that's odd
{/await}
-
-
```
If the expression in `{#await expression}` *isn't* a promise, Svelte skips ahead to the `then` section.
@@ -266,12 +237,12 @@ If the expression in `{#await expression}` *isn't* a promise, Svelte skips ahead
### Directives
-Directives allow you to add special instructions for adding [event handlers](guide#event-handlers), [bindings](guide#bindings), [referencing elements](guide#refs) and so on. We'll cover each of those in later stages of this guide – for now, all you need to know is that directives can be identified by the `:` character:
+Directives allow you to add special instructions for adding [event handlers](guide#event-handlers), [bindings](guide#bindings), [transitions](guide#transitions) and so on. We'll cover each of those in later stages of this guide – for now, all you need to know is that directives can be identified by the `:` character:
```html
Count: {count}
-
+
```
```json
@@ -290,7 +261,7 @@ To inspect data as it changes and flows through your app, use a `{@debug ...}` t
```html
-
+
{@debug name}
Hello {name}!
diff --git a/site/content/guide/03-scoped-styles.md b/site/content/guide/03-scoped-styles.md
index ca8a53a5b4..9a96da84db 100644
--- a/site/content/guide/03-scoped-styles.md
+++ b/site/content/guide/03-scoped-styles.md
@@ -10,10 +10,6 @@ Your component template can have a `
+
+
+ Big red Comic Sans
+
```
@@ -41,9 +41,9 @@ Styles will *only* apply to the current component, unless you opt in to cascadin
```html
-
-
-
+
-
+
+
+
```
> Scoped styles are *not* dynamic – they are shared between all instances of a component. In other words you can't use `{tags}` inside your CSS.
@@ -75,27 +71,27 @@ Styles will *only* apply to the current component, unless you opt in to cascadin
Svelte will identify and remove styles that are not being used in your app. It will also emit a warning so that you can remove them from the source.
-For rules *not* to be removed, they must apply to the component's markup. As far as Svelte is concerned `.active` is unused in the following code and should be removed:
+For rules *not* to be removed, they must apply to the component's markup. As far as Svelte is concerned `.bold` is unused in the following code and should be removed:
```html
-
this text is not bold
+
this text is not bold
```
@@ -104,7 +100,7 @@ Instead of manually manipulating the DOM, you should always use the `class` attr
```html
-
this text is bold
+
this text is bold
```
@@ -113,30 +109,10 @@ If that's impossible for some reason, you can use `:global(...)`:
```html
```
-The same applies to the contents of `{@html ...}` tags.
-
-
-### Special selectors
-
-If you have a [ref](guide#refs) on an element, you can use it as a CSS selector. The `ref:*` selector has the same specificity as a class or attribute selector.
-
-
-```html
-
-
- yeah!
-
-
-
-```
+The same applies to the contents of `{@html ...}` tags.
\ No newline at end of file
diff --git a/site/content/guide/04-behaviour.md b/site/content/guide/04-behaviour.md
index ca9fea021b..008a6e4556 100644
--- a/site/content/guide/04-behaviour.md
+++ b/site/content/guide/04-behaviour.md
@@ -2,880 +2,120 @@
title: Behaviours
---
-As well as scoped styles and a template, components can encapsulate *behaviours*. For that, we add a `
-```
-
-
-### Default data
-
-Often, it makes sense for a component to have default data. This should be expressed as a function that returns a plain JavaScript object:
-
-```html
-
-
Count: {count}
-
-
-```
-
-Data supplied at instantiation takes priority over defaults. In other words, if we instantiated the component above like so...
-
-```js
-const counter = new Counter({
- data: {
- count: 99
- }
-});
-```
-
-...then `{count}`, or `counter.get().count`, would initially be 99 rather than 0.
-
-
-### Computed properties
-
-Often, your program will use values that depend on other values – for example, you might have a filtered list, which depends on both the list *and* the filter. Normally in JavaScript you'd have to add logic to update the dependent property when *any* of the dependencies change. This is a frequent source of bugs, and it gets worse as your application grows.
-
-Svelte allows you to express these dependencies in computed properties, which are recalculated whenever those dependencies change:
-```html
-
-
- The time is
- {hours}:{minutes}:{seconds}
-
-
-
+
+
+
```
-Each function is passed the component's current state object. Because we're using destructuring syntax, the compiler knows that `hours`, `minutes` and `seconds` only need to re-run when `time` changes, and not when any other values change. There's no costly dependency tracking involved – the dependency graph is resolved at compile time.
-> `computed` must be an object literal, and the properties must be function expressions or arrow function expressions. Any external functions used in computed must be wrapped _here_:
+### Internal state
-```js
-import externalFunc from '_external_file';
-export default {
- computed: {
- externalFunc: ({ dep1, dep2 }) => externalFunc(dep1, dep2);
- }
-}
-```
-
-Computed properties can of course return functions. For example, we could dynamically generate a filter function for a list of items:
+Often, it makes sense for a component to have internal state that isn't visible to the outside world.
```html
-
-
-
-{#each items.filter(predicate) as word}
-
+
```
-### Lifecycle hooks
+### External properties
-There are four 'hooks' provided by Svelte for adding control logic — `oncreate`, `ondestroy`, `onstate` and `onupdate`:
+On the other hand, for the component to form part of a system, it needs to expose certain values so that they can be set from outside. These are called *props*, and we use the `export` keyword to differentiate them from internal state:
```html
-
-
- The time is
- {hours}:{minutes}:{seconds}
-
-
+
-```
-
-> You can add event listeners corresponding to `onstate`, `onupdate` and `ondestroy` programmatically — see [component.on](guide#component-on-eventname-callback-)
-
-### Helpers
-
-Helpers are simple functions that are used in your template. In the example above, we want to ensure that `minutes` and `seconds` are preceded with a `0` if they only have one digit, so we add a `leftPad` helper:
-
-```html
-
-
- The time is
- {hours}:{leftPad(minutes, 2, '0')}:{leftPad(seconds, 2, '0')}
-
-
-
+
Count: {count}
+
```
-Of course, you could use `leftPad` inside the computed properties instead of in the template. There's no hard and fast rule about when you should use expressions with helpers versus when you should use computed properties – do whatever makes your component easier for the next developer to understand.
-
-> Helper functions should be *pure* – in other words, they should not have side-effects, and their returned value should only depend on their arguments.
+> Effectively, we're exporting a *contract* with the outside world. The `export` keyword normally means something different in JavaScript, so you might be surprised to see it used like this. Just roll with it for now!
-
-### Custom methods
-
-In addition to the [built-in methods](guide#component-api), you can add methods of your own:
-
-```html
-
-
Try calling app.say('hello!') from the console
-
-
-```
-
-These become part of the component's API:
+The `= 0` sets a default value for `count`, if none is provided.
```js
-import MyComponent from './MyComponent.html';
-
-var component = new MyComponent({
- target: document.querySelector('main')
+const counter = new Counter({
+ target: document.body,
+ props: {
+ count: 99
+ }
});
-component.say('👋');
+counter.count; // 99
+counter.count += 1; // 100
```
-Methods (whether built-in or custom) can also be called inside [event handlers](guide#event-handlers):
+Props declared with `const` or `function` are *read-only* — they cannot be set from outside. This allows you to, for example, attach custom methods to your component:
-```html
-
-
-```
-
-
-### Custom event handlers
-
-Soon, we'll learn about [event handlers](guide#event-handlers) – if you want, skip ahead to that section first then come back here!
-
-Most of the time you can make do with the standard DOM events (the sort you'd add via `element.addEventListener`, such as `click`) but sometimes you might need custom events to handle gestures, for example.
-
-Custom events are just functions that take a node and a callback as their argument, and return an object with a `destroy` method that gets called when the element is removed from the page:
-
-```html
-
-
-
-{#if done}
-
clicked and held
-{/if}
-
-
+```js
+component.doSomethingFun();
```
-### Namespaces
+### Lifecycle hooks
-Components are assumed to be in the HTML namespace. If your component is designed to be used inside an `