8000 feat(icons): expose `cacheMap` in `createCDNFetchLoader` · unocss/unocss@5eae795 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 5eae795

Browse files
committed
feat(icons): expose cacheMap in createCDNFetchLoader
1 parent 43dac81 commit 5eae795

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages-presets/preset-icons/src/cdn.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { UniversalIconLoader } from '@iconify/utils'
22
import { $fetch } from 'ofetch'
33
import { createCDNFetchLoader } from './core'
44

5-
export function createCDNLoader(cdnBase: string): UniversalIconLoader {
5+
export function createCDNLoader(
6+
cdnBase: string,
7+
): UniversalIconLoader {
68
return createCDNFetchLoader($fetch, cdnBase)
79
}

packages-presets/preset-icons/src/core.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,17 @@ export function combineLoaders(loaders: UniversalIconLoader[]) {
156156
}) as UniversalIconLoader
157157
}
158158

159-
export function createCDNFetchLoader(fetcher: (url: string) => Promise<any>, cdnBase: string): UniversalIconLoader {
160-
const cache = new Map<string, Promise<IconifyJSON>>()
161-
159+
export function createCDNFetchLoader(
160+
fetcher: (url: string) => Promise<any>,
161+
cdnBase: string,
162+
cacheMap: Map<string, IconifyJSON | Promise<IconifyJSON>> = new Map(),
163+
): UniversalIconLoader {
162164
function fetchCollection(name: string) {
163165
if (!icons.includes(name))
164166
return undefined
165-
if (!cache.has(name))
166-
cache.set(name, fetcher(`${cdnBase}@iconify-json/${name}/icons.json`))
167-
return cache.get(name)!
167+
if (!cacheMap.has(name))
168+
cacheMap.set(name, fetcher(`${cdnBase}@iconify-json/${name}/icons.json`))
169+
return cacheMap.get(name)!
168170
}
169171

170172
return async (collection, icon, options) => {

0 commit comments

Comments
 (0)
0