Skip to content

Commit ec0c060

Browse files
authored
Merge pull request #150 from ospfranco/mmkv
Use MMKV instead of async storage
2 parents cf5d8a5 + 0b43d17 commit ec0c060

File tree

7 files changed

+89
-17
lines changed

7 files changed

+89
-17
lines changed

macos/Podfile.lock

+41-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PODS:
88
- hermes-engine/Pre-built (= 0.76.6)
99
- hermes-engine/Pre-built (0.76.6)
1010
- HotKey (0.2.1)
11+
- MMKV (2.0.2):
12+
- MMKVCore (~> 2.0.2)
13+
- MMKVCore (2.0.2)
1114
- RCT-Folly (2024.01.01.00):
1215
- boost
1316
- DoubleConversion
@@ -1246,6 +1249,28 @@ PODS:
12461249
- Yoga
12471250
- react-native-get-random-values (1.11.0):
12481251
- React-Core
1252+
- react-native-mmkv (2.12.2):
1253+
- DoubleConversion
1254+
- glog
1255+
- hermes-engine
1256+
- MMKV (>= 1.3.3)
1257+
- RCT-Folly (= 2024.01.01.00)
1258+
- RCTRequired
1259+
- RCTTypeSafety
1260+
- React-Core
1261+
- React-debug
1262+
- React-Fabric
1263+
- React-featureflags
1264+
- React-graphics
1265+
- React-ImageManager
1266+
- React-NativeModulesApple
1267+
- React-RCTFabric
1268+
- React-rendererdebug
1269+
- React-utils
1270+
- ReactCodegen
1271+
- ReactCommon/turbomodule/bridging
1272+
- ReactCommon/turbomodule/core
1273+
- Yoga
12491274
- React-nativeconfig (0.76.6)
12501275
- React-NativeModulesApple (0.76.6):
12511276
- glog
@@ -1515,7 +1540,7 @@ PODS:
15151540
- React-utils (= 0.76.6)
15161541
- RNCAsyncStorage (1.24.0):
15171542
- React-Core
1518-
- RNReanimated (3.16.6):
1543+
- RNReanimated (3.16.7):
15191544
- DoubleConversion
15201545
- glog
15211546
- hermes-engine
@@ -1535,10 +1560,10 @@ PODS:
15351560
- ReactCodegen
15361561
- ReactCommon/turbomodule/bridging
15371562
- ReactCommon/turbomodule/core
1538-
- RNReanimated/reanimated (= 3.16.6)
1539-
- RNReanimated/worklets (= 3.16.6)
1563+
- RNReanimated/reanimated (= 3.16.7)
1564+
- RNReanimated/worklets (= 3.16.7)
15401565
- Yoga
1541-
- RNReanimated/reanimated (3.16.6):
1566+
- RNReanimated/reanimated (3.16.7):
15421567
- DoubleConversion
15431568
- glog
15441569
- hermes-engine
@@ -1558,9 +1583,9 @@ PODS:
15581583
- ReactCodegen
15591584
- ReactCommon/turbomodule/bridging
15601585
- ReactCommon/turbomodule/core
1561-
- RNReanimated/reanimated/apple (= 3.16.6)
1586+
- RNReanimated/reanimated/apple (= 3.16.7)
15621587
- Yoga
1563-
- RNReanimated/reanimated/apple (3.16.6):
1588+
- RNReanimated/reanimated/apple (3.16.7):
15641589
- DoubleConversion
15651590
- glog
15661591
- hermes-engine
@@ -1581,7 +1606,7 @@ PODS:
15811606
- ReactCommon/turbomodule/bridging
15821607
- ReactCommon/turbomodule/core
15831608
- Yoga
1584-
- RNReanimated/worklets (3.16.6):
1609+
- RNReanimated/worklets (3.16.7):
15851610
- DoubleConversion
15861611
- glog
15871612
- hermes-engine
@@ -1670,6 +1695,7 @@ DEPENDENCIES:
16701695
- React-Mapbuffer (from `../node_modules/react-native-macos/ReactCommon`)
16711696
- React-microtasksnativemodule (from `../node_modules/react-native-macos/ReactCommon/react/nativemodule/microtasks`)
16721697
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
1698+
- react-native-mmkv (from `../node_modules/react-native-mmkv`)
16731699
- React-nativeconfig (from `../node_modules/react-native-macos/ReactCommon`)
16741700
- React-NativeModulesApple (from `../node_modules/react-native-macos/ReactCommon/react/nativemodule/core/platform/ios`)
16751701
- React-perflogger (from `../node_modules/react-native-macos/ReactCommon/reactperflogger`)
@@ -1707,6 +1733,8 @@ DEPENDENCIES:
17071733
SPEC REPOS:
17081734
trunk:
17091735
- HotKey
1736+
- MMKV
1737+
- MMKVCore
17101738
- Sentry
17111739
- Sparkle
17121740

@@ -1784,6 +1812,8 @@ EXTERNAL SOURCES:
17841812
:path: "../node_modules/react-native-macos/ReactCommon/react/nativemodule/microtasks"
17851813
react-native-get-random-values:
17861814
:path: "../node_modules/react-native-get-random-values"
1815+
react-native-mmkv:
1816+
:path: "../node_modules/react-native-mmkv"
17871817
React-nativeconfig:
17881818
:path: "../node_modules/react-native-macos/ReactCommon"
17891819
React-NativeModulesApple:
@@ -1857,6 +1887,8 @@ SPEC CHECKSUMS:
18571887
glog: 750f96a379703a2d724d2f1fc6cb3a3eff000817
18581888
hermes-engine: 1949ca944b195a8bde7cbf6316b9068e19cf53c6
18591889
HotKey: 400beb7caa29054ea8d864c96f5ba7e5b4852277
1890+
MMKV: 3eacda84cd1c4fc95cf848d3ecb69d85ed56006c
1891+
MMKVCore: 508b4d3a8ce031f1b5c8bd235f0517fb3f4c73a9
18601892
RCT-Folly: 38dded4465d7da30a12a3087110693a6799091d4
18611893
RCTDeprecation: 063fc281b30b7dc944c98fe53a7e266dab1a8706
18621894
RCTRequired: 74d3e5dbded3e4e62113ef04f5534b5aebe0f619
@@ -1887,6 +1919,7 @@ SPEC CHECKSUMS:
18871919
React-Mapbuffer: 54c6c6ef2f1aa1325437d7ff9b98d4d9074bc20c
18881920
React-microtasksnativemodule: 21e9f7479e65e2244302cb89872e17b0ada3be7e
18891921
react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbba
1922+
react-native-mmkv: f84bf6f48c906911695f9cd16d39d4fb78fcd5a4
18901923
React-nativeconfig: f751aaeabc49b11e5a0dae4c0e1a709ab55c128c
18911924
React-NativeModulesApple: 624a15426130c68d4097088bc6950ef6ff8668ba
18921925
React-perflogger: 2db18ff24632e5ab5093e4f7f6b61ed830c9f17b
@@ -1915,7 +1948,7 @@ SPEC CHECKSUMS:
19151948
ReactCodegen: 489a96e05e7564c2bf0363be8319c07e762a3f4d
19161949
ReactCommon: a7a5981602782da52c9573e845c485dae2b37521
19171950
RNCAsyncStorage: b6410dead2732b5c72a7fdb1ecb5651bbcf4674b
1918-
RNReanimated: 2f762cd9e6b74c1f6ec88c0545d773a68b8e1085
1951+
RNReanimated: 66cf0f600a26d2b5e74c6e0b1c77c1ab1f62fc05
19191952
RNSentry: b1d9f61f725d3aba2ce943bfea23ac74b860ee89
19201953
Sentry: ee060c09b2f7ec1240e95c766ab44c04c7bdb052
19211954
SocketRocket: 03f7111df1a343b162bf5b06ead333be808e1e0a

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"react": "18.3.1",
4040
"react-native": "^0.76.6",
4141
"react-native-get-random-values": "^1.8.0",
42+
"react-native-mmkv": "2.12.2",
4243
"react-native-macos": "^0.76.6",
4344
"react-native-reanimated": "^3.8.1",
4445
"uuid": "^9.0.0"

src/stores/clipboard.store.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {EmitterSubscription} from 'react-native'
55
import {IRootStore} from 'store'
66
import {Widget} from './ui.store'
77
import MiniSearch from 'minisearch'
8+
import {storage} from './storage'
89

910
const MAX_ITEMS = 1000
1011

@@ -85,7 +86,16 @@ export const createClipboardStore = (root: IRootStore) => {
8586
onCopyListener = solNative.addListener('onTextCopied', store.onTextCopied)
8687

8788
const hydrate = async () => {
88-
const state = await AsyncStorage.getItem('@clipboard.store')
89+
let state: string | null | undefined
90+
try {
91+
state = storage.getString('@clipboard.store')
92+
} catch {
93+
// intentionally left blank
94+
}
95+
if (!state) {
96+
state = await AsyncStorage.getItem('@clipboard.store')
97+
}
98+
8999
if (state) {
90100
const parsedStore = JSON.parse(state)
91101
store.saveHistory = parsedStore.saveHistory

src/stores/emoji.store.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {IRootStore} from 'store'
44
import {emojis as rawEmojis_} from '../lib/emojis'
55
import {solNative} from 'lib/SolNative'
66
import MiniSearch from 'minisearch'
7+
import {storage} from './storage'
78

89
let rawEmojis = rawEmojis_.map((emoji: any, idx) => ({id: idx, ...emoji}))
910

@@ -55,7 +56,15 @@ export const createEmojiStore = (root: IRootStore) => {
5556
}
5657

5758
let hydrate = async () => {
58-
const storeState = await AsyncStorage.getItem('@emoji.store')
59+
let storeState: string | null | undefined
60+
try {
61+
storeState = storage.getString('@emoji.store')
62+
} catch {
63+
// intentionally left blank
64+
}
65+
if (!storeState) {
66+
storeState = await AsyncStorage.getItem('@emoji.store')
67+
}
5968

6069
if (storeState) {
6170
let parsedStore = JSON.parse(storeState)

src/stores/storage.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {MMKV} from 'react-native-mmkv'
2+
3+
export const storage = new MMKV()

src/stores/ui.store.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {createBaseItems} from './items'
1313
import plist from '@expo/plist'
1414
import MiniSearch from 'minisearch'
1515
import * as Sentry from '@sentry/react-native'
16+
import {storage} from './storage'
1617
import {defaultShortcuts, validShortcutTokensRegex} from 'lib/shorcuts'
1718

1819
const exprParser = new Parser()
@@ -138,17 +139,22 @@ export const createUIStore = (root: IRootStore) => {
138139
let persist = async () => {
139140
let plainState = toJS(store)
140141
try {
141-
await AsyncStorage.setItem('@ui.store', JSON.stringify(plainState))
142-
} catch (error) {
143-
await AsyncStorage.clear()
144-
await AsyncStorage.setItem('@ui.store', JSON.stringify(plainState)).catch(
145-
e => console.warn('Could re-persist persist ui store', e),
146-
)
142+
storage.set('@ui.store', JSON.stringify(plainState))
143+
} catch (e) {
144+
Sentry.captureException(e)
147145
}
148146
}
149147

150148
let hydrate = async () => {
151-
const storeState = await AsyncStorage.getItem('@ui.store')
149+
let storeState: string | null | undefined
150+
try {
151+
storeState = storage.getString('@ui.store')
152+
} catch {
153+
// intentionally left blank
154+
}
155+
if (!storeState) {
156+
storeState = await AsyncStorage.getItem('@ui.store')
157+
}
152158

153159
if (storeState) {
154160
let parsedStore = JSON.parse(storeState)

0 commit comments

Comments
 (0)