Skip to content

Commit

Permalink
docs: multiple event listeners on single node
Browse files Browse the repository at this point in the history
It documents sveltejs#2709
  • Loading branch information
ematipico authored May 20, 2019
1 parent 7ebf347 commit cb5dcf2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion site/content/docs/02-template-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,23 @@ Components can emit events using [createEventDispatcher](docs#createEventDispatc
<SomeComponent on:whatever={handler}/>
```

It's also possible to have two different listeners that react on the same event:

```html
<script>
let counter;
function increment() {
counter = counter + 1;
}
function track(event) {
trackEvent(event)
}
</script>

<button on:click="{increment}" on:click="{track}">Click me!</button>
```html

---

As with DOM events, if the `on:` directive is used without a value, the component will *forward* the event, meaning that a consumer of the component can listen for it.
Expand Down Expand Up @@ -1307,4 +1324,4 @@ It accepts a comma-separated list of variable names (not arbitrary expressions).
{@debug typeof user === 'object'}
```

The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when *any* state changes, as opposed to the specified variables.
The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when *any* state changes, as opposed to the specified variables.

0 comments on commit cb5dcf2

Please sign in to comment.