From c5aec5f2d0766e98fad00bed9d7a51caf46b1884 Mon Sep 17 00:00:00 2001 From: MeuhMeuh Date: Mon, 6 Apr 2020 15:56:47 +0200 Subject: [PATCH] fix(tutorial): more precise explanation --- site/content/tutorial/05-events/04-component-events/text.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/site/content/tutorial/05-events/04-component-events/text.md b/site/content/tutorial/05-events/04-component-events/text.md index 1226450ea0..3af0254600 100644 --- a/site/content/tutorial/05-events/04-component-events/text.md +++ b/site/content/tutorial/05-events/04-component-events/text.md @@ -20,6 +20,8 @@ Components can also dispatch events. To do so, they must create an event dispatc > `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. +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. This attribute is named with `on:` followed by the event name that we are dispatching (here, `message`). -> 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! +Without this attribute, messages would still be dispatched, but the App would not react to it. You can try removing the `on:message` attribute and pressing the button again. + +> You can also try changing the event name to anything you like. For instance, change `dispatch('message')` to `dispatch('myevent')` in `Inner.svelte` and change the attribute name from `on:message` to `on:myevent` in the `App.svelte` component. This still works!