-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8338b9
commit 4b2d422
Showing
9 changed files
with
110 additions
and
19 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
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
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,42 @@ | ||
import AsyncStorage from '@react-native-async-storage/async-storage' | ||
|
||
export class LocalStorage { | ||
localStore: Record<string, string> = {} | ||
length = 0 | ||
|
||
getItem(key: string) { | ||
return this.localStore[key] ?? null | ||
} | ||
|
||
setItem(key: string, value: string) { | ||
this.localStore[key] = value | ||
this.length = Object.keys(this.localStore).length | ||
AsyncStorage.setItem(key, value) | ||
} | ||
|
||
removeItem(key: string) { | ||
delete this.localStore[key] | ||
this.length = Object.keys(this.localStore).length | ||
AsyncStorage.removeItem(key) | ||
} | ||
|
||
clear() { | ||
this.localStore = {} | ||
this.length = 0 | ||
AsyncStorage.clear() | ||
} | ||
|
||
async load() { | ||
const keys = await AsyncStorage.getAllKeys() | ||
const items = await AsyncStorage.multiGet(keys) | ||
this.localStore = Object.fromEntries(items) | ||
} | ||
|
||
async sync() { | ||
await AsyncStorage.multiSet(Object.entries(this.localStore)) | ||
} | ||
|
||
key(index: number) { | ||
return Object.keys(this.localStore)[index] | ||
} | ||
} |
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
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
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