MCPcopy Index your code
hub / github.com/plotly/dash / fillStorage

Function fillStorage

dash/dash-renderer/tests/persistence.test.js:12–42  ·  view source on GitHub ↗
(store, key)

Source from the content-addressed store, hash-verified

10};
11
12const fillStorage = (store, key) => {
13 // double the attempted string until we fail
14 // then a binary search to find the exact point of failure
15 const maxPow = 30;
16 let pow = 0;
17 for (; pow < maxPow; pow++) {
18 try {
19 store.setItem(key, longString(pow));
20 } catch (e) {
21 break;
22 }
23 }
24 pow--;
25 let s = longString(pow);
26 for (pow--; pow >= 0; pow--) {
27 const s2 = s + longString(pow);
28 try {
29 store.setItem(key, s2);
30 s = s2;
31 } catch (e) {
32 // s remains as is, next time we'll add half as much
33 }
34 }
35 // finally a sanity check that nothing more can be added
36 try {
37 store.setItem(key + '+', 'a');
38 } catch (e) {
39 return;
40 }
41 throw new Error('Something still fits in the store?');
42};
43
44const clearStores = () => {
45 window.localStorage.clear();

Callers 1

Calls 2

longStringFunction · 0.70
setItemMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…