diff --git a/src/storage.ts b/src/storage.ts index d53c755d..f9484116 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -69,13 +69,15 @@ export function createStorage( })); }; - const onChange: WatchCallback = (event, key) => { + const onChange: WatchCallback = (event, resource) => { if (!context.watching) { return; } - key = normalizeKey(key); + resource = normalizeKey( + typeof resource === "string" ? resource : resource.key + ); for (const listener of context.watchListeners) { - listener(event, key); + listener(event, resource); } }; diff --git a/src/types.ts b/src/types.ts index e33a8da5..1a276371 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,9 @@ export type StorageValue = null | string | number | boolean | object; export type WatchEvent = "update" | "remove"; -export type WatchCallback = (event: WatchEvent, key: string) => any; +export type WatchCallback = ( + event: WatchEvent, + resource: string | (Record & { key: string }) +) => any; type MaybePromise = T | Promise;