feat(tutorial): better explanation of component events

pull/4639/head
MeuhMeuh 6 years ago
parent d7497deaec
commit 25bb740bc0

@ -18,4 +18,8 @@ Components can also dispatch events. To do so, they must create an event dispatc
</script> </script>
``` ```
> `createEventDispatcher` must be called when the component is first instantiated — you can't do it later inside e.g. a `setTimeout` callback. This links `dispatch` to the component instance. > `createEventDispatcher` must be called when the component is first instantiated — you can't do it later inside e.g. a `setTimeout` callback. This links `dispatch` to the component instance.
Notice how the `App.svelte` component, that is including `Inner.svelte`, is listening to the messages dispatched by `Inner` thanks to the `on:message` attribute.
> Without this attribute, messages would still be dispatched, but the App would not react to it. Try removing the `on:message` attribute and pressing the button again!

Loading…
Cancel
Save