diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index 616c662476..8b939d183e 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -490,10 +490,69 @@ You can bind to component props using the same mechanism: Components also support `bind:this`, allowing you to interact with component instances programmatically. +#### Classes + +A `class:` directive provides a shorter way of toggling a class on an element. These are equivalent: + +```html +
...
+
...
+ + +
...
+``` + + +#### Actions + +Actions are functions that are called when an element is created. They must return an object with a `destroy` method that is called after the element is unmounted: + +```html + + +
+``` + +An action can have arguments. If the returned value has an `update` method, it will be called whenever those arguments change, immediately after Svelte has applied updates to the markup: + +```html + + +
+``` + +> Don't worry about the fact that we're redeclaring the `foo` function for every component instance — Svelte will hoist any functions that don't depend on local state out of the component definition. + + + #### TODO -* classes -* actions * transitions * animations * slots