diff --git a/extensions/storage/src/index.ts b/extensions/storage/src/index.ts index a422e749..90f9c8bc 100644 --- a/extensions/storage/src/index.ts +++ b/extensions/storage/src/index.ts @@ -21,12 +21,14 @@ export default function storageExtension(options?: Par type, prefix, sync, + exclude, serialiser, parser, } = { type: 'local', prefix: 'harlem', sync: true, + exclude: [], serialiser: state => JSON.stringify(state), parser: value => JSON.parse(value), ...options, @@ -38,7 +40,7 @@ export default function storageExtension(options?: Par const storageKey = prefix ? `${prefix}:${store.name}` : store.name; store.on(EVENTS.mutation.success, (event?: EventPayload) => { - if (!event || event.data.mutation === '$storage') { + if (!event || event.data.mutation === '$storage' || exclude.includes(event.data.mutation)) { return; } @@ -63,6 +65,10 @@ export default function storageExtension(options?: Par window.removeEventListener('storage', listener); } + function clearStorage() { + storage.removeItem(storageKey); + } + store.once(EVENTS.store.destroyed, () => stopStorageSync()); if (sync) { @@ -72,6 +78,7 @@ export default function storageExtension(options?: Par return { startStorageSync, stopStorageSync, + clearStorage, }; }; } \ No newline at end of file diff --git a/extensions/storage/src/types.ts b/extensions/storage/src/types.ts index 4eb26abf..eb5952ca 100644 --- a/extensions/storage/src/types.ts +++ b/extensions/storage/src/types.ts @@ -9,6 +9,7 @@ export interface Options { type: StorageType; prefix: string; sync: boolean; + exclude: string[]; serialiser(state: ReadState): string; parser(value: string): TState; } \ No newline at end of file