File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
packages-presets/preset-icons/src Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import type { UniversalIconLoader } from '@iconify/utils'
2
2
import { $fetch } from 'ofetch'
3
3
import { createCDNFetchLoader } from './core'
4
4
5
- export function createCDNLoader ( cdnBase : string ) : UniversalIconLoader {
5
+ export function createCDNLoader (
6
+ cdnBase : string ,
7
+ ) : UniversalIconLoader {
6
8
return createCDNFetchLoader ( $fetch , cdnBase )
7
9
}
Original file line number Diff line number Diff line change @@ -156,15 +156,17 @@ export function combineLoaders(loaders: UniversalIconLoader[]) {
156
156
} ) as UniversalIconLoader
157
157
}
158
158
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 {
162
164
function fetchCollection ( name : string ) {
163
165
if ( ! icons . includes ( name ) )
164
166
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 ) !
168
170
}
169
171
170
172
return async ( collection , icon , options ) => {
You can’t perform that action at this time.
0 commit comments