mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-11 15:33:33 -07:00
global: fixes
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* @template V
|
||||
* @param {number} [maxSize]
|
||||
*/
|
||||
export function createMapCache(maxSize = 100) {
|
||||
/** @type {Map<string, V>} */
|
||||
const map = new Map();
|
||||
|
||||
/** @param {string} key @param {V} value */
|
||||
const set = (key, value) => {
|
||||
if (map.size >= maxSize && !map.has(key)) {
|
||||
const first = map.keys().next().value;
|
||||
if (first !== undefined) map.delete(first);
|
||||
}
|
||||
map.set(key, value);
|
||||
};
|
||||
|
||||
return {
|
||||
/** @param {string} key @returns {V | undefined} */
|
||||
get: (key) => map.get(key),
|
||||
/** @param {string} key @returns {boolean} */
|
||||
has: (key) => map.has(key),
|
||||
set,
|
||||
/** @param {string} key @param {() => Promise<V>} fetcher @returns {Promise<V>} */
|
||||
async fetch(key, fetcher) {
|
||||
const hit = map.get(key);
|
||||
if (hit !== undefined) return hit;
|
||||
const value = await fetcher();
|
||||
set(key, value);
|
||||
return value;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @template V
|
||||
* @typedef {ReturnType<typeof createMapCache<V>>} MapCache
|
||||
*/
|
||||
@@ -10,7 +10,6 @@ import { capture } from "./capture.js";
|
||||
import { colors } from "../colors.js";
|
||||
import { createRadios, createSelect, getElementById } from "../dom.js";
|
||||
import { createPersistedValue } from "../persisted.js";
|
||||
import { createMapCache } from "../cache.js";
|
||||
import { onChange as onThemeChange } from "../theme.js";
|
||||
import { throttle, debounce } from "../timing.js";
|
||||
import { serdeBool, INDEX_FROM_LABEL } from "../serde.js";
|
||||
@@ -193,7 +192,8 @@ export function createChart({ parent, brk, fitContent }) {
|
||||
},
|
||||
};
|
||||
|
||||
const cache = createMapCache(Infinity);
|
||||
/** @type {Map<string, AnySeriesData>} */
|
||||
const cache = new Map();
|
||||
|
||||
// Range state: localStorage stores all ranges per-index, URL stores current range only
|
||||
/** @typedef {{ from: number, to: number }} Range */
|
||||
|
||||
Reference in New Issue
Block a user