Skip to content

Commit

Permalink
Core - Call window.setTimeout instead of setTimeout to improve IDE hints
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Oct 31, 2023
1 parent e2b9e58 commit edf5eef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions demo/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default defineNuxtConfig({
},
notivue: {
// addPlugin: true,
// limit: Infinity,
notifications: {
global: {
// duration: Infinity,
Expand All @@ -23,7 +22,8 @@ export default defineNuxtConfig({
},
vite: {
build: {
cssMinify: 'lightningcss',
// Never use lightningcss - https://github.com/parcel-bundler/lightningcss/issues/288
cssMinify: 'esbuild',
},
css: {
transformer: 'lightningcss',
Expand Down
6 changes: 3 additions & 3 deletions packages/notivue/Notivue/composables/useTouchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export function useTouchEvents() {

function pauseTouch(event: PointerEvent) {
if (!isMouse(event)) {
clearTimeout(timeouts.touchDebounceTimeout)
window.clearTimeout(timeouts.touchDebounceTimeout)
timeouts.pause()

timeouts.touchDebounceTimeout = setTimeout(() => {
timeouts.touchDebounceTimeout = window.setTimeout(() => {
timeouts.resume()
}, 2000)
}
}

onBeforeUnmount(() => {
clearTimeout(timeouts.touchDebounceTimeout)
window.clearTimeout(timeouts.touchDebounceTimeout)
})

return computed(() =>
Expand Down
10 changes: 5 additions & 5 deletions packages/notivue/NotivueSwipe/NotivueSwipe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ function getDebounceMs(e: PointerEvent) {
}
function pauseTimeouts() {
clearTimeout(timeouts.touchDebounceTimeout)
window.clearTimeout(timeouts.touchDebounceTimeout)
timeouts.pause()
}
function resumeTimeouts(ms: number) {
clearTimeout(timeouts.touchDebounceTimeout)
window.clearTimeout(timeouts.touchDebounceTimeout)
timeouts.touchDebounceTimeout = setTimeout(() => {
timeouts.touchDebounceTimeout = window.setTimeout(() => {
timeouts.resume()
}, ms)
}
Expand Down Expand Up @@ -249,7 +249,7 @@ function onPointerMoveClear(e: PointerEvent) {
}
const animDuration = parseFloat(animations.getTransitionData()?.duration ?? 0) * 1000
setTimeout(() => (state.isClearing = false), animDuration)
window.setTimeout(() => (state.isClearing = false), animDuration)
}
/**
Expand Down Expand Up @@ -281,7 +281,7 @@ function onPointerUp(e: PointerEvent) {
isLocked: true,
})
setTimeout(() => (state.isLocked = false), RETURN_DUR)
window.setTimeout(() => (state.isLocked = false), RETURN_DUR)
}
/**
Expand Down
8 changes: 4 additions & 4 deletions packages/notivue/core/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function createAnimationsSlice(

export function createTimeoutsSlice(items: ItemsSlice, animations: AnimationsSlice) {
return {
touchDebounceTimeout: undefined as unknown as ReturnType<typeof setTimeout>,
touchDebounceTimeout: undefined as undefined | number,
isStreamPaused: ref(false),
isStreamFocused: ref(false),
setStreamPause(newVal = true) {
Expand All @@ -232,7 +232,7 @@ export function createTimeoutsSlice(items: ItemsSlice, animations: AnimationsSli
this.isStreamFocused.value = newVal
},
reset() {
clearTimeout(this.touchDebounceTimeout)
window.clearTimeout(this.touchDebounceTimeout)

this.setStreamPause(false)
this.setStreamFocus(false)
Expand All @@ -256,7 +256,7 @@ export function createTimeoutsSlice(items: ItemsSlice, animations: AnimationsSli

console.log('Pausing timeouts')
items.updateAll((item) => {
clearTimeout(item.timeout as number)
window.clearTimeout(item.timeout as number)

return {
...item,
Expand All @@ -271,7 +271,7 @@ export function createTimeoutsSlice(items: ItemsSlice, animations: AnimationsSli

console.log('Resuming timeouts')
items.updateAll((item) => {
clearTimeout(item.timeout as number)
window.clearTimeout(item.timeout as number)
/**
* 'elapsed' may be equal to 'undefined' if a notification
* is pushed while the stream is paused as pause() won't be called.
Expand Down
2 changes: 0 additions & 2 deletions tests/Notivue/config-pause-on-hover.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Notivue from './components/Notivue.vue'

import type { VueWrapper } from '@vue/test-utils'

describe('Pause on hover', () => {
Expand Down

0 comments on commit edf5eef

Please sign in to comment.