Skip to content

Commit

Permalink
perf: remove ohash dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Jun 6, 2024
1 parent d824e03 commit d0af857
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 34 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"peerDependencies": {
"vue": "^3"
},
"dependencies": {
"ohash": "^1.1.3"
},
"devDependencies": {
"@antfu/eslint-config": "^2.19.2",
"@types/node": "^20.13.0",
Expand Down
4 changes: 0 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -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]'
Expand Down Expand Up @@ -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')
Expand Down
18 changes: 0 additions & 18 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import { hash } from 'ohash'
import type { LocaleMessage, MessageParameters } from './types'

const cache = new Map<string, string>()

export function getCachedLocalizedMessage(
locale: string,
options: Parameters<typeof getLocalizedMessage>[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<Message = string>(
{
chain,
Expand Down

0 comments on commit d0af857

Please sign in to comment.