Skip to content

Commit

Permalink
Merge pull request #4 from chungchunwang/main
Browse files Browse the repository at this point in the history
Resolves bug where interval continues even on new page.
  • Loading branch information
MartinPicc authored Dec 6, 2022
2 parents cb200ca + d7a0d8c commit da784ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Interval",
"version": "1.1.0",
"version": "1.1.1",
"description": "Set time interval to trigger actions.",
"license": "MIT",
"svelte": "index.js",
Expand Down
10 changes: 7 additions & 3 deletions src/lib/Interval.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<script>
import { createEventDispatcher } from "svelte";
import { createEventDispatcher, onDestroy } from "svelte";
import stopwatchSvg from './icons/stopwatch.svg';
const dispatch = createEventDispatcher();
export let interval;
export let display = true;
export let text = "Interval";
let intervalID = null;
if (interval > 0) {
window.setInterval(() => { dispatch("trigger"); }, interval * 1000);
intervalID = window.setInterval(() => { dispatch("trigger"); }, interval * 1000);
}
onDestroy(() => {
if(intervalID) window.clearInterval(intervalID);
});
</script>

{#if display}
Expand Down

0 comments on commit da784ed

Please sign in to comment.