@momentum-design/components 0.25.2 → 0.25.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +69 -69
- package/dist/browser/index.js.map +4 -4
- package/dist/components/icon/icon.component.js +18 -17
- package/dist/components/icon/icon.utils.d.ts +19 -1
- package/dist/components/icon/icon.utils.js +64 -6
- package/dist/components/iconprovider/iconprovider.component.d.ts +35 -10
- package/dist/components/iconprovider/iconprovider.component.js +18 -15
- package/dist/components/iconprovider/iconprovider.context.d.ts +2 -2
- package/dist/components/iconprovider/iconprovider.context.js +0 -3
- package/dist/custom-elements.json +261 -243
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/react/iconprovider/index.d.ts +7 -3
- package/dist/react/iconprovider/index.js +7 -3
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/utils/icon-cache/index.d.ts +32 -0
- package/dist/utils/icon-cache/index.js +54 -0
- package/package.json +1 -1
@@ -0,0 +1,32 @@
|
|
1
|
+
export type CacheStrategy = 'in-memory-cache' | 'web-cache-api';
|
2
|
+
/**
|
3
|
+
* Cache, using In-Memory Cache (Map)
|
4
|
+
* @param name - name of the cache (used as an identifier)
|
5
|
+
* @returns Object with set, get and delete methods
|
6
|
+
*/
|
7
|
+
export declare const inMemoryCache: (name: string) => Promise<{
|
8
|
+
set(request: Request, response: Response): Promise<void>;
|
9
|
+
get(request: Request): Promise<string | undefined>;
|
10
|
+
delete(request: Request): Promise<void>;
|
11
|
+
}>;
|
12
|
+
/**
|
13
|
+
* Cache, using Web API Cache
|
14
|
+
* @param name - name of the cache (used as an identifier)
|
15
|
+
* @returns Object with set, get and delete methods
|
16
|
+
*/
|
17
|
+
export declare const webAPIIconsCache: (name: string) => Promise<{
|
18
|
+
set: (request: Request, response: Response) => Promise<void>;
|
19
|
+
get: (request: Request) => Promise<string | undefined>;
|
20
|
+
delete: (request: Request) => Promise<void>;
|
21
|
+
}>;
|
22
|
+
/**
|
23
|
+
* Function to return the cache based on the cache strategy
|
24
|
+
* @param cacheName - name of the cache to be used
|
25
|
+
* @param cacheStrategy - strategy to be used for caching
|
26
|
+
* @returns the cache based on the strategy
|
27
|
+
*/
|
28
|
+
export declare const iconsCache: (cacheName: string, cacheStrategy: CacheStrategy) => Promise<{
|
29
|
+
set(request: Request, response: Response): Promise<void>;
|
30
|
+
get(request: Request): Promise<string | undefined>;
|
31
|
+
delete(request: Request): Promise<void>;
|
32
|
+
}>;
|
@@ -0,0 +1,54 @@
|
|
1
|
+
const registry = {};
|
2
|
+
/**
|
3
|
+
* Cache, using In-Memory Cache (Map)
|
4
|
+
* @param name - name of the cache (used as an identifier)
|
5
|
+
* @returns Object with set, get and delete methods
|
6
|
+
*/
|
7
|
+
export const inMemoryCache = async (name) => {
|
8
|
+
if (registry[name] === undefined) {
|
9
|
+
registry[name] = new Map();
|
10
|
+
}
|
11
|
+
return {
|
12
|
+
async set(request, response) {
|
13
|
+
registry[name].set(request.url, await response.text());
|
14
|
+
},
|
15
|
+
async get(request) {
|
16
|
+
return registry[name].get(request.url);
|
17
|
+
},
|
18
|
+
async delete(request) {
|
19
|
+
registry[name].delete(request.url);
|
20
|
+
},
|
21
|
+
};
|
22
|
+
};
|
23
|
+
/**
|
24
|
+
* Cache, using Web API Cache
|
25
|
+
* @param name - name of the cache (used as an identifier)
|
26
|
+
* @returns Object with set, get and delete methods
|
27
|
+
*/
|
28
|
+
export const webAPIIconsCache = async (name) => {
|
29
|
+
const cache = await caches.open(name);
|
30
|
+
return {
|
31
|
+
set: async (request, response) => {
|
32
|
+
await cache.put(request, response);
|
33
|
+
},
|
34
|
+
get: async (request) => {
|
35
|
+
const response = await cache.match(request);
|
36
|
+
return response === null || response === void 0 ? void 0 : response.text();
|
37
|
+
},
|
38
|
+
delete: async (request) => {
|
39
|
+
await cache.delete(request);
|
40
|
+
},
|
41
|
+
};
|
42
|
+
};
|
43
|
+
/**
|
44
|
+
* Function to return the cache based on the cache strategy
|
45
|
+
* @param cacheName - name of the cache to be used
|
46
|
+
* @param cacheStrategy - strategy to be used for caching
|
47
|
+
* @returns the cache based on the strategy
|
48
|
+
*/
|
49
|
+
export const iconsCache = async (cacheName, cacheStrategy) => {
|
50
|
+
if (cacheStrategy === 'in-memory-cache') {
|
51
|
+
return inMemoryCache(cacheName);
|
52
|
+
}
|
53
|
+
return webAPIIconsCache(cacheName);
|
54
|
+
};
|
package/package.json
CHANGED