react-native-mmkv 3.0.0-beta.4 → 3.0.0-beta.6
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/android/build.gradle +3 -0
- package/android/src/main/cpp/AndroidLogger.cpp +3 -3
- package/cpp/MmkvHostObject.cpp +38 -50
- package/cpp/{Logger.h → MmkvLogger.h} +3 -3
- package/cpp/NativeMmkvModule.cpp +2 -2
- package/ios/AppleLogger.mm +3 -3
- 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/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/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/package.json +5 -22
- package/react-native-mmkv.podspec +3 -0
- 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/LICENSE +0 -20
- package/MMKV/LICENSE.TXT +0 -193
- package/MMKV/README.md +0 -354
- 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/lib/module/MMKV.js
CHANGED
|
@@ -2,7 +2,6 @@ import { AppState } from 'react-native';
|
|
|
2
2
|
import { createMMKV } from './createMMKV';
|
|
3
3
|
import { createMockMMKV } from './createMMKV.mock';
|
|
4
4
|
import { isTest } from './PlatformChecker';
|
|
5
|
-
export { Configuration, Mode } from './NativeMmkv';
|
|
6
5
|
const onValueChangedListeners = new Map();
|
|
7
6
|
|
|
8
7
|
/**
|
package/lib/module/MMKV.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AppState","createMMKV","createMockMMKV","isTest","
|
|
1
|
+
{"version":3,"names":["AppState","createMMKV","createMockMMKV","isTest","onValueChangedListeners","Map","MMKV","constructor","configuration","id","nativeInstance","functionCache","addEventListener","trim","has","set","get","getFunctionFromCache","functionName","onValuesChanged","keys","length","key","listener","size","value","func","getBoolean","getString","getNumber","getBuffer","contains","delete","getAllKeys","clearAll","recrypt","toString","join","toJSON","addOnValueChangedListener","onValueChanged","push","remove","index","indexOf","splice"],"sourceRoot":"../../src","sources":["MMKV.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,MAAM,QAAQ,mBAAmB;AAK1C,MAAMC,uBAAuB,GAAG,IAAIC,GAAG,CAAoC,CAAC;;AAE5E;AACA;AACA;AACA,OAAO,MAAMC,IAAI,CAA0B;EAKzC;AACF;AACA;AACA;EACEC,WAAWA,CAACC,aAA4B,GAAG;IAAEC,EAAE,EAAE;EAAe,CAAC,EAAE;IACjE,IAAI,CAACA,EAAE,GAAGD,aAAa,CAACC,EAAE;IAC1B,IAAI,CAACC,cAAc,GAAGP,MAAM,CAAC,CAAC,GAC1BD,cAAc,CAAC,CAAC,GAChBD,UAAU,CAACO,aAAa,CAAC;IAC7B,IAAI,CAACG,aAAa,GAAG,CAAC,CAAC;IAEvBX,QAAQ,CAACY,gBAAgB,CAAC,eAAe,EAAE,MAAM;MAC/C;MACA,IAAI,CAACC,IAAI,CAAC,CAAC;IACb,CAAC,CAAC;EACJ;EAEA,IAAYT,uBAAuBA,CAAA,EAAG;IACpC,IAAI,CAACA,uBAAuB,CAACU,GAAG,CAAC,IAAI,CAACL,EAAE,CAAC,EAAE;MACzCL,uBAAuB,CAACW,GAAG,CAAC,IAAI,CAACN,EAAE,EAAE,EAAE,CAAC;IAC1C;IACA,OAAOL,uBAAuB,CAACY,GAAG,CAAC,IAAI,CAACP,EAAE,CAAC;EAC7C;EAEQQ,oBAAoBA,CAC1BC,YAAe,EACA;IACf,IAAI,IAAI,CAACP,aAAa,CAACO,YAAY,CAAC,IAAI,IAAI,EAAE;MAC5C,IAAI,CAACP,aAAa,CAACO,YAAY,CAAC,GAAG,IAAI,CAACR,cAAc,CAACQ,YAAY,CAAC;IACtE;IACA,OAAO,IAAI,CAACP,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AM,EAAEA,CAAA,KAAM;QACZ,MAAMC,KAAK,GAAG,IAAI,CAACvC,uBAAuB,CAACwC,OAAO,CAACJ,cAAc,CAAC;QAClE,IAAIG,KAAK,KAAK,CAAC,CAAC,EAAE;UAChB,IAAI,CAACvC,uBAAuB,CAACyC,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;QAC/C;MACF;IACF,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
const BULLET_POINT = '\n* ';
|
|
3
|
+
function messageWithSuggestions(message, suggestions) {
|
|
4
|
+
return message + BULLET_POINT + suggestions.join(BULLET_POINT);
|
|
5
|
+
}
|
|
6
|
+
function getFrameworkType() {
|
|
7
|
+
// check if Expo
|
|
8
|
+
const ExpoConstants = NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
|
|
9
|
+
if (ExpoConstants != null) {
|
|
10
|
+
if (ExpoConstants.appOwnership === 'expo') {
|
|
11
|
+
// We're running Expo Go
|
|
12
|
+
return 'expo-go';
|
|
13
|
+
} else {
|
|
14
|
+
// We're running Expo bare / standalone
|
|
15
|
+
return 'expo';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return 'react-native';
|
|
19
|
+
}
|
|
20
|
+
export class ModuleNotFoundError extends Error {
|
|
21
|
+
constructor(cause) {
|
|
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
|
+
const message = 'Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!';
|
|
28
|
+
const suggestions = [];
|
|
29
|
+
suggestions.push('Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.');
|
|
30
|
+
suggestions.push('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)');
|
|
31
|
+
const error = messageWithSuggestions(message, suggestions);
|
|
32
|
+
super(error, {
|
|
33
|
+
cause: cause
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const framework = getFrameworkType();
|
|
38
|
+
if (framework === 'expo-go') {
|
|
39
|
+
super('react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const message = 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
|
|
43
|
+
const suggestions = [];
|
|
44
|
+
suggestions.push('Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)');
|
|
45
|
+
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');
|
|
46
|
+
suggestions.push('Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.');
|
|
47
|
+
suggestions.push('Make sure you rebuilt the app.');
|
|
48
|
+
if (framework === 'expo') {
|
|
49
|
+
suggestions.push('Make sure you ran `expo prebuild`.');
|
|
50
|
+
}
|
|
51
|
+
switch (Platform.OS) {
|
|
52
|
+
case 'ios':
|
|
53
|
+
case 'macos':
|
|
54
|
+
suggestions.push('Make sure you ran `pod install` in the ios/ directory.');
|
|
55
|
+
break;
|
|
56
|
+
case 'android':
|
|
57
|
+
suggestions.push('Make sure gradle is synced.');
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`MMKV is not supported on ${Platform.OS}!`);
|
|
61
|
+
}
|
|
62
|
+
const error = messageWithSuggestions(message, suggestions);
|
|
63
|
+
super(error, {
|
|
64
|
+
cause: cause
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=ModuleNotFoundError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","global","__turboModuleProxy","push","error","framework","OS"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAOtD,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;EACA,MAAMC,aAAa,GACjBR,aAAa,CAACS,oBAAoB,EAAEC,gBAAgB,EAAEC,iBAAiB;EACzE,IAAIH,aAAa,IAAI,IAAI,EAAE;IACzB,IAAIA,aAAa,CAACI,YAAY,KAAK,MAAM,EAAE;MACzC;MACA,OAAO,SAAS;IAClB,CAAC,MAAM;MACL;MACA,OAAO,MAAM;IACf;EACF;EACA,OAAO,cAAc;AACvB;AAEA,OAAO,MAAMC,mBAAmB,SAASC,KAAK,CAAC;EAC7CC,WAAWA,CAACC,KAAe,EAAE;IAC3B;IACA,IAAIC,MAAM,CAACC,kBAAkB,IAAI,IAAI,EAAE;MACrC;MACA;MACA;MACA,MAAMd,OAAO,GACX,+HAA+H;MACjI,MAAMC,WAAqB,GAAG,EAAE;MAChCA,WAAW,CAACc,IAAI,CACd,mFACF,CAAC;MACDd,WAAW,CAACc,IAAI,CACd,sKACF,CAAC;MACD,MAAMC,KAAK,GAAGjB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;MAC1D,KAAK,CAACe,KAAK,EAAE;QAAEJ,KAAK,EAAEA;MAAM,CAAC,CAAC;MAC9B;IACF;IAEA,MAAMK,SAAS,GAAGd,gBAAgB,CAAC,CAAC;IACpC,IAAIc,SAAS,KAAK,SAAS,EAAE;MAC3B,KAAK,CACH,+GACF,CAAC;MACD;IACF;IAEA,MAAMjB,OAAO,GACX,kFAAkF;IACpF,MAAMC,WAAqB,GAAG,EAAE;IAChCA,WAAW,CAACc,IAAI,CACd,+FACF,CAAC;IACDd,WAAW,CAACc,IAAI,CACd,kNACF,CAAC;IACDd,WAAW,CAACc,IAAI,CACd,wGACF,CAAC;IACDd,WAAW,CAACc,IAAI,CAAC,gCAAgC,CAAC;IAClD,IAAIE,SAAS,KAAK,MAAM,EAAE;MACxBhB,WAAW,CAACc,IAAI,CAAC,oCAAoC,CAAC;IACxD;IACA,QAAQlB,QAAQ,CAACqB,EAAE;MACjB,KAAK,KAAK;MACV,KAAK,OAAO;QACVjB,WAAW,CAACc,IAAI,CACd,wDACF,CAAC;QACD;MACF,KAAK,SAAS;QACZd,WAAW,CAACc,IAAI,CAAC,6BAA6B,CAAC;QAC/C;MACF;QACE,MAAM,IAAIL,KAAK,CAAE,4BAA2Bb,QAAQ,CAACqB,EAAG,GAAE,CAAC;IAC/D;IAEA,MAAMF,KAAK,GAAGjB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;IAC1D,KAAK,CAACe,KAAK,EAAE;MAAEJ,KAAK,EAAEA;IAAM,CAAC,CAAC;EAChC;AACF","ignoreList":[]}
|
package/lib/module/NativeMmkv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ModuleNotFoundError } from './ModuleNotFoundError';
|
|
3
|
+
import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Configures the mode of the MMKV instance.
|
|
@@ -15,18 +15,24 @@ export let Mode = /*#__PURE__*/function (Mode) {
|
|
|
15
15
|
* Used for configuration of a single MMKV instance.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
let
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
let module;
|
|
19
|
+
export function getMMKVTurboModule() {
|
|
20
|
+
try {
|
|
21
|
+
if (module == null) {
|
|
22
|
+
// 1. Load MMKV TurboModule
|
|
23
|
+
module = TurboModuleRegistry.getEnforcing('MmkvCxx');
|
|
24
|
+
|
|
25
|
+
// 2. Get the PlatformContext TurboModule as well
|
|
26
|
+
const platformContext = getMMKVPlatformContextTurboModule();
|
|
27
|
+
|
|
28
|
+
// 3. Initialize it with the documents directory from platform-specific context
|
|
29
|
+
const basePath = platformContext.getBaseDirectory();
|
|
30
|
+
module.initialize(basePath);
|
|
31
|
+
}
|
|
32
|
+
return module;
|
|
33
|
+
} catch (cause) {
|
|
34
|
+
// TurboModule could not be found!
|
|
35
|
+
throw new ModuleNotFoundError(cause);
|
|
28
36
|
}
|
|
29
|
-
return module;
|
|
30
37
|
}
|
|
31
|
-
export const MMKVTurboModule = getLazyTurboModule(getNativeModule);
|
|
32
38
|
//# sourceMappingURL=NativeMmkv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","ModuleNotFoundError","getMMKVPlatformContextTurboModule","Mode","module","getMMKVTurboModule","getEnforcing","platformContext","basePath","getBaseDirectory","initialize","cause"],"sourceRoot":"../../src","sources":["NativeMmkv.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAElD,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,iCAAiC,QAAQ,6BAA6B;;AAE/E;AACA;AACA;AACA,WAAYC,IAAI,0BAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA;;AAWhB;AACA;AACA;;AAiEA,IAAIC,MAAmB;AAEvB,OAAO,SAASC,kBAAkBA,CAAA,EAAS;EACzC,IAAI;IACF,IAAID,MAAM,IAAI,IAAI,EAAE;MAClB;MACAA,MAAM,GAAGJ,mBAAmB,CAACM,YAAY,CAAO,SAAS,CAAC;;MAE1D;MACA,MAAMC,eAAe,GAAGL,iCAAiC,CAAC,CAAC;;MAE3D;MACA,MAAMM,QAAQ,GAAGD,eAAe,CAACE,gBAAgB,CAAC,CAAC;MACnDL,MAAM,CAACM,UAAU,CAACF,QAAQ,CAAC;IAC7B;IAEA,OAAOJ,MAAM;EACf,CAAC,CAAC,OAAOO,KAAK,EAAE;IACd;IACA,MAAM,IAAIV,mBAAmB,CAACU,KAAK,CAAC;EACtC;AACF","ignoreList":[]}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { ModuleNotFoundError } from './ModuleNotFoundError';
|
|
3
|
+
let module;
|
|
4
|
+
export function getMMKVPlatformContextTurboModule() {
|
|
5
|
+
try {
|
|
6
|
+
if (module == null) {
|
|
7
|
+
// 1. Get the TurboModule
|
|
8
|
+
module = TurboModuleRegistry.getEnforcing('MmkvPlatformContext');
|
|
9
|
+
}
|
|
10
|
+
return module;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// TurboModule could not be found!
|
|
13
|
+
throw new ModuleNotFoundError(e);
|
|
14
|
+
}
|
|
5
15
|
}
|
|
6
|
-
export const PlatformContext = getLazyTurboModule(getModule);
|
|
7
16
|
//# sourceMappingURL=NativeMmkvPlatformContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","ModuleNotFoundError","module","getMMKVPlatformContextTurboModule","getEnforcing","e"],"sourceRoot":"../../src","sources":["NativeMmkvPlatformContext.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAClD,SAASC,mBAAmB,QAAQ,uBAAuB;AAS3D,IAAIC,MAAmB;AAEvB,OAAO,SAASC,iCAAiCA,CAAA,EAAS;EACxD,IAAI;IACF,IAAID,MAAM,IAAI,IAAI,EAAE;MAClB;MACAA,MAAM,GAAGF,mBAAmB,CAACI,YAAY,CAAO,qBAAqB,CAAC;IACxE;IACA,OAAOF,MAAM;EACf,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV;IACA,MAAM,IAAIJ,mBAAmB,CAACI,CAAC,CAAC;EAClC;AACF","ignoreList":[]}
|
package/lib/module/createMMKV.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getMMKVTurboModule } from './NativeMmkv';
|
|
2
2
|
export const createMMKV = config => {
|
|
3
|
-
const
|
|
3
|
+
const module = getMMKVTurboModule();
|
|
4
|
+
const instance = module.createMMKV(config);
|
|
4
5
|
if (__DEV__) {
|
|
5
6
|
if (typeof instance !== 'object' || instance == null) {
|
|
6
7
|
throw new Error('Failed to create MMKV instance - an unknown object was returned by createMMKV(..)!');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["getMMKVTurboModule","createMMKV","config","module","instance","__DEV__","Error"],"sourceRoot":"../../src","sources":["createMMKV.ts"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,cAAc;AAGjD,OAAO,MAAMC,UAAU,GAAIC,MAAqB,IAAiB;EAC/D,MAAMC,MAAM,GAAGH,kBAAkB,CAAC,CAAC;EAEnC,MAAMI,QAAQ,GAAGD,MAAM,CAACF,UAAU,CAACC,MAAM,CAAC;EAC1C,IAAIG,OAAO,EAAE;IACX,IAAI,OAAOD,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,IAAI,IAAI,EAAE;MACpD,MAAM,IAAIE,KAAK,CACb,oFACF,CAAC;IACH;EACF;EACA,OAAOF,QAAQ;AACjB,CAAC","ignoreList":[]}
|
package/lib/module/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","useState","useMemo","useCallback","useEffect","MMKV","isConfigurationEqual","left","right","encryptionKey","id","path","mode","defaultInstance","getDefaultInstance","useMMKV","configuration","instance","lastConfiguration","current","createMMKVHook","getter","key","mmkv","bump","setBump","value","set","v","newValue","delete","ArrayBuffer","Error","listener","addOnValueChangedListener","changedKey","b","remove","useMMKVString","getString","useMMKVNumber","getNumber","useMMKVBoolean","getBoolean","useMMKVBuffer","getBuffer","useMMKVObject","json","setJson","undefined","JSON","parse","setValue","Function","currentJson","currentValue","stringify","useMMKVListener","valueChangedListener","ref"],"sourceRoot":"../../src","sources":["hooks.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,WAAW,EAAEC,SAAS,QAAQ,OAAO;
|
|
1
|
+
{"version":3,"names":["useRef","useState","useMemo","useCallback","useEffect","MMKV","isConfigurationEqual","left","right","encryptionKey","id","path","mode","defaultInstance","getDefaultInstance","useMMKV","configuration","instance","lastConfiguration","current","createMMKVHook","getter","key","mmkv","bump","setBump","value","set","v","newValue","delete","ArrayBuffer","Error","listener","addOnValueChangedListener","changedKey","b","remove","useMMKVString","getString","useMMKVNumber","getNumber","useMMKVBoolean","getBoolean","useMMKVBuffer","getBuffer","useMMKVObject","json","setJson","undefined","JSON","parse","setValue","Function","currentJson","currentValue","stringify","useMMKVListener","valueChangedListener","ref"],"sourceRoot":"../../src","sources":["hooks.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAEzE,SAASC,IAAI,QAAQ,QAAQ;AAE7B,SAASC,oBAAoBA,CAC3BC,IAAoB,EACpBC,KAAqB,EACZ;EACT,IAAID,IAAI,IAAI,IAAI,IAA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VInterface } from './Types';
|
|
3
|
-
export { Configuration
|
|
1
|
+
import type { Configuration } from './NativeMmkv';
|
|
2
|
+
import type { Listener, MMKVInterface } from './Types';
|
|
3
|
+
export type { Configuration } from './NativeMmkv';
|
|
4
4
|
/**
|
|
5
5
|
* A single MMKV instance.
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MMKV.d.ts","sourceRoot":"","sources":["../../../src/MMKV.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"MMKV.d.ts","sourceRoot":"","sources":["../../../src/MMKV.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAc,MAAM,SAAS,CAAC;AACnE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,qBAAa,IAAK,YAAW,aAAa;IACxC,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,EAAE,CAAS;IAEnB;;;OAGG;gBACS,aAAa,GAAE,aAAsC;IAajE,OAAO,KAAK,uBAAuB,GAKlC;IAED,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,eAAe;IAUvB,IAAI,IAAI,IAAI,MAAM,CAEjB;IACD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI;IAMtE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI5C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI1C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI1C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAI/C,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI9B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAMzB,UAAU,IAAI,MAAM,EAAE;IAItB,QAAQ,IAAI,IAAI;IAQhB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAItC,IAAI,IAAI,IAAI;IAKZ,QAAQ,IAAI,MAAM;IAGlB,MAAM,IAAI,MAAM;IAMhB,yBAAyB,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,QAAQ;CAY3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModuleNotFoundError.d.ts","sourceRoot":"","sources":["../../../src/ModuleNotFoundError.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AA2BD,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,KAAK,CAAC,EAAE,OAAO;CA6D5B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react-native/types/modules/Codegen" />
|
|
2
|
-
import { TurboModule } from 'react-native';
|
|
3
|
-
import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
2
|
+
import type { TurboModule } from 'react-native';
|
|
3
|
+
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
4
|
/**
|
|
5
5
|
* Configures the mode of the MMKV instance.
|
|
6
6
|
*/
|
|
@@ -79,5 +79,5 @@ export interface Spec extends TurboModule {
|
|
|
79
79
|
*/
|
|
80
80
|
createMMKV(configuration: Configuration): UnsafeObject;
|
|
81
81
|
}
|
|
82
|
-
export declare
|
|
82
|
+
export declare function getMMKVTurboModule(): Spec;
|
|
83
83
|
//# sourceMappingURL=NativeMmkv.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeMmkv.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkv.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeMmkv.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkv.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAI9E;;GAEG;AACH,oBAAY,IAAI;IACd;;OAEG;IACH,cAAc,IAAA;IACd;;OAEG;IACH,aAAa,IAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;OAUG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;;OAGG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC;;;OAGG;IACH,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,YAAY,CAAC;CACxD;AAID,wBAAgB,kBAAkB,IAAI,IAAI,CAmBzC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { TurboModule } from 'react-native';
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
2
|
export interface Spec extends TurboModule {
|
|
3
3
|
/**
|
|
4
4
|
* Gets the base directory of the documents storage
|
|
5
5
|
*/
|
|
6
6
|
getBaseDirectory(): string;
|
|
7
7
|
}
|
|
8
|
-
export declare
|
|
8
|
+
export declare function getMMKVPlatformContextTurboModule(): Spec;
|
|
9
9
|
//# sourceMappingURL=NativeMmkvPlatformContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeMmkvPlatformContext.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkvPlatformContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"NativeMmkvPlatformContext.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkvPlatformContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;OAEG;IACH,gBAAgB,IAAI,MAAM,CAAC;CAC5B;AAID,wBAAgB,iCAAiC,IAAI,IAAI,CAWxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMMKV.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,UAAU,WAAY,aAAa,KAAG,
|
|
1
|
+
{"version":3,"file":"createMMKV.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,UAAU,WAAY,aAAa,KAAG,UAYlD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAwB9B;;GAEG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAAC;AAChC;;;GAGG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;AAiF5D;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAnEjB,MAAM,aACA,IAAI,kIAC8B,IAAI,CAmEpD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAjFjB,MAAM,aACA,IAAI,kIAC8B,IAAI,CAiFpD,CAAC;AACF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,QA9FlB,MAAM,aACA,IAAI,sIAC8B,IAAI,CA8FpD,CAAC;AACF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QA3GjB,MAAM,aACA,IAAI,sJAC8B,IAAI,CA2GpD,CAAC;AACF;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,IAAI,GACd;IACD,KAAK,EAAE,CAAC,GAAG,SAAS;IACpB,QAAQ,EAAE,CACR,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC,KACjE,IAAI;CACV,CA4BA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAC3C,QAAQ,CAAC,EAAE,IAAI,GACd,IAAI,CAYN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mmkv",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.6",
|
|
4
4
|
"description": "The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"src",
|
|
27
27
|
"react-native-mmkv.podspec",
|
|
28
28
|
"react-native.config.js",
|
|
29
|
-
"README.md",
|
|
29
|
+
"../README.md",
|
|
30
30
|
"img/banner-light.png",
|
|
31
31
|
"img/banner-dark.png"
|
|
32
32
|
],
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
36
36
|
"lint-ci": "yarn lint -f ./node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
|
|
37
37
|
"lint-cpp": "scripts/clang-format.sh",
|
|
38
|
+
"check-all": "yarn lint --fix && yarn lint-cpp",
|
|
38
39
|
"test": "jest",
|
|
39
40
|
"typecheck": "tsc --noEmit",
|
|
40
41
|
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
@@ -148,28 +149,10 @@
|
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
},
|
|
151
|
-
"eslintConfig": {
|
|
152
|
-
"root": true,
|
|
153
|
-
"extends": [
|
|
154
|
-
"@react-native",
|
|
155
|
-
"prettier"
|
|
156
|
-
],
|
|
157
|
-
"rules": {
|
|
158
|
-
"prettier/prettier": [
|
|
159
|
-
"error",
|
|
160
|
-
{
|
|
161
|
-
"quoteProps": "consistent",
|
|
162
|
-
"singleQuote": true,
|
|
163
|
-
"tabWidth": 2,
|
|
164
|
-
"trailingComma": "es5",
|
|
165
|
-
"useTabs": false
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
152
|
"eslintIgnore": [
|
|
171
153
|
"node_modules/",
|
|
172
|
-
"lib/"
|
|
154
|
+
"lib/",
|
|
155
|
+
"MMKV"
|
|
173
156
|
],
|
|
174
157
|
"prettier": {
|
|
175
158
|
"quoteProps": "consistent",
|
|
@@ -3,6 +3,9 @@ require "json"
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
5
|
|
|
6
|
+
Pod::UI.puts "[react-native-mmkv] Thank you for using react-native-mmkv ❤️"
|
|
7
|
+
Pod::UI.puts "[react-native-mmkv] If you enjoy using react-native-mmkv, please consider sponsoring this project: https://github.com/sponsors/mrousavy"
|
|
8
|
+
|
|
6
9
|
Pod::Spec.new do |s|
|
|
7
10
|
s.name = "react-native-mmkv"
|
|
8
11
|
s.version = package["version"]
|
package/src/MMKV.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { AppState } from 'react-native';
|
|
|
2
2
|
import { createMMKV } from './createMMKV';
|
|
3
3
|
import { createMockMMKV } from './createMMKV.mock';
|
|
4
4
|
import { isTest } from './PlatformChecker';
|
|
5
|
-
import { Configuration } from './NativeMmkv';
|
|
6
|
-
import { Listener, MMKVInterface, NativeMMKV } from './Types';
|
|
7
|
-
export { Configuration
|
|
5
|
+
import type { Configuration } from './NativeMmkv';
|
|
6
|
+
import type { Listener, MMKVInterface, NativeMMKV } from './Types';
|
|
7
|
+
export type { Configuration } from './NativeMmkv';
|
|
8
8
|
|
|
9
9
|
const onValueChangedListeners = new Map<string, ((key: string) => void)[]>();
|
|
10
10
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
// A react-native internal from TurboModuleRegistry.js
|
|
5
|
+
var __turboModuleProxy: unknown | undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const BULLET_POINT = '\n* ';
|
|
9
|
+
|
|
10
|
+
function messageWithSuggestions(
|
|
11
|
+
message: string,
|
|
12
|
+
suggestions: string[]
|
|
13
|
+
): string {
|
|
14
|
+
return message + BULLET_POINT + suggestions.join(BULLET_POINT);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getFrameworkType(): 'react-native' | 'expo' | 'expo-go' {
|
|
18
|
+
// check if Expo
|
|
19
|
+
const ExpoConstants =
|
|
20
|
+
NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
|
|
21
|
+
if (ExpoConstants != null) {
|
|
22
|
+
if (ExpoConstants.appOwnership === 'expo') {
|
|
23
|
+
// We're running Expo Go
|
|
24
|
+
return 'expo-go';
|
|
25
|
+
} else {
|
|
26
|
+
// We're running Expo bare / standalone
|
|
27
|
+
return 'expo';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return 'react-native';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class ModuleNotFoundError extends Error {
|
|
34
|
+
constructor(cause?: unknown) {
|
|
35
|
+
// TurboModule not found, something went wrong!
|
|
36
|
+
if (global.__turboModuleProxy == null) {
|
|
37
|
+
// TurboModules are not available/new arch is not enabled.
|
|
38
|
+
// react-native-mmkv 3.x.x requires new arch (react-native >0.74)
|
|
39
|
+
// react-native-mmkv 2.x.x works on old arch (react-native <0.74)
|
|
40
|
+
const message =
|
|
41
|
+
'Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!';
|
|
42
|
+
const suggestions: string[] = [];
|
|
43
|
+
suggestions.push(
|
|
44
|
+
'Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.'
|
|
45
|
+
);
|
|
46
|
+
suggestions.push(
|
|
47
|
+
'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)'
|
|
48
|
+
);
|
|
49
|
+
const error = messageWithSuggestions(message, suggestions);
|
|
50
|
+
super(error, { cause: cause });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const framework = getFrameworkType();
|
|
55
|
+
if (framework === 'expo-go') {
|
|
56
|
+
super(
|
|
57
|
+
'react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'
|
|
58
|
+
);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const message =
|
|
63
|
+
'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
|
|
64
|
+
const suggestions: string[] = [];
|
|
65
|
+
suggestions.push(
|
|
66
|
+
'Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)'
|
|
67
|
+
);
|
|
68
|
+
suggestions.push(
|
|
69
|
+
'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'
|
|
70
|
+
);
|
|
71
|
+
suggestions.push(
|
|
72
|
+
'Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.'
|
|
73
|
+
);
|
|
74
|
+
suggestions.push('Make sure you rebuilt the app.');
|
|
75
|
+
if (framework === 'expo') {
|
|
76
|
+
suggestions.push('Make sure you ran `expo prebuild`.');
|
|
77
|
+
}
|
|
78
|
+
switch (Platform.OS) {
|
|
79
|
+
case 'ios':
|
|
80
|
+
case 'macos':
|
|
81
|
+
suggestions.push(
|
|
82
|
+
'Make sure you ran `pod install` in the ios/ directory.'
|
|
83
|
+
);
|
|
84
|
+
break;
|
|
85
|
+
case 'android':
|
|
86
|
+
suggestions.push('Make sure gradle is synced.');
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`MMKV is not supported on ${Platform.OS}!`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const error = messageWithSuggestions(message, suggestions);
|
|
93
|
+
super(error, { cause: cause });
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/NativeMmkv.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { TurboModule } from 'react-native';
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
2
|
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
-
import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
import { ModuleNotFoundError } from './ModuleNotFoundError';
|
|
5
|
+
import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Configures the mode of the MMKV instance.
|
|
@@ -85,21 +85,25 @@ export interface Spec extends TurboModule {
|
|
|
85
85
|
createMMKV(configuration: Configuration): UnsafeObject;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
let
|
|
88
|
+
let module: Spec | null;
|
|
89
89
|
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
export function getMMKVTurboModule(): Spec {
|
|
91
|
+
try {
|
|
92
|
+
if (module == null) {
|
|
93
|
+
// 1. Load MMKV TurboModule
|
|
94
|
+
module = TurboModuleRegistry.getEnforcing<Spec>('MmkvCxx');
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
// 2. Get the PlatformContext TurboModule as well
|
|
97
|
+
const platformContext = getMMKVPlatformContextTurboModule();
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
// 3. Initialize it with the documents directory from platform-specific context
|
|
100
|
+
const basePath = platformContext.getBaseDirectory();
|
|
101
|
+
module.initialize(basePath);
|
|
102
|
+
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
return module;
|
|
105
|
+
} catch (cause) {
|
|
106
|
+
// TurboModule could not be found!
|
|
107
|
+
throw new ModuleNotFoundError(cause);
|
|
108
|
+
}
|
|
104
109
|
}
|
|
105
|
-
export const MMKVTurboModule = getLazyTurboModule(getNativeModule);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TurboModule
|
|
2
|
-
import {
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
import { ModuleNotFoundError } from './ModuleNotFoundError';
|
|
3
4
|
|
|
4
5
|
export interface Spec extends TurboModule {
|
|
5
6
|
/**
|
|
@@ -8,7 +9,17 @@ export interface Spec extends TurboModule {
|
|
|
8
9
|
getBaseDirectory(): string;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
let module: Spec | null;
|
|
13
|
+
|
|
14
|
+
export function getMMKVPlatformContextTurboModule(): Spec {
|
|
15
|
+
try {
|
|
16
|
+
if (module == null) {
|
|
17
|
+
// 1. Get the TurboModule
|
|
18
|
+
module = TurboModuleRegistry.getEnforcing<Spec>('MmkvPlatformContext');
|
|
19
|
+
}
|
|
20
|
+
return module;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
// TurboModule could not be found!
|
|
23
|
+
throw new ModuleNotFoundError(e);
|
|
24
|
+
}
|
|
13
25
|
}
|
|
14
|
-
export const PlatformContext = getLazyTurboModule(getModule);
|
package/src/createMMKV.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Configuration } from './MMKV';
|
|
2
|
-
import {
|
|
2
|
+
import { getMMKVTurboModule } from './NativeMmkv';
|
|
3
3
|
import type { NativeMMKV } from './Types';
|
|
4
4
|
|
|
5
5
|
export const createMMKV = (config: Configuration): NativeMMKV => {
|
|
6
|
-
const
|
|
6
|
+
const module = getMMKVTurboModule();
|
|
7
|
+
|
|
8
|
+
const instance = module.createMMKV(config);
|
|
7
9
|
if (__DEV__) {
|
|
8
10
|
if (typeof instance !== 'object' || instance == null) {
|
|
9
11
|
throw new Error(
|
package/src/hooks.ts
CHANGED