Skip to content

Commit d0af857

Browse files
perf: remove ohash dependency
1 parent d824e03 commit d0af857

File tree

4 files changed

+6
-34
lines changed

4 files changed

+6
-34
lines changed

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
"peerDependencies": {
4242
"vue": "^3"
4343
},
44-
"dependencies": {
45-
"ohash": "^1.1.3"
46-
},
4744
"devDependencies": {
4845
"@antfu/eslint-config": "^2.19.2",
4946
"@types/node": "^20.13.0",

pnpm-lock.yaml

-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { computed, ref } from 'vue'
22
import type { App, InjectionKey } from 'vue'
3-
import { getCachedLocalizedMessage } from './utils'
3+
import { getLocalizedMessage } from './utils'
44
import type { I18nConfig, I18nInstance, MessageParameters } from './types'
55

66
const CONSOLE_PREFIX = '[vue-i18n]'
@@ -32,14 +32,11 @@ export function createI18n(
3232
}
3333

3434
try {
35-
return getCachedLocalizedMessage(
36-
locale.value,
37-
{
38-
chain: key.split('.'),
39-
messages: messages[locale.value],
40-
params,
41-
},
42-
)
35+
return getLocalizedMessage({
36+
chain: key.split('.'),
37+
messages: messages[locale.value],
38+
params,
39+
})
4340
}
4441
catch (error) {
4542
if (logLevel === 'warn')

src/utils.ts

-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
import { hash } from 'ohash'
21
import type { LocaleMessage, MessageParameters } from './types'
32

4-
const cache = new Map<string, string>()
5-
6-
export function getCachedLocalizedMessage(
7-
locale: string,
8-
options: Parameters<typeof getLocalizedMessage>[0],
9-
) {
10-
const key = hash([locale, options.chain, options.params])
11-
12-
if (cache.has(key))
13-
return cache.get(key)!
14-
15-
const message = getLocalizedMessage(options)
16-
cache.set(key, message)
17-
18-
return message
19-
}
20-
213
export function getLocalizedMessage<Message = string>(
224
{
235
chain,

0 commit comments

Comments
 (0)