Skip to content

Commit 8a8687f

Browse files
committed
Incorporate some more feedback
1 parent a452023 commit 8a8687f

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

packages/datafile-manager/__mocks__/@react-native-community/async-storage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ export default class AsyncStorage {
1818
static getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise<string | null> {
1919
return new Promise((resolve, reject) => {
2020
switch (key) {
21-
case 'keyThatExists':
21+
case 'keyThatExists':
2222
resolve('{ "name": "Awesome Object" }')
23-
break;
23+
break
2424
case 'keyThatDoesNotExist':
2525
resolve(null)
26-
break;
26+
break
2727
case 'keyWithInvalidJsonObject':
2828
resolve('bad json }')
29-
break;
29+
break
3030
}
3131
})
3232
}
3333

3434
static setItem(key: string, value: string, callback?: (error?: Error) => void): Promise<void> {
35-
return new Promise(resolve => resolve())
35+
return Promise.resolve()
3636
}
3737
}

packages/datafile-manager/src/persistentKeyValueCache.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,39 @@ export default interface PersistentKeyValueCache {
2323
/**
2424
* Returns value stored against a key or null if not found.
2525
* @param key
26-
* @returns Promise which resolves with a
26+
* @returns
27+
* Resolves promise with
2728
* 1. Object if value found was stored as a JSON Object.
2829
* 2. null if the key does not exist in the cache.
30+
* Rejects the promise in case of an error
2931
*/
30-
get(key: string): Promise<Object | null>
32+
get(key: string): Promise<any | null>
3133

3234
/**
3335
* Stores Object in the persistent cache against a key
3436
* @param key
3537
* @param val
38+
* @returns
39+
* Resolves promise without a value if successful
40+
* Rejects the promise in case of an error
3641
*/
37-
set(key: string, val: Object): Promise<void>
42+
set(key: string, val: any): Promise<void>
3843

3944
/**
4045
* Checks if a key exists in the cache
41-
* @param key
46+
* @param key
47+
* Resolves promise with
48+
* 1. true if the key exists
49+
* 2. false if the key does not exist
50+
* Rejects the promise in case of an error
4251
*/
4352
contains(key: string): Promise<Boolean>
4453

4554
/**
46-
* Removed the key value pair from cache.
47-
* @param key
55+
* Removes the key value pair from cache.
56+
* @param key
57+
* Resolves promise without a value if successful
58+
* Rejects the promise in case of an error
4859
*/
4960
remove(key: string): Promise<void>
5061
}

packages/datafile-manager/src/reactNativeAsyncStorageCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const logger = getLogger('DatafileManager')
2323

2424
export default class ReactNativeAsyncStorageCache implements PersistentKeyValueCache {
2525

26-
get(key: string): Promise<Object | null> {
26+
get(key: string): Promise<any | null> {
2727
try {
2828
return AsyncStorage.getItem(key)
2929
.then((val: string | null) => val ? JSON.parse(val) : null)
@@ -33,7 +33,7 @@ export default class ReactNativeAsyncStorageCache implements PersistentKeyValueC
3333
}
3434
}
3535

36-
set(key: string, val: Object): Promise<void> {
36+
set(key: string, val: any): Promise<void> {
3737
try {
3838
return AsyncStorage.setItem(key, JSON.stringify(val))
3939
} catch (e) {

0 commit comments

Comments
 (0)