diff --git a/site/content/examples/13-actions/01-adding-parameters-to-actions/App.svelte b/site/content/examples/13-actions/01-adding-parameters-to-actions/App.svelte index 0bd9d56113..97079a275b 100644 --- a/site/content/examples/13-actions/01-adding-parameters-to-actions/App.svelte +++ b/site/content/examples/13-actions/01-adding-parameters-to-actions/App.svelte @@ -1,70 +1,20 @@ - destroy() { - tooltip.remove(); - node.removeEventListener('mouseenter', append); - node.removeEventListener('mouseleave', remove); - } - }; - } + - function toggleLanguage() { - language = language === 'english' ? 'latin' : 'english' - } - + - \ No newline at end of file +{#if pressed} +

congratulations, you pressed and held for {duration}ms

+{/if} \ No newline at end of file diff --git a/site/content/examples/13-actions/01-adding-parameters-to-actions/longpress.js b/site/content/examples/13-actions/01-adding-parameters-to-actions/longpress.js new file mode 100644 index 0000000000..0bb3019c7b --- /dev/null +++ b/site/content/examples/13-actions/01-adding-parameters-to-actions/longpress.js @@ -0,0 +1,20 @@ +export function longpress(node, duration) { + const handleMousedown = () => { + setTimeout(() => { + node.dispatchEvent( + new CustomEvent('longpress') + ); + }, duration); + }; + + node.addEventListener('mousedown', handleMousedown); + + return { + update(newDuration) { + duration = newDuration; + }, + destroy() { + node.removeEventListener('mousedown', handleMousedown); + } + }; +} \ No newline at end of file