Skip to content

Commit

Permalink
add CustomStorageEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Jun 15, 2024
1 parent 0d504ab commit 99da11f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/porridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const validStores = [
*/
export class Porridge {
eventName: string;
storageArea: string;
storageArea: 'localStorage' | 'sessionStorage';

constructor(storageArea: 'localStorage' | 'sessionStorage' = 'localStorage', eventName = 'porridge.didChange') {
if (typeof eventName !== 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function didExpire(expires: string): boolean {
return expires && new Date(expires) <= new Date();
}

function eventDispatcher(eventName, payload) {
function eventDispatcher(eventName: string, payload: WebPorridge.CustomStorageEvent) {
try {
window.dispatchEvent(
new CustomEvent(eventName, {
Expand Down
7 changes: 7 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ declare namespace WebPorridge {
value: '@value';
type: '@type';
}

type CustomStorageEvent = {
key?: string;
newValue: unknown;
oldValue: unknown;
storageArea: 'localStorage' | 'sessionStorage' | 'indexedDB';
}
}

export {
Expand Down

0 comments on commit 99da11f

Please sign in to comment.