You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
601 B

const TYPE_VALUE = 'value';
const TYPE_ERROR = 'error';
export default function createIconSourceCache() {
const cache = new Map();
const setValue = (key, value) =>
cache.set(key, { type: TYPE_VALUE, data: value });
const setError = (key, error) =>
cache.set(key, { type: TYPE_ERROR, data: error });
const has = key => cache.has(key);
const get = key => {
if (!cache.has(key)) {
return undefined;
}
const { type, data } = cache.get(key);
if (type === TYPE_ERROR) {
throw data;
}
return data;
};
return { setValue, setError, has, get };
}