UNPKG

seitu

Version:
23 lines (22 loc) • 697 B
//#region src/internal/storage-event.ts function dispatchStorageEvent(storageArea, key, oldValue, newValue) { if (oldValue === newValue) return; window.dispatchEvent(new StorageEvent("storage", { key, oldValue, newValue, storageArea, url: window.location.href })); } /** Attaches a `storage` listener; returns undefined on the server. */ function listenStorage(shouldNotify, notify) { if (typeof window === "undefined") return; const listener = (event) => { if (shouldNotify(event)) notify(); }; window.addEventListener("storage", listener); return () => window.removeEventListener("storage", listener); } //#endregion export { listenStorage as n, dispatchStorageEvent as t };