@mui/toolpad-utils
Advanced tools
Comparing version
@@ -8,32 +8,17 @@ import { | ||
var emitter = new Emitter(); | ||
var cache = /* @__PURE__ */ new Map(); | ||
function subscribe(area, key, cb) { | ||
const onKeyChange = () => { | ||
cache.delete(key); | ||
cb(); | ||
}; | ||
const storageHandler = (event) => { | ||
if (event.storageArea === area && event.key === key) { | ||
onKeyChange(); | ||
cb(); | ||
} | ||
}; | ||
window.addEventListener("storage", storageHandler); | ||
emitter.on(key, onKeyChange); | ||
emitter.on(key, cb); | ||
return () => { | ||
window.removeEventListener("storage", storageHandler); | ||
emitter.off(key, onKeyChange); | ||
emitter.off(key, cb); | ||
}; | ||
} | ||
function getSnapshot(area, key) { | ||
let value = cache.get(key) ?? null; | ||
if (!value) { | ||
const item = area.getItem(key); | ||
value = item; | ||
if (value === null) { | ||
cache.delete(key); | ||
} else { | ||
cache.set(key, value); | ||
} | ||
} | ||
return value; | ||
return area.getItem(key); | ||
} | ||
@@ -43,6 +28,4 @@ function setValue(area, key, value) { | ||
if (value === null) { | ||
cache.delete(key); | ||
area.removeItem(key); | ||
} else { | ||
cache.set(key, value); | ||
area.setItem(key, String(value)); | ||
@@ -49,0 +32,0 @@ } |
{ | ||
"name": "@mui/toolpad-utils", | ||
"version": "0.1.44", | ||
"version": "0.1.45", | ||
"description": "Build MUI apps quickly", | ||
@@ -65,7 +65,7 @@ "author": "MUI Toolpad team", | ||
"@types/prettier": "2.7.3", | ||
"@types/react": "18.2.46", | ||
"@types/react": "18.2.47", | ||
"@types/react-is": "18.2.4", | ||
"@types/title": "3.4.3" | ||
}, | ||
"gitHead": "2fe722be5e3fbcc44e11a29e1490c348f518fa6c" | ||
"gitHead": "d1e2743334d036a98c9a0867404f3fbcf70f6e43" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
249377
-0.94%2931
-1.15%