Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit 37cb1b6

Browse files
authored
Fix error if calling resume method when carousel is already playing (#57)
* Avoid adding intervals when there is one already * Update built files
1 parent 3887313 commit 37cb1b6

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

dist/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@
693693

694694
return () => {
695695
autoplay && clearInterval(timer);
696+
timer = null;
696697
controller.destroy();
697698
}
698699
});
@@ -716,10 +717,11 @@
716717

717718
function pause() {
718719
clearInterval(timer);
720+
timer = null;
719721
}
720722

721723
function resume() {
722-
if (autoplay) {
724+
if (autoplay && !timer) {
723725
timer = setInterval(right, autoplay);
724726
}
725727
}

dist/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ function instance($$self, $$props, $$invalidate) {
687687

688688
return () => {
689689
autoplay && clearInterval(timer);
690+
timer = null;
690691
controller.destroy();
691692
}
692693
});
@@ -710,10 +711,11 @@ function instance($$self, $$props, $$invalidate) {
710711

711712
function pause() {
712713
clearInterval(timer);
714+
timer = null;
713715
}
714716

715717
function resume() {
716-
if (autoplay) {
718+
if (autoplay && !timer) {
717719
timer = setInterval(right, autoplay);
718720
}
719721
}

src/Carousel.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
128128
return () => {
129129
autoplay && clearInterval(timer)
130+
timer = null
130131
controller.destroy()
131132
}
132133
})
@@ -150,10 +151,11 @@
150151
151152
export function pause() {
152153
clearInterval(timer);
154+
timer = null
153155
}
154156
155157
export function resume() {
156-
if (autoplay) {
158+
if (autoplay && !timer) {
157159
timer = setInterval(right, autoplay);
158160
}
159161
}

0 commit comments

Comments
 (0)