react-native-mmkv 3.0.0-beta.3 → 3.0.0-beta.5
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/cpp/MmkvHostObject.cpp +34 -46
- package/lib/commonjs/MMKV.js +0 -13
- package/lib/commonjs/MMKV.js.map +1 -1
- package/lib/commonjs/ModuleNotFoundError.js +75 -0
- package/lib/commonjs/ModuleNotFoundError.js.map +1 -0
- package/lib/commonjs/NativeMmkv.js +21 -14
- package/lib/commonjs/NativeMmkv.js.map +1 -1
- package/lib/commonjs/NativeMmkvPlatformContext.js +14 -5
- package/lib/commonjs/NativeMmkvPlatformContext.js.map +1 -1
- package/lib/commonjs/createMMKV.js +2 -1
- package/lib/commonjs/createMMKV.js.map +1 -1
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +0 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MMKV.js +0 -1
- package/lib/module/MMKV.js.map +1 -1
- package/lib/module/ModuleNotFoundError.js +68 -0
- package/lib/module/ModuleNotFoundError.js.map +1 -0
- package/lib/module/NativeMmkv.js +20 -14
- package/lib/module/NativeMmkv.js.map +1 -1
- package/lib/module/NativeMmkvPlatformContext.js +13 -4
- package/lib/module/NativeMmkvPlatformContext.js.map +1 -1
- package/lib/module/createMMKV.js +3 -2
- package/lib/module/createMMKV.js.map +1 -1
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/MMKV.d.ts +3 -3
- package/lib/typescript/src/MMKV.d.ts.map +1 -1
- package/lib/typescript/src/ModuleNotFoundError.d.ts +7 -0
- package/lib/typescript/src/ModuleNotFoundError.d.ts.map +1 -0
- package/lib/typescript/src/NativeMmkv.d.ts +3 -3
- package/lib/typescript/src/NativeMmkv.d.ts.map +1 -1
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +2 -2
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +1 -1
- package/lib/typescript/src/createMMKV.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +2 -1
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +3 -21
- package/react-native.config.js +1 -1
- package/src/MMKV.ts +3 -3
- package/src/ModuleNotFoundError.ts +95 -0
- package/src/NativeMmkv.ts +21 -17
- package/src/NativeMmkvPlatformContext.ts +16 -5
- package/src/createMMKV.ts +4 -2
- package/src/hooks.ts +2 -1
- package/src/index.ts +1 -1
- package/LICENSE +0 -20
- package/README.md +0 -282
- package/lib/commonjs/LazyTurboModule.js +0 -66
- package/lib/commonjs/LazyTurboModule.js.map +0 -1
- package/lib/module/LazyTurboModule.js +0 -60
- package/lib/module/LazyTurboModule.js.map +0 -1
- package/lib/typescript/src/LazyTurboModule.d.ts +0 -9
- package/lib/typescript/src/LazyTurboModule.d.ts.map +0 -1
- package/src/LazyTurboModule.ts +0 -98
package/README.md
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
<a href="https://margelo.io">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="./img/banner-dark.png" />
|
|
4
|
-
<source media="(prefers-color-scheme: light)" srcset="./img/banner-light.png" />
|
|
5
|
-
<img alt="VisionCamera" src="./img/banner-light.png" />
|
|
6
|
-
</picture>
|
|
7
|
-
</a>
|
|
8
|
-
|
|
9
|
-
<div align="center">
|
|
10
|
-
<h1 align="center">MMKV</h1>
|
|
11
|
-
<h3 align="center">The fastest key/value storage for React Native.</h3>
|
|
12
|
-
</div>
|
|
13
|
-
|
|
14
|
-
<div align="center">
|
|
15
|
-
<a align="center" href="https://github.com/mrousavy?tab=followers">
|
|
16
|
-
<img src="https://img.shields.io/github/followers/mrousavy?label=Follow%20%40mrousavy&style=social" />
|
|
17
|
-
</a>
|
|
18
|
-
<br/>
|
|
19
|
-
<a align="center" href="https://twitter.com/mrousavy">
|
|
20
|
-
<img src="https://img.shields.io/twitter/follow/mrousavy?label=Follow%20%40mrousavy&style=social" />
|
|
21
|
-
</a>
|
|
22
|
-
<br />
|
|
23
|
-
<a href="https://github.com/sponsors/mrousavy">
|
|
24
|
-
<img align="right" width="160" alt="This library helped you? Consider sponsoring!" src=".github/funding-octocat.svg">
|
|
25
|
-
</a>
|
|
26
|
-
</div>
|
|
27
|
-
<br/>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* **MMKV** is an efficient, small mobile key-value storage framework developed by WeChat. See [Tencent/MMKV](https://github.com/Tencent/MMKV) for more information
|
|
31
|
-
* **react-native-mmkv** is a library that allows you to easily use **MMKV** inside your React Native applications. It provides fast and direct bindings to the native C++ library which are accessible through a simple JS API.
|
|
32
|
-
|
|
33
|
-
## Features
|
|
34
|
-
|
|
35
|
-
* **Get** and **set** strings, booleans, numbers and ArrayBuffers
|
|
36
|
-
* **Fully synchronous** calls, no async/await, no Promises, no Bridge.
|
|
37
|
-
* **Encryption** support (secure storage)
|
|
38
|
-
* **Multiple instances** support (separate user-data with global data)
|
|
39
|
-
* **Customize storage location**
|
|
40
|
-
* **High performance** because everything is **written in C++**
|
|
41
|
-
* **~30x faster than AsyncStorage**
|
|
42
|
-
* Uses [**JSI**](https://reactnative.dev/docs/the-new-architecture/landing-page#fast-javascriptnative-interfacing) and [**C++ TurboModules**](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules-xplat.md) instead of the "old" Bridge
|
|
43
|
-
* **iOS**, **Android** and **Web** support
|
|
44
|
-
* Easy to use **React Hooks** API
|
|
45
|
-
|
|
46
|
-
## react-native-mmkv V3
|
|
47
|
-
|
|
48
|
-
> [!IMPORTANT]
|
|
49
|
-
> react-native-mmkv V3 is now a pure C++ TurboModule, and **requires the new architecture to be enabled**.
|
|
50
|
-
> - If you want to use react-native-mmkv 3.x.x, you need to enable the new architecture in your app (see ["Enable the New Architecture for Apps"](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md))
|
|
51
|
-
> - If you cannot use the new architecture yet, downgrade to react-native-mmkv 2.x.x for now.
|
|
52
|
-
|
|
53
|
-
## Sponsors
|
|
54
|
-
|
|
55
|
-
<div align="right">
|
|
56
|
-
<a href="https://getstream.io/chat/react-native-chat/tutorial/?utm_source=Github&utm_medium=Github_Repo_Content_Ad&utm_content=Developer&utm_campaign=Github_Jan2022_ReactNative&utm_term=react-native-mmkv">
|
|
57
|
-
<img align="right" src="https://theme.zdassets.com/theme_assets/9442057/efc3820e436f9150bc8cf34267fff4df052a1f9c.png" height="40" />
|
|
58
|
-
</a>
|
|
59
|
-
</div>
|
|
60
|
-
|
|
61
|
-
react-native-mmkv is sponsored by **getstream.io**. <br/>
|
|
62
|
-
[Try the React Native Chat tutorial 💬](https://getstream.io/chat/react-native-chat/tutorial/?utm_source=Github&utm_medium=Github_Repo_Content_Ad&utm_content=Developer&utm_campaign=Github_Jan2022_ReactNative&utm_term=react-native-mmkv)
|
|
63
|
-
|
|
64
|
-
## Benchmark
|
|
65
|
-
|
|
66
|
-
[StorageBenchmark](https://github.com/mrousavy/StorageBenchmark) compares popular storage libraries against each other by reading a value from storage for 1000 times:
|
|
67
|
-
|
|
68
|
-
<div align="center">
|
|
69
|
-
<a href="https://github.com/mrousavy/StorageBenchmark">
|
|
70
|
-
<img src="./img/benchmark_1000_get.png" />
|
|
71
|
-
</a>
|
|
72
|
-
<p>
|
|
73
|
-
<b>MMKV vs other storage libraries</b>: Reading a value from Storage 1000 times. <br/>
|
|
74
|
-
Measured in milliseconds on an iPhone 11 Pro, lower is better. <br/>
|
|
75
|
-
</p>
|
|
76
|
-
</div>
|
|
77
|
-
|
|
78
|
-
## Installation
|
|
79
|
-
|
|
80
|
-
### React Native
|
|
81
|
-
|
|
82
|
-
```sh
|
|
83
|
-
yarn add react-native-mmkv
|
|
84
|
-
cd ios && pod install
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Expo
|
|
88
|
-
|
|
89
|
-
```sh
|
|
90
|
-
npx expo install react-native-mmkv
|
|
91
|
-
npx expo prebuild
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Usage
|
|
95
|
-
|
|
96
|
-
### Create a new instance
|
|
97
|
-
|
|
98
|
-
To create a new instance of the MMKV storage, use the `MMKV` constructor. It is recommended that you re-use this instance throughout your entire app instead of creating a new instance each time, so `export` the `storage` object.
|
|
99
|
-
|
|
100
|
-
#### Default
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
import { MMKV } from 'react-native-mmkv'
|
|
104
|
-
|
|
105
|
-
export const storage = new MMKV()
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
This creates a new storage instance using the default MMKV storage ID (`mmkv.default`).
|
|
109
|
-
|
|
110
|
-
#### App Groups or Extensions
|
|
111
|
-
|
|
112
|
-
If you want to share MMKV data between your app and other apps or app extensions in the same group, open `Info.plist` and create an `AppGroup` key with your app group's value. MMKV will then automatically store data inside the app group which can be read and written to from other apps or app extensions in the same group by making use of MMKV's multi processing mode.
|
|
113
|
-
See [Configuring App Groups](https://developer.apple.com/documentation/xcode/configuring-app-groups).
|
|
114
|
-
|
|
115
|
-
#### Customize
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
import { MMKV, Mode } from 'react-native-mmkv'
|
|
119
|
-
|
|
120
|
-
export const storage = new MMKV({
|
|
121
|
-
id: `user-${userId}-storage`,
|
|
122
|
-
path: `${USER_DIRECTORY}/storage`,
|
|
123
|
-
encryptionKey: 'hunter2',
|
|
124
|
-
mode: Mode.MULTI_PROCESS
|
|
125
|
-
})
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
This creates a new storage instance using a custom MMKV storage ID. By using a custom storage ID, your storage is separated from the default MMKV storage of your app.
|
|
129
|
-
|
|
130
|
-
The following values can be configured:
|
|
131
|
-
|
|
132
|
-
* `id`: The MMKV instance's ID. If you want to use multiple instances, use different IDs. For example, you can separate the global app's storage and a logged-in user's storage. (required if `path` or `encryptionKey` fields are specified, otherwise defaults to: `'mmkv.default'`)
|
|
133
|
-
* `path`: The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization (documentation: [iOS](https://github.com/Tencent/MMKV/wiki/iOS_advance#customize-location) / [Android](https://github.com/Tencent/MMKV/wiki/android_advance#customize-location))
|
|
134
|
-
* `encryptionKey`: The MMKV instance's encryption/decryption key. By default, MMKV stores all key-values in plain text on file, relying on iOS's/Android's sandbox to make sure the file is encrypted. Should you worry about information leaking, you can choose to encrypt MMKV. (documentation: [iOS](https://github.com/Tencent/MMKV/wiki/iOS_advance#encryption) / [Android](https://github.com/Tencent/MMKV/wiki/android_advance#encryption))
|
|
135
|
-
* `mode`: The MMKV's process behaviour - when set to `MULTI_PROCESS`, the MMKV instance will assume data can be changed from the outside (e.g. App Clips, Extensions or App Groups).
|
|
136
|
-
|
|
137
|
-
### Set
|
|
138
|
-
|
|
139
|
-
```js
|
|
140
|
-
storage.set('user.name', 'Marc')
|
|
141
|
-
storage.set('user.age', 21)
|
|
142
|
-
storage.set('is-mmkv-fast-asf', true)
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### Get
|
|
146
|
-
|
|
147
|
-
```js
|
|
148
|
-
const username = storage.getString('user.name') // 'Marc'
|
|
149
|
-
const age = storage.getNumber('user.age') // 21
|
|
150
|
-
const isMmkvFastAsf = storage.getBoolean('is-mmkv-fast-asf') // true
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Hooks
|
|
154
|
-
|
|
155
|
-
```js
|
|
156
|
-
const [username, setUsername] = useMMKVString('user.name')
|
|
157
|
-
const [age, setAge] = useMMKVNumber('user.age')
|
|
158
|
-
const [isMmkvFastAsf, setIsMmkvFastAf] = useMMKVBoolean('is-mmkv-fast-asf')
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Keys
|
|
162
|
-
|
|
163
|
-
```js
|
|
164
|
-
// checking if a specific key exists
|
|
165
|
-
const hasUsername = storage.contains('user.name')
|
|
166
|
-
|
|
167
|
-
// getting all keys
|
|
168
|
-
const keys = storage.getAllKeys() // ['user.name', 'user.age', 'is-mmkv-fast-asf']
|
|
169
|
-
|
|
170
|
-
// delete a specific key + value
|
|
171
|
-
storage.delete('user.name')
|
|
172
|
-
|
|
173
|
-
// delete all keys
|
|
174
|
-
storage.clearAll()
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### Objects
|
|
178
|
-
|
|
179
|
-
```js
|
|
180
|
-
const user = {
|
|
181
|
-
username: 'Marc',
|
|
182
|
-
age: 21
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Serialize the object into a JSON string
|
|
186
|
-
storage.set('user', JSON.stringify(user))
|
|
187
|
-
|
|
188
|
-
// Deserialize the JSON string into an object
|
|
189
|
-
const jsonUser = storage.getString('user') // { 'username': 'Marc', 'age': 21 }
|
|
190
|
-
const userObject = JSON.parse(jsonUser)
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Encryption
|
|
194
|
-
|
|
195
|
-
```js
|
|
196
|
-
// encrypt all data with a private key
|
|
197
|
-
storage.recrypt('hunter2')
|
|
198
|
-
|
|
199
|
-
// remove encryption
|
|
200
|
-
storage.recrypt(undefined)
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Buffers
|
|
204
|
-
|
|
205
|
-
```js
|
|
206
|
-
const buffer = new ArrayBuffer(3)
|
|
207
|
-
const dataWriter = new Uint8Array(buffer)
|
|
208
|
-
dataWriter[0] = 1
|
|
209
|
-
dataWriter[1] = 100
|
|
210
|
-
dataWriter[2] = 255
|
|
211
|
-
storage.set('someToken', buffer)
|
|
212
|
-
|
|
213
|
-
const buffer = storage.getBuffer('someToken')
|
|
214
|
-
console.log(buffer) // [1, 100, 255]
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Size
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
// get size of MMKV storage in bytes
|
|
221
|
-
const size = storage.size
|
|
222
|
-
if (size >= 4096) {
|
|
223
|
-
// clean unused keys and clear memory cache
|
|
224
|
-
storage.trim()
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
## Testing with Jest or Vitest
|
|
229
|
-
|
|
230
|
-
A mocked MMKV instance is automatically used when testing with Jest or Vitest, so you will be able to use `new MMKV()` as per normal in your tests. Refer to [example/test/MMKV.test.ts](example/test/MMKV.test.ts) for an example using Jest.
|
|
231
|
-
|
|
232
|
-
## Documentation
|
|
233
|
-
|
|
234
|
-
* [Hooks](./docs/HOOKS.md)
|
|
235
|
-
* [Value-change Listeners](./docs/LISTENERS.md)
|
|
236
|
-
* [Migrate from AsyncStorage](./docs/MIGRATE_FROM_ASYNC_STORAGE.md)
|
|
237
|
-
* [Using MMKV with redux-persist](./docs/WRAPPER_REDUX.md)
|
|
238
|
-
* [Using MMKV with recoil](./docs/WRAPPER_RECOIL.md)
|
|
239
|
-
* [Using MMKV with mobx-persist-storage](./docs/WRAPPER_MOBX.md)
|
|
240
|
-
* [Using MMKV with mobx-persist](./docs/WRAPPER_MOBXPERSIST.md)
|
|
241
|
-
* [Using MMKV with zustand persist-middleware](./docs/WRAPPER_ZUSTAND_PERSIST_MIDDLEWARE.md)
|
|
242
|
-
* [Using MMKV with jotai](./docs/WRAPPER_JOTAI.md)
|
|
243
|
-
* [Using MMKV with react-query](./docs/WRAPPER_REACT_QUERY.md)
|
|
244
|
-
* [How is this library different from **react-native-mmkv-storage**?](https://github.com/mrousavy/react-native-mmkv/issues/100#issuecomment-886477361)
|
|
245
|
-
|
|
246
|
-
## LocalStorage and In-Memory Storage (Web)
|
|
247
|
-
|
|
248
|
-
If a user chooses to disable LocalStorage in their browser, the library will automatically provide a limited in-memory storage as an alternative. However, this in-memory storage won't persist data, and users may experience data loss if they refresh the page or close their browser. To optimize user experience, consider implementing a suitable solution within your app to address this scenario.
|
|
249
|
-
|
|
250
|
-
## Limitations
|
|
251
|
-
|
|
252
|
-
- react-native-mmkv V3 requires react-native 0.74 or higher.
|
|
253
|
-
- react-native-mmkv V3 requires [the new architecture](https://reactnative.dev/docs/the-new-architecture/landing-page)/TurboModules to be enabled.
|
|
254
|
-
- Since react-native-mmkv uses JSI for synchronous native method invocations, remote debugging (e.g. with Chrome) is no longer possible. Instead, you should use [Flipper](https://fbflipper.com) or [React DevTools](https://react.dev/learn/react-developer-tools).
|
|
255
|
-
|
|
256
|
-
## Integrations
|
|
257
|
-
|
|
258
|
-
### Flipper
|
|
259
|
-
|
|
260
|
-
Use [flipper-plugin-react-native-mmkv](https://github.com/muchobien/flipper-plugin-react-native-mmkv) to debug your MMKV storage using Flipper. You can also simply `console.log` an MMKV instance.
|
|
261
|
-
|
|
262
|
-
### Reactotron
|
|
263
|
-
|
|
264
|
-
Use [reactotron-react-native-mmkv](https://www.npmjs.com/package/reactotron-react-native-mmkv) to automatically log writes to your MMKV storage using Reactotron. [See the docs for how to setup this plugin with Reactotron.](https://www.npmjs.com/package/reactotron-react-native-mmkv)
|
|
265
|
-
|
|
266
|
-
## Community Discord
|
|
267
|
-
|
|
268
|
-
[**Join the Margelo Community Discord**](https://discord.gg/6CSHz2qAvA) to chat about react-native-mmkv or other Margelo libraries.
|
|
269
|
-
|
|
270
|
-
## Adopting at scale
|
|
271
|
-
|
|
272
|
-
react-native-mmkv is provided _as is_, I work on it in my free time.
|
|
273
|
-
|
|
274
|
-
If you're integrating react-native-mmkv in a production app, consider [funding this project](https://github.com/sponsors/mrousavy) and <a href="mailto:me@mrousavy.com?subject=Adopting react-native-mmkv at scale">contact me</a> to receive premium enterprise support, help with issues, prioritize bugfixes, request features, help at integrating react-native-mmkv, and more.
|
|
275
|
-
|
|
276
|
-
## Contributing
|
|
277
|
-
|
|
278
|
-
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
279
|
-
|
|
280
|
-
## License
|
|
281
|
-
|
|
282
|
-
MIT
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getLazyTurboModule = getLazyTurboModule;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
const BULLET_POINT = '\n* ';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Lazily get a TurboModule by wrapping it in a Proxy.
|
|
12
|
-
*/
|
|
13
|
-
function getLazyTurboModule(initializeTurboModule) {
|
|
14
|
-
const proxy = new Proxy({
|
|
15
|
-
module: null
|
|
16
|
-
}, {
|
|
17
|
-
get: (target, property) => {
|
|
18
|
-
if (target.module == null) {
|
|
19
|
-
// Target is null, let's initialize it!
|
|
20
|
-
target.module = initializeTurboModule();
|
|
21
|
-
if (target.module == null) {
|
|
22
|
-
// TurboModule not found, something went wrong!
|
|
23
|
-
if (global.__turboModuleProxy == null) {
|
|
24
|
-
// TurboModules are not available/new arch is not enabled.
|
|
25
|
-
// react-native-mmkv 3.x.x requires new arch (react-native >0.74)
|
|
26
|
-
// react-native-mmkv 2.x.x works on old arch (react-native <0.74)
|
|
27
|
-
throw new Error('Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!' + BULLET_POINT + 'Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.' + BULLET_POINT + 'Enable the new architecture in your app to use react-native-mmkv 3.x.x. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
|
|
28
|
-
}
|
|
29
|
-
const message = 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
|
|
30
|
-
const suggestions = [];
|
|
31
|
-
suggestions.push('Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)');
|
|
32
|
-
suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
|
|
33
|
-
suggestions.push('Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.');
|
|
34
|
-
suggestions.push('Make sure you rebuilt the app.');
|
|
35
|
-
switch (_reactNative.Platform.OS) {
|
|
36
|
-
case 'ios':
|
|
37
|
-
case 'macos':
|
|
38
|
-
suggestions.push('Make sure you ran `pod install` in the ios/ directory.');
|
|
39
|
-
break;
|
|
40
|
-
case 'android':
|
|
41
|
-
suggestions.push('Make sure gradle is synced.');
|
|
42
|
-
break;
|
|
43
|
-
default:
|
|
44
|
-
throw new Error(`MMKV is not supported on ${_reactNative.Platform.OS}!`);
|
|
45
|
-
}
|
|
46
|
-
// check if Expo
|
|
47
|
-
const ExpoConstants = _reactNative.NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
|
|
48
|
-
if (ExpoConstants != null) {
|
|
49
|
-
if (ExpoConstants.appOwnership === 'expo') {
|
|
50
|
-
// We're running Expo Go
|
|
51
|
-
throw new Error('react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
|
|
52
|
-
} else {
|
|
53
|
-
// We're running Expo bare / standalone
|
|
54
|
-
suggestions.push('Make sure you ran `expo prebuild`.');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const error = message + BULLET_POINT + suggestions.join(BULLET_POINT);
|
|
58
|
-
throw new Error(error);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return target.module[property];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return proxy;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=LazyTurboModule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","BULLET_POINT","getLazyTurboModule","initializeTurboModule","proxy","Proxy","module","get","target","property","global","__turboModuleProxy","Error","message","suggestions","push","Platform","OS","ExpoConstants","NativeModules","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","error","join"],"sourceRoot":"../../src","sources":["LazyTurboModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAWA,MAAMC,YAAY,GAAG,MAAM;;AAE3B;AACA;AACA;AACO,SAASC,kBAAkBA,CAChCC,qBAAqC,EAClC;EACH,MAAMC,KAAK,GAAG,IAAIC,KAAK,CACrB;IACEC,MAAM,EAAE;EACV,CAAC,EACD;IACEC,GAAG,EAAEA,CAACC,MAAM,EAAEC,QAAQ,KAAK;MACzB,IAAID,MAAM,CAACF,MAAM,IAAI,IAAI,EAAE;QACzB;QACAE,MAAM,CAACF,MAAM,GAAGH,qBAAqB,CAAC,CAAC;QAEvC,IAAIK,MAAM,CAACF,MAAM,IAAI,IAAI,EAAE;UACzB;UACA,IAAII,MAAM,CAACC,kBAAkB,IAAI,IAAI,EAAE;YACrC;YACA;YACA;YACA,MAAM,IAAIC,KAAK,CACb,+HAA+H,GAC7HX,YAAY,GACZ,mFAAmF,GACnFA,YAAY,GACZ,sKACJ,CAAC;UACH;UAEA,MAAMY,OAAO,GACX,kFAAkF;UACpF,MAAMC,WAAqB,GAAG,EAAE;UAChCA,WAAW,CAACC,IAAI,CACd,+FACF,CAAC;UACDD,WAAW,CAACC,IAAI,CACd,kNACF,CAAC;UACDD,WAAW,CAACC,IAAI,CACd,wGACF,CAAC;UACDD,WAAW,CAACC,IAAI,CAAC,gCAAgC,CAAC;UAClD,QAAQC,qBAAQ,CAACC,EAAE;YACjB,KAAK,KAAK;YACV,KAAK,OAAO;cACVH,WAAW,CAACC,IAAI,CACd,wDACF,CAAC;cACD;YACF,KAAK,SAAS;cACZD,WAAW,CAACC,IAAI,CAAC,6BAA6B,CAAC;cAC/C;YACF;cACE,MAAM,IAAIH,KAAK,CAAE,4BAA2BI,qBAAQ,CAACC,EAAG,GAAE,CAAC;UAC/D;UACA;UACA,MAAMC,aAAa,GACjBC,0BAAa,CAACC,oBAAoB,EAAEC,gBAAgB,EAChDC,iBAAiB;UACvB,IAAIJ,aAAa,IAAI,IAAI,EAAE;YACzB,IAAIA,aAAa,CAACK,YAAY,KAAK,MAAM,EAAE;cACzC;cACA,MAAM,IAAIX,KAAK,CACb,+GACF,CAAC;YACH,CAAC,MAAM;cACL;cACAE,WAAW,CAACC,IAAI,CAAC,oCAAoC,CAAC;YACxD;UACF;UAEA,MAAMS,KAAK,GACTX,OAAO,GAAGZ,YAAY,GAAGa,WAAW,CAACW,IAAI,CAACxB,YAAY,CAAC;UACzD,MAAM,IAAIW,KAAK,CAACY,KAAK,CAAC;QACxB;MACF;MAEA,OAAOhB,MAAM,CAACF,MAAM,CAACG,QAAQ,CAAY;IAC3C;EACF,CACF,CAAC;EACD,OAAOL,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { NativeModules, Platform } from 'react-native';
|
|
2
|
-
const BULLET_POINT = '\n* ';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Lazily get a TurboModule by wrapping it in a Proxy.
|
|
6
|
-
*/
|
|
7
|
-
export function getLazyTurboModule(initializeTurboModule) {
|
|
8
|
-
const proxy = new Proxy({
|
|
9
|
-
module: null
|
|
10
|
-
}, {
|
|
11
|
-
get: (target, property) => {
|
|
12
|
-
if (target.module == null) {
|
|
13
|
-
// Target is null, let's initialize it!
|
|
14
|
-
target.module = initializeTurboModule();
|
|
15
|
-
if (target.module == null) {
|
|
16
|
-
// TurboModule not found, something went wrong!
|
|
17
|
-
if (global.__turboModuleProxy == null) {
|
|
18
|
-
// TurboModules are not available/new arch is not enabled.
|
|
19
|
-
// react-native-mmkv 3.x.x requires new arch (react-native >0.74)
|
|
20
|
-
// react-native-mmkv 2.x.x works on old arch (react-native <0.74)
|
|
21
|
-
throw new Error('Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!' + BULLET_POINT + 'Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.' + BULLET_POINT + 'Enable the new architecture in your app to use react-native-mmkv 3.x.x. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
|
|
22
|
-
}
|
|
23
|
-
const message = 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
|
|
24
|
-
const suggestions = [];
|
|
25
|
-
suggestions.push('Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)');
|
|
26
|
-
suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
|
|
27
|
-
suggestions.push('Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.');
|
|
28
|
-
suggestions.push('Make sure you rebuilt the app.');
|
|
29
|
-
switch (Platform.OS) {
|
|
30
|
-
case 'ios':
|
|
31
|
-
case 'macos':
|
|
32
|
-
suggestions.push('Make sure you ran `pod install` in the ios/ directory.');
|
|
33
|
-
break;
|
|
34
|
-
case 'android':
|
|
35
|
-
suggestions.push('Make sure gradle is synced.');
|
|
36
|
-
break;
|
|
37
|
-
default:
|
|
38
|
-
throw new Error(`MMKV is not supported on ${Platform.OS}!`);
|
|
39
|
-
}
|
|
40
|
-
// check if Expo
|
|
41
|
-
const ExpoConstants = NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
|
|
42
|
-
if (ExpoConstants != null) {
|
|
43
|
-
if (ExpoConstants.appOwnership === 'expo') {
|
|
44
|
-
// We're running Expo Go
|
|
45
|
-
throw new Error('react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
|
|
46
|
-
} else {
|
|
47
|
-
// We're running Expo bare / standalone
|
|
48
|
-
suggestions.push('Make sure you ran `expo prebuild`.');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const error = message + BULLET_POINT + suggestions.join(BULLET_POINT);
|
|
52
|
-
throw new Error(error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return target.module[property];
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return proxy;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=LazyTurboModule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","BULLET_POINT","getLazyTurboModule","initializeTurboModule","proxy","Proxy","module","get","target","property","global","__turboModuleProxy","Error","message","suggestions","push","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","error","join"],"sourceRoot":"../../src","sources":["LazyTurboModule.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAqB,cAAc;AAWnE,MAAMC,YAAY,GAAG,MAAM;;AAE3B;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAChCC,qBAAqC,EAClC;EACH,MAAMC,KAAK,GAAG,IAAIC,KAAK,CACrB;IACEC,MAAM,EAAE;EACV,CAAC,EACD;IACEC,GAAG,EAAEA,CAACC,MAAM,EAAEC,QAAQ,KAAK;MACzB,IAAID,MAAM,CAACF,MAAM,IAAI,IAAI,EAAE;QACzB;QACAE,MAAM,CAACF,MAAM,GAAGH,qBAAqB,CAAC,CAAC;QAEvC,IAAIK,MAAM,CAACF,MAAM,IAAI,IAAI,EAAE;UACzB;UACA,IAAII,MAAM,CAACC,kBAAkB,IAAI,IAAI,EAAE;YACrC;YACA;YACA;YACA,MAAM,IAAIC,KAAK,CACb,+HAA+H,GAC7HX,YAAY,GACZ,mFAAmF,GACnFA,YAAY,GACZ,sKACJ,CAAC;UACH;UAEA,MAAMY,OAAO,GACX,kFAAkF;UACpF,MAAMC,WAAqB,GAAG,EAAE;UAChCA,WAAW,CAACC,IAAI,CACd,+FACF,CAAC;UACDD,WAAW,CAACC,IAAI,CACd,kNACF,CAAC;UACDD,WAAW,CAACC,IAAI,CACd,wGACF,CAAC;UACDD,WAAW,CAACC,IAAI,CAAC,gCAAgC,CAAC;UAClD,QAAQf,QAAQ,CAACgB,EAAE;YACjB,KAAK,KAAK;YACV,KAAK,OAAO;cACVF,WAAW,CAACC,IAAI,CACd,wDACF,CAAC;cACD;YACF,KAAK,SAAS;cACZD,WAAW,CAACC,IAAI,CAAC,6BAA6B,CAAC;cAC/C;YACF;cACE,MAAM,IAAIH,KAAK,CAAE,4BAA2BZ,QAAQ,CAACgB,EAAG,GAAE,CAAC;UAC/D;UACA;UACA,MAAMC,aAAa,GACjBlB,aAAa,CAACmB,oBAAoB,EAAEC,gBAAgB,EAChDC,iBAAiB;UACvB,IAAIH,aAAa,IAAI,IAAI,EAAE;YACzB,IAAIA,aAAa,CAACI,YAAY,KAAK,MAAM,EAAE;cACzC;cACA,MAAM,IAAIT,KAAK,CACb,+GACF,CAAC;YACH,CAAC,MAAM;cACL;cACAE,WAAW,CAACC,IAAI,CAAC,oCAAoC,CAAC;YACxD;UACF;UAEA,MAAMO,KAAK,GACTT,OAAO,GAAGZ,YAAY,GAAGa,WAAW,CAACS,IAAI,CAACtB,YAAY,CAAC;UACzD,MAAM,IAAIW,KAAK,CAACU,KAAK,CAAC;QACxB;MACF;MAEA,OAAOd,MAAM,CAACF,MAAM,CAACG,QAAQ,CAAY;IAC3C;EACF,CACF,CAAC;EACD,OAAOL,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TurboModule } from 'react-native';
|
|
2
|
-
declare global {
|
|
3
|
-
var __turboModuleProxy: unknown | undefined;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Lazily get a TurboModule by wrapping it in a Proxy.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getLazyTurboModule<T extends TurboModule>(initializeTurboModule: () => T | null): T;
|
|
9
|
-
//# sourceMappingURL=LazyTurboModule.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LazyTurboModule.d.ts","sourceRoot":"","sources":["../../../src/LazyTurboModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AAQD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,WAAW,EACtD,qBAAqB,EAAE,MAAM,CAAC,GAAG,IAAI,GACpC,CAAC,CA+EH"}
|
package/src/LazyTurboModule.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { NativeModules, Platform, TurboModule } from 'react-native';
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
// A react-native internal from TurboModuleRegistry.js
|
|
5
|
-
var __turboModuleProxy: unknown | undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface ModuleHolder<T> {
|
|
9
|
-
module: T | null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const BULLET_POINT = '\n* ';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Lazily get a TurboModule by wrapping it in a Proxy.
|
|
16
|
-
*/
|
|
17
|
-
export function getLazyTurboModule<T extends TurboModule>(
|
|
18
|
-
initializeTurboModule: () => T | null
|
|
19
|
-
): T {
|
|
20
|
-
const proxy = new Proxy<ModuleHolder<T>>(
|
|
21
|
-
{
|
|
22
|
-
module: null,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
get: (target, property) => {
|
|
26
|
-
if (target.module == null) {
|
|
27
|
-
// Target is null, let's initialize it!
|
|
28
|
-
target.module = initializeTurboModule();
|
|
29
|
-
|
|
30
|
-
if (target.module == null) {
|
|
31
|
-
// TurboModule not found, something went wrong!
|
|
32
|
-
if (global.__turboModuleProxy == null) {
|
|
33
|
-
// TurboModules are not available/new arch is not enabled.
|
|
34
|
-
// react-native-mmkv 3.x.x requires new arch (react-native >0.74)
|
|
35
|
-
// react-native-mmkv 2.x.x works on old arch (react-native <0.74)
|
|
36
|
-
throw new Error(
|
|
37
|
-
'Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!' +
|
|
38
|
-
BULLET_POINT +
|
|
39
|
-
'Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.' +
|
|
40
|
-
BULLET_POINT +
|
|
41
|
-
'Enable the new architecture in your app to use react-native-mmkv 3.x.x. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)'
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const message =
|
|
46
|
-
'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
|
|
47
|
-
const suggestions: string[] = [];
|
|
48
|
-
suggestions.push(
|
|
49
|
-
'Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)'
|
|
50
|
-
);
|
|
51
|
-
suggestions.push(
|
|
52
|
-
'Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md'
|
|
53
|
-
);
|
|
54
|
-
suggestions.push(
|
|
55
|
-
'Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.'
|
|
56
|
-
);
|
|
57
|
-
suggestions.push('Make sure you rebuilt the app.');
|
|
58
|
-
switch (Platform.OS) {
|
|
59
|
-
case 'ios':
|
|
60
|
-
case 'macos':
|
|
61
|
-
suggestions.push(
|
|
62
|
-
'Make sure you ran `pod install` in the ios/ directory.'
|
|
63
|
-
);
|
|
64
|
-
break;
|
|
65
|
-
case 'android':
|
|
66
|
-
suggestions.push('Make sure gradle is synced.');
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
throw new Error(`MMKV is not supported on ${Platform.OS}!`);
|
|
70
|
-
}
|
|
71
|
-
// check if Expo
|
|
72
|
-
const ExpoConstants =
|
|
73
|
-
NativeModules.NativeUnimoduleProxy?.modulesConstants
|
|
74
|
-
?.ExponentConstants;
|
|
75
|
-
if (ExpoConstants != null) {
|
|
76
|
-
if (ExpoConstants.appOwnership === 'expo') {
|
|
77
|
-
// We're running Expo Go
|
|
78
|
-
throw new Error(
|
|
79
|
-
'react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'
|
|
80
|
-
);
|
|
81
|
-
} else {
|
|
82
|
-
// We're running Expo bare / standalone
|
|
83
|
-
suggestions.push('Make sure you ran `expo prebuild`.');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const error =
|
|
88
|
-
message + BULLET_POINT + suggestions.join(BULLET_POINT);
|
|
89
|
-
throw new Error(error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return target.module[property as keyof T];
|
|
94
|
-
},
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
return proxy as unknown as T;
|
|
98
|
-
}
|