From d0af857bf94a11129892eb50e9ef135aacbad6fd Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Thu, 6 Jun 2024 22:05:04 +0200 Subject: [PATCH] perf: remove `ohash` dependency --- package.json | 3 --- pnpm-lock.yaml | 4 ---- src/i18n.ts | 15 ++++++--------- src/utils.ts | 18 ------------------ 4 files changed, 6 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index ec9db9f..04e78cf 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,6 @@ "peerDependencies": { "vue": "^3" }, - "dependencies": { - "ohash": "^1.1.3" - }, "devDependencies": { "@antfu/eslint-config": "^2.19.2", "@types/node": "^20.13.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c35fd2..3ae262d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,10 +7,6 @@ settings: importers: .: - dependencies: - ohash: - specifier: ^1.1.3 - version: 1.1.3 devDependencies: '@antfu/eslint-config': specifier: ^2.19.2 diff --git a/src/i18n.ts b/src/i18n.ts index a0a6d99..713b4d2 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,6 +1,6 @@ import { computed, ref } from 'vue' import type { App, InjectionKey } from 'vue' -import { getCachedLocalizedMessage } from './utils' +import { getLocalizedMessage } from './utils' import type { I18nConfig, I18nInstance, MessageParameters } from './types' const CONSOLE_PREFIX = '[vue-i18n]' @@ -32,14 +32,11 @@ export function createI18n( } try { - return getCachedLocalizedMessage( - locale.value, - { - chain: key.split('.'), - messages: messages[locale.value], - params, - }, - ) + return getLocalizedMessage({ + chain: key.split('.'), + messages: messages[locale.value], + params, + }) } catch (error) { if (logLevel === 'warn') diff --git a/src/utils.ts b/src/utils.ts index b9924dc..975cc1a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,23 +1,5 @@ -import { hash } from 'ohash' import type { LocaleMessage, MessageParameters } from './types' -const cache = new Map() - -export function getCachedLocalizedMessage( - locale: string, - options: Parameters[0], -) { - const key = hash([locale, options.chain, options.params]) - - if (cache.has(key)) - return cache.get(key)! - - const message = getLocalizedMessage(options) - cache.set(key, message) - - return message -} - export function getLocalizedMessage( { chain,