From db37501fdd40290a89b820e34f4ecd9451c28639 Mon Sep 17 00:00:00 2001 From: SushilMallRC Date: Thu, 11 Jul 2024 10:45:56 +0530 Subject: [PATCH 1/2] Support asynchronous externals.localStorage API --- sdk/src/core/Cache.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sdk/src/core/Cache.ts b/sdk/src/core/Cache.ts index 70e723f..e970b74 100644 --- a/sdk/src/core/Cache.ts +++ b/sdk/src/core/Cache.ts @@ -23,7 +23,9 @@ export default class Cache { } public async setItem(key, data) { - this.setItemSync(key, data); + await this._externals.localStorage.setItem(this._prefixKey(key), JSON.stringify(data)); + return this; + //this.setItemSync(key, data); } public removeItemSync(key) { @@ -32,7 +34,9 @@ export default class Cache { } public async removeItem(key) { - await this.removeItemSync(key); + await this._externals.localStorage.removeItem(this._prefixKey(key)); + return this; + //await this.removeItemSync(key); } public getItemSync(key) { @@ -42,7 +46,10 @@ export default class Cache { } public async getItem(key) { - return this.getItemSync(key); + const item = await this._externals.localStorage.getItem(this._prefixKey(key)); + if (!item) {return null;} + return JSON.parse(item); + // return this.getItemSync(key); } private async _keys(): Promise { From ac33e42f93f4cf5d14da09bdbb893d4e1f8f266f Mon Sep 17 00:00:00 2001 From: SushilMallRC Date: Thu, 11 Jul 2024 11:08:25 +0530 Subject: [PATCH 2/2] remove return --- sdk/src/core/Cache.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/src/core/Cache.ts b/sdk/src/core/Cache.ts index e970b74..490da05 100644 --- a/sdk/src/core/Cache.ts +++ b/sdk/src/core/Cache.ts @@ -24,7 +24,6 @@ export default class Cache { public async setItem(key, data) { await this._externals.localStorage.setItem(this._prefixKey(key), JSON.stringify(data)); - return this; //this.setItemSync(key, data); } @@ -35,7 +34,6 @@ export default class Cache { public async removeItem(key) { await this._externals.localStorage.removeItem(this._prefixKey(key)); - return this; //await this.removeItemSync(key); }