Complete the code to import the event dispatcher from Svelte.
import { [1] } from 'svelte';
The createEventDispatcher function is imported from Svelte to create a dispatcher for custom events.
Complete the code to create the event dispatcher inside the action function.
function myAction(node) {
const dispatch = [1]();
// action logic
}You call createEventDispatcher (without parentheses here) to get the dispatcher function inside the action.
Fix the error in dispatching a custom event named 'custom' with detail data.
dispatch('[1]', { detail: { message: 'Hello' } });
The event name should be a string that matches the custom event you want to dispatch, here 'custom'.
Fill both blanks to dispatch an event named 'update' with a payload containing count.
dispatch([1], { [2]: count });
The event name is 'update' as a string, and the payload must be inside a detail object.
Fill all three blanks to create an action that dispatches 'change' event with newValue when the node is clicked.
function changeAction(node) {
const dispatch = [1]();
node.addEventListener('click', () => {
dispatch([2], { [3]: newValue });
});
return {
destroy() {
node.removeEventListener('click', () => {});
}
};
}First, create the dispatcher with createEventDispatcher. Then dispatch the 'change' event with the payload inside detail.