@umituz/react-native-storage 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -62,9 +62,9 @@ export {
|
|
|
62
62
|
} from './infrastructure/repositories/AsyncStorageRepository';
|
|
63
63
|
|
|
64
64
|
export {
|
|
65
|
-
|
|
65
|
+
storageService,
|
|
66
66
|
type StateStorage,
|
|
67
|
-
} from './infrastructure/adapters/
|
|
67
|
+
} from './infrastructure/adapters/StorageService';
|
|
68
68
|
|
|
69
69
|
// =============================================================================
|
|
70
70
|
// PRESENTATION LAYER - Hooks
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Storage Service
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Zustand persist middleware compatible StateStorage implementation.
|
|
5
5
|
* Uses AsyncStorage under the hood for React Native persistence.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Zustand
|
|
12
|
-
* Compatible with zustand/middleware persist
|
|
11
|
+
* StateStorage interface for Zustand persist middleware
|
|
13
12
|
*/
|
|
14
13
|
export interface StateStorage {
|
|
15
14
|
getItem: (name: string) => string | null | Promise<string | null>;
|
|
@@ -18,10 +17,10 @@ export interface StateStorage {
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* Zustand
|
|
22
|
-
* Direct AsyncStorage implementation
|
|
20
|
+
* Storage service for Zustand persist middleware
|
|
21
|
+
* Direct AsyncStorage implementation
|
|
23
22
|
*/
|
|
24
|
-
export const
|
|
23
|
+
export const storageService: StateStorage = {
|
|
25
24
|
getItem: async (name: string): Promise<string | null> => {
|
|
26
25
|
try {
|
|
27
26
|
return await AsyncStorage.getItem(name);
|
|
@@ -34,7 +33,7 @@ export const zustandStorage: StateStorage = {
|
|
|
34
33
|
try {
|
|
35
34
|
await AsyncStorage.setItem(name, value);
|
|
36
35
|
} catch {
|
|
37
|
-
// Silent fail
|
|
36
|
+
// Silent fail
|
|
38
37
|
}
|
|
39
38
|
},
|
|
40
39
|
|