Skip to content

Commit

Permalink
remove useless IIFE (pacocoursey#267)
Browse files Browse the repository at this point in the history
upd
  • Loading branch information
Dimitri POSTOLOV authored Mar 13, 2024
1 parent 5f8669a commit 725983c
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions next-themes/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export const script = (
const el = document.documentElement
const systemThemes = ['light', 'dark']
const isClass = attribute === 'class'
const classes =
isClass && value
? themes.map(t => value[t] || t)
: themes
const classes = isClass && value ? themes.map(t => value[t] || t) : themes

function updateDOM(theme: string) {
if (isClass) {
Expand All @@ -37,18 +34,16 @@ export const script = (
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

;(function () {
if (forcedTheme) {
updateDOM(forcedTheme)
} else {
try {
const themeName = localStorage.getItem(storageKey) || defaultTheme
const isSystem = enableSystem && themeName === 'system'
const theme = isSystem ? getSystemTheme() : themeName
updateDOM(theme)
} catch (e) {
//
}
if (forcedTheme) {
updateDOM(forcedTheme)
} else {
try {
const themeName = localStorage.getItem(storageKey) || defaultTheme
const isSystem = enableSystem && themeName === 'system'
const theme = isSystem ? getSystemTheme() : themeName
updateDOM(theme)
} catch (e) {
//
}
})()
}
}

0 comments on commit 725983c

Please sign in to comment.