From 725983c7527e594293fa09b426befca995e86336 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Wed, 13 Mar 2024 22:18:55 +0100 Subject: [PATCH] remove useless IIFE (#267) upd --- next-themes/src/script.ts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/next-themes/src/script.ts b/next-themes/src/script.ts index dd72a51..792cae0 100644 --- a/next-themes/src/script.ts +++ b/next-themes/src/script.ts @@ -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) { @@ -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) { + // } - })() + } }