-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📀 Add own local storage implementation (#848)
* Add own implementation * Create local-storage-implementation.md * Fix lint * Update packages/core/src/constants/type/Config.ts Co-authored-by: Przemyslaw Rzad <przemyslaw.rzad@trusttoken.com> * Add localStorageObject * Add local storage improvement * Update packages/core/src/constants/type/Config.ts Co-authored-by: Przemyslaw Rzad <przemyslaw.rzad@trusttoken.com> * Remove neccessary localStorageItem * Add own implementation * Fix lint * Create local-storage-implementation.md * Update packages/core/src/constants/type/Config.ts Co-authored-by: Przemyslaw Rzad <przemyslaw.rzad@trusttoken.com> * Add localStorageObject * Add local storage improvement * Update packages/core/src/constants/type/Config.ts Co-authored-by: Przemyslaw Rzad <przemyslaw.rzad@trusttoken.com> * Remove neccessary localStorageItem * Some changes * Some changes * Linting * Remove unnecessary if statement * Some changes * Update packages/core/src/hooks/useLocalStorage.ts * Remove unnecessary if statement * Add custom localStorage * Remove unnecessary if statement * Refactor LocalStorage class Co-authored-by: mj426382 <mateusz.jandula@trusttoken.com> Co-authored-by: Przemyslaw Rzad <przemyslaw.rzad@trusttoken.com> Co-authored-by: Jakub Sieczczyński <j.sieczczynski@gmail.com>
- Loading branch information
1 parent
4fa72d2
commit e89b3d6
Showing
5 changed files
with
515 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@usedapp/core": patch | ||
--- | ||
|
||
📀 Add own local storage implementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export default class LocalStorage { | ||
private data: { [key: string]: string } = {} | ||
length = 0 | ||
|
||
clear() { | ||
this.data = {} | ||
this.length = 0 | ||
} | ||
|
||
getItem(key: string): string | null { | ||
const item: any = this.data[key] | ||
return item || null | ||
} | ||
|
||
key(index: number): string | null { | ||
const keys = Object.keys(this.data) | ||
return keys[index] || null | ||
} | ||
|
||
removeItem(key: string): void { | ||
if (this.data[key]) { | ||
delete this.data[key] | ||
this.length-- | ||
} | ||
} | ||
|
||
setItem(key: string, value: string): void { | ||
if (!this.data[key]) { | ||
this.length++ | ||
} | ||
this.data[key] = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
e89b3d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://usedapp-docs.netlify.app as production
🚀 Deployed on https://630e28889523b07459ece4c0--usedapp-docs.netlify.app
e89b3d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://example.usedapp.io as production
🚀 Deployed on https://630e2890f6a43e713fbe4543--usedapp-example.netlify.app
e89b3d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://usedapp.io as production
🚀 Deployed on https://630e289744eb2971d73e489a--usedapp-website.netlify.app