Skip to content

Instantly share code, notes, and snippets.

@default-writer
Last active October 24, 2019 12:29
Show Gist options
  • Select an option

  • Save default-writer/c8c722cd94e1a442b4ec36d8197e4792 to your computer and use it in GitHub Desktop.

Select an option

Save default-writer/c8c722cd94e1a442b4ec36d8197e4792 to your computer and use it in GitHub Desktop.
svelte:CustomEvent
<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>
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