Skip to content

Commit

Permalink
refactor: update name of reduced-motions handleThemeChange to handleM…
Browse files Browse the repository at this point in the history
…otionChange (#4)

* update name of handler to conform with hint subscribed to

* rename cleanup in subscribe of reduced-motion
  • Loading branch information
muhammadjalabi authored Nov 26, 2023
1 parent fe42d66 commit 5dd9f67
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/reduced-motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export function subscribeToMotionChange(
cookieName: string = clientHint.cookieName,
) {
const motionMatch = window.matchMedia('(prefers-reduced-motion: reduce)')
function handleThemeChange() {
function handleMotionChange() {
const value = motionMatch.matches ? 'reduce' : 'no-preference'
document.cookie = `${cookieName}=${value}; Max-Age=31536000; Path=/`
subscriber(value)
}
motionMatch.addEventListener('change', handleThemeChange)
return function cleanupSchemaChange() {
motionMatch.removeEventListener('change', handleThemeChange)
motionMatch.addEventListener('change', handleMotionChange)
return function cleanupMotionChange() {
motionMatch.removeEventListener('change', handleMotionChange)
}
}

0 comments on commit 5dd9f67

Please sign in to comment.