Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 5, 2022
1 parent d3998e3 commit 697e76c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/core/useDevicePixelRatio/index.ts
Expand Up @@ -19,7 +19,6 @@ export function useDevicePixelRatio({

const pixelRatio = ref(1)

let mqResolution: MediaQueryList
const cleanups: Fn[] = []

const cleanup = () => {
Expand All @@ -30,10 +29,10 @@ export function useDevicePixelRatio({
const observe = () => {
pixelRatio.value = window.devicePixelRatio
cleanup()
mqResolution = window.matchMedia(`(resolution: ${pixelRatio.value}dppx)`)
mqResolution.addEventListener('change', observe, { once: true })
const media = window.matchMedia(`(resolution: ${pixelRatio.value}dppx)`)
media.addEventListener('change', observe, { once: true })
cleanups.push(() => {
mqResolution.removeEventListener('change', observe)
media.removeEventListener('change', observe)
})
}

Expand Down

0 comments on commit 697e76c

Please sign in to comment.