-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(other): add api for persistence via Async Storage
- Loading branch information
Showing
4 changed files
with
117 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export const memoryStorage = new Map(); | ||
|
||
export const prefix = '@react-native-firebase:'; | ||
|
||
const asyncStorageMemory = { | ||
setItem(key, value) { | ||
memoryStorage.set(key, value); | ||
return Promise.resolve(); | ||
}, | ||
getItem(key) { | ||
const hasValue = memoryStorage.has(key); | ||
if (hasValue) { | ||
return Promise.resolve(memoryStorage.get(key)); | ||
} | ||
return Promise.resolve(null); | ||
}, | ||
removeItem: function (key) { | ||
memoryStorage.delete(key); | ||
return Promise.resolve(); | ||
}, | ||
}; | ||
|
||
let asyncStorage = asyncStorageMemory; | ||
|
||
export async function getReactNativeAsyncStorageInternal() { | ||
return asyncStorage; | ||
} | ||
|
||
export function setReactNativeAsyncStorageInternal(asyncStorageInstance) { | ||
asyncStorage = asyncStorageInstance || asyncStorageMemory; | ||
} | ||
|
||
export function isMemoryStorage() { | ||
return asyncStorage === asyncStorageMemory; | ||
} | ||
|
||
export async function setItem(key, value) { | ||
return await asyncStorage.setItem(prefix + key, value); | ||
} | ||
|
||
export async function getItem(key) { | ||
return await asyncStorage.getItem(prefix + key); | ||
} | ||
|
||
export async function removeItem(key) { | ||
return await asyncStorage.removeItem(prefix + key); | ||
} |
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