Last active
October 24, 2019 12:29
-
-
Save default-writer/c8c722cd94e1a442b4ec36d8197e4792 to your computer and use it in GitHub Desktop.
svelte:CustomEvent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| import { timer } from './timer.js'; | |
| let time = ''; | |
| </script> | |
| <h1>Hello from Svelte!</h1> | |
| <p use:timer on:timer={event=>time=event.detail}>It's currently {time}</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function timer(node) { | |
| const interval = setInterval(() => { | |
| node.dispatchEvent(new CustomEvent('timer', { | |
| detail: new Date() | |
| })); | |
| }, 1000); | |
| return { | |
| destroy() { | |
| clearInterval(interval); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment