File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 17
17
| [ ` localForage ` ] ( https://github.com/localForage/localForage ) | web | ` LocalForageWrapper ` |
18
18
| [ ` Ionic storage ` ] ( https://ionicframework.com/docs/building/storage ) | web and mobile | ` IonicStorageWrapper ` |
19
19
| [ ` MMKV Storage ` ] ( https://github.com/ammarahm-ed/react-native-mmkv-storage ) | React Native | ` MMKVStorageWrapper ` |
20
+ | [ ` MMKV ` ] ( https://github.com/mrousavy/react-native-mmkv ) | React Native | ` MMKVWrapper ` |
20
21
21
22
22
23
## Redux Persist Providers
Original file line number Diff line number Diff line change
1
+ import { PersistentStorage } from '../types' ;
2
+
3
+ /**
4
+ * Wrapper for react-native-mmkv.
5
+ * See [https://github.com/mrousavy/react-native-mmkv](https://github.com/mrousavy/react-native-mmkv) for installation instructions.
6
+ *
7
+ * @example
8
+ * const storage = new MMKV();
9
+ * const persistor = new CachePersistor({
10
+ * cache,
11
+ * storage: new MMKVWrapper(storage),
12
+ * });
13
+ *
14
+ */
15
+ export class MMKVWrapper implements PersistentStorage < string | null > {
16
+ private storage ;
17
+
18
+ constructor ( storage : MMKVInterface ) {
19
+ this . storage = storage ;
20
+ }
21
+
22
+ getItem ( key : string ) : string | null {
23
+ return this . storage . getString ( key ) || null ;
24
+ }
25
+
26
+ removeItem ( key : string ) : void {
27
+ return this . storage . delete ( key ) ;
28
+ }
29
+
30
+ setItem ( key : string , value : string | null ) : void {
31
+ if ( value !== null ) {
32
+ return this . storage . set ( key , value ) ;
33
+ }
34
+ return this . removeItem ( key ) ;
35
+ }
36
+ }
37
+
38
+ interface MMKVInterface {
39
+ set : ( key : string , value : boolean | string | number ) => void ;
40
+ getBoolean : ( key : string ) => boolean ;
41
+ getString : ( key : string ) => string | undefined ;
42
+ getNumber : ( key : string ) => number ;
43
+ delete : ( key : string ) => void ;
44
+ getAllKeys : ( ) => string [ ] ;
45
+ clearAll : ( ) => void ;
46
+ }
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ export * from './IonicStorageWrapper';
3
3
export * from './LocalForageWrapper' ;
4
4
export * from './LocalStorageWrapper' ;
5
5
export * from './MMKVStorageWrapper' ;
6
+ export * from './MMKVWrapper' ;
6
7
export * from './SessionStorageWrapper' ;
You can’t perform that action at this time.
0 commit comments