Skip to content

Commit

Permalink
fix(alpine): expiation data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 12, 2024
1 parent 9bcba09 commit 77eecce
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/alpine/src/store/store-with-backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ export class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends
constructor(private config__: AlpineStoreWithBackupOptions<T>) {
super(config__);

if (this.config__.expireDuration !== null) {
this.handleDataExpiration__();
if (this.config__.expireDuration != null) {
this.checkForDataExpiration__();
}

this.load__();
}

Expand Down Expand Up @@ -111,16 +112,16 @@ export class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends
* Handles the expiration duration by checking if the stored data has expired.
* If expired, it clears the stored data.
*/
private handleDataExpiration__(): void {
this.logger_.logMethod?.('handleDataExpiration__');
private checkForDataExpiration__(): void {
this.logger_.logMethod?.('checkForDataExpiration__');

const expireDuration = localJsonStorage.getItem<{time: number}>(
const expireDuration = localJsonStorage.getItem<{time: number | null}>(
this.localStorageKey__.expireTime,
{time: 0},
{time: null},
this.config__.version,
).time;

if (expireDuration < Date.now()) {
if (expireDuration !== null && expireDuration < Date.now()) {
this.clear();
}
}
Expand Down

0 comments on commit 77eecce

Please sign in to comment.