Skip to content

Commit ad9173d

Browse files
authored
[fix] Clear timeout on destroy (#166)
If the component gets destroyed before the timeout is cleared, you'll be invoking a method on a node that should not exist anymore
1 parent 8d0376c commit ad9173d

File tree

2 files changed

+2
-0
lines changed
  • content/tutorial/03-advanced-svelte/04-actions/02-adding-parameters-to-actions

2 files changed

+2
-0
lines changed

content/tutorial/03-advanced-svelte/04-actions/02-adding-parameters-to-actions/app-a/src/lib/longpress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function longpress(node, duration) {
1616

1717
return {
1818
destroy() {
19+
clearTimeout(timer);
1920
node.removeEventListener('mousedown', handleMousedown);
2021
node.removeEventListener('mouseup', handleMouseup);
2122
}

content/tutorial/03-advanced-svelte/04-actions/02-adding-parameters-to-actions/app-b/src/lib/longpress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function longpress(node, duration) {
1919
duration = newDuration;
2020
},
2121
destroy() {
22+
clearTimeout(timer);
2223
node.removeEventListener('mousedown', handleMousedown);
2324
node.removeEventListener('mouseup', handleMouseup);
2425
}

0 commit comments

Comments
 (0)