react-native-mmkv 4.0.0-beta.1 → 4.0.0-beta.11

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.
Files changed (226) hide show
  1. package/NitroMmkv.podspec +44 -0
  2. package/README.md +1 -3
  3. package/android/CMakeLists.txt +31 -30
  4. package/android/build.gradle +66 -21
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -5
  7. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  8. package/android/src/main/java/com/margelo/nitro/mmkv/HybridMMKVPlatformContext.kt +19 -0
  9. package/android/src/main/java/com/margelo/nitro/mmkv/NitroMmkvPackage.java +33 -0
  10. package/cpp/HybridMMKV.cpp +184 -0
  11. package/cpp/HybridMMKV.hpp +47 -0
  12. package/cpp/HybridMMKVFactory.cpp +33 -0
  13. package/cpp/HybridMMKVFactory.hpp +24 -0
  14. package/cpp/{MmkvTypes.h → MMKVTypes.hpp} +1 -1
  15. package/cpp/MMKVValueChangedListenerRegistry.cpp +58 -0
  16. package/cpp/MMKVValueChangedListenerRegistry.hpp +43 -0
  17. package/cpp/{ManagedMMBuffer.h → ManagedMMBuffer.hpp} +13 -5
  18. package/ios/HybridMMKVPlatformContext.swift +43 -0
  19. package/lib/__tests__/hooks.test.d.ts +1 -0
  20. package/lib/__tests__/hooks.test.js +69 -0
  21. package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
  22. package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
  23. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
  24. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
  25. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
  26. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
  27. package/lib/createMMKV/createMMKV.d.ts +3 -0
  28. package/lib/createMMKV/createMMKV.js +40 -0
  29. package/lib/createMMKV/createMMKV.web.d.ts +3 -0
  30. package/lib/createMMKV/createMMKV.web.js +117 -0
  31. package/lib/createMMKV/createMockMMKV.d.ts +5 -0
  32. package/lib/createMMKV/createMockMMKV.js +74 -0
  33. package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
  34. package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
  35. package/lib/hooks/createMMKVHook.d.ts +2 -0
  36. package/lib/hooks/createMMKVHook.js +49 -0
  37. package/lib/hooks/useMMKV.d.ts +11 -0
  38. package/lib/hooks/useMMKV.js +23 -0
  39. package/lib/hooks/useMMKVBoolean.d.ts +11 -0
  40. package/lib/hooks/useMMKVBoolean.js +12 -0
  41. package/lib/hooks/useMMKVBuffer.d.ts +11 -0
  42. package/lib/hooks/useMMKVBuffer.js +12 -0
  43. package/lib/hooks/useMMKVKeys.d.ts +12 -0
  44. package/lib/hooks/useMMKVKeys.js +33 -0
  45. package/lib/hooks/useMMKVListener.d.ts +15 -0
  46. package/lib/hooks/useMMKVListener.js +26 -0
  47. package/lib/hooks/useMMKVNumber.d.ts +11 -0
  48. package/lib/hooks/useMMKVNumber.js +12 -0
  49. package/lib/hooks/useMMKVObject.d.ts +17 -0
  50. package/lib/hooks/useMMKVObject.js +38 -0
  51. package/lib/hooks/useMMKVString.d.ts +11 -0
  52. package/lib/hooks/useMMKVString.js +12 -0
  53. package/lib/index.d.ts +11 -0
  54. package/lib/index.js +11 -0
  55. package/lib/isTest.d.ts +1 -0
  56. package/lib/isTest.js +7 -0
  57. package/lib/specs/MMKV.nitro.d.ts +94 -0
  58. package/lib/specs/MMKV.nitro.js +1 -0
  59. package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +26 -33
  60. package/lib/specs/MMKVFactory.nitro.js +1 -0
  61. package/lib/specs/MMKVPlatformContext.nitro.d.ts +18 -0
  62. package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
  63. package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
  64. package/lib/web/createTextEncoder.js +17 -0
  65. package/nitro.json +28 -0
  66. package/nitrogen/generated/.gitattributes +1 -0
  67. package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
  68. package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
  69. package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +54 -0
  70. package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
  71. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +52 -0
  72. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
  73. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
  75. package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
  76. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
  77. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +77 -0
  78. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +45 -0
  79. package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
  80. package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
  81. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
  82. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +82 -0
  83. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
  84. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +141 -0
  85. package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
  86. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
  87. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
  88. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
  89. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +64 -0
  90. package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
  91. package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
  92. package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
  93. package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
  94. package/package.json +74 -122
  95. package/react-native.config.js +2 -15
  96. package/src/__tests__/hooks.test.tsx +39 -34
  97. package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
  98. package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
  99. package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
  100. package/src/createMMKV/createMMKV.ts +51 -0
  101. package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +58 -46
  102. package/src/createMMKV/createMockMMKV.ts +78 -0
  103. package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
  104. package/src/hooks/createMMKVHook.ts +66 -0
  105. package/src/hooks/useMMKV.ts +45 -0
  106. package/src/hooks/useMMKVBoolean.ts +15 -0
  107. package/src/hooks/useMMKVBuffer.ts +15 -0
  108. package/src/hooks/useMMKVKeys.ts +36 -0
  109. package/src/hooks/useMMKVListener.ts +33 -0
  110. package/src/hooks/useMMKVNumber.ts +15 -0
  111. package/src/hooks/useMMKVObject.ts +53 -0
  112. package/src/hooks/useMMKVString.ts +15 -0
  113. package/src/index.ts +15 -3
  114. package/src/{PlatformChecker.ts → isTest.ts} +2 -2
  115. package/src/specs/MMKV.nitro.ts +93 -0
  116. package/src/specs/MMKVFactory.nitro.ts +87 -0
  117. package/src/specs/MMKVPlatformContext.nitro.ts +17 -0
  118. package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
  119. package/android/src/main/cpp/AndroidLogger.cpp +0 -16
  120. package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
  121. package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
  122. package/cpp/MmkvHostObject.cpp +0 -360
  123. package/cpp/MmkvHostObject.h +0 -31
  124. package/cpp/MmkvLogger.h +0 -35
  125. package/cpp/NativeMmkvModule.cpp +0 -43
  126. package/cpp/NativeMmkvModule.h +0 -31
  127. package/ios/AppleLogger.mm +0 -16
  128. package/ios/MmkvOnLoad.mm +0 -25
  129. package/ios/MmkvPlatformContext.h +0 -19
  130. package/ios/MmkvPlatformContextModule.mm +0 -55
  131. package/lib/commonjs/MMKV.js +0 -124
  132. package/lib/commonjs/MMKV.js.map +0 -1
  133. package/lib/commonjs/MemoryWarningListener.js +0 -31
  134. package/lib/commonjs/MemoryWarningListener.js.map +0 -1
  135. package/lib/commonjs/MemoryWarningListener.web.js +0 -11
  136. package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
  137. package/lib/commonjs/ModuleNotFoundError.js +0 -75
  138. package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
  139. package/lib/commonjs/NativeMmkv.js +0 -47
  140. package/lib/commonjs/NativeMmkv.js.map +0 -1
  141. package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
  142. package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
  143. package/lib/commonjs/PlatformChecker.js +0 -14
  144. package/lib/commonjs/PlatformChecker.js.map +0 -1
  145. package/lib/commonjs/Types.js +0 -26
  146. package/lib/commonjs/Types.js.map +0 -1
  147. package/lib/commonjs/createMMKV.js +0 -43
  148. package/lib/commonjs/createMMKV.js.map +0 -1
  149. package/lib/commonjs/createMMKV.mock.js +0 -43
  150. package/lib/commonjs/createMMKV.mock.js.map +0 -1
  151. package/lib/commonjs/createMMKV.web.js +0 -110
  152. package/lib/commonjs/createMMKV.web.js.map +0 -1
  153. package/lib/commonjs/createTextEncoder.js +0 -23
  154. package/lib/commonjs/createTextEncoder.js.map +0 -1
  155. package/lib/commonjs/hooks.js +0 -198
  156. package/lib/commonjs/hooks.js.map +0 -1
  157. package/lib/commonjs/index.js +0 -40
  158. package/lib/commonjs/index.js.map +0 -1
  159. package/lib/commonjs/package.json +0 -1
  160. package/lib/module/MMKV.js +0 -119
  161. package/lib/module/MMKV.js.map +0 -1
  162. package/lib/module/MemoryWarningListener.js +0 -27
  163. package/lib/module/MemoryWarningListener.js.map +0 -1
  164. package/lib/module/MemoryWarningListener.web.js +0 -6
  165. package/lib/module/MemoryWarningListener.web.js.map +0 -1
  166. package/lib/module/ModuleNotFoundError.js +0 -70
  167. package/lib/module/ModuleNotFoundError.js.map +0 -1
  168. package/lib/module/NativeMmkv.js +0 -45
  169. package/lib/module/NativeMmkv.js.map +0 -1
  170. package/lib/module/NativeMmkvPlatformContext.js +0 -18
  171. package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
  172. package/lib/module/PlatformChecker.js +0 -10
  173. package/lib/module/PlatformChecker.js.map +0 -1
  174. package/lib/module/Types.js +0 -25
  175. package/lib/module/Types.js.map +0 -1
  176. package/lib/module/createMMKV.js +0 -38
  177. package/lib/module/createMMKV.js.map +0 -1
  178. package/lib/module/createMMKV.mock.js +0 -38
  179. package/lib/module/createMMKV.mock.js.map +0 -1
  180. package/lib/module/createMMKV.web.js +0 -105
  181. package/lib/module/createMMKV.web.js.map +0 -1
  182. package/lib/module/createTextEncoder.js +0 -19
  183. package/lib/module/createTextEncoder.js.map +0 -1
  184. package/lib/module/hooks.js +0 -189
  185. package/lib/module/hooks.js.map +0 -1
  186. package/lib/module/index.js +0 -6
  187. package/lib/module/index.js.map +0 -1
  188. package/lib/module/package.json +0 -1
  189. package/lib/typescript/src/MMKV.d.ts +0 -34
  190. package/lib/typescript/src/MMKV.d.ts.map +0 -1
  191. package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
  192. package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
  193. package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
  194. package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
  195. package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
  196. package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
  197. package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
  198. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
  199. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
  200. package/lib/typescript/src/PlatformChecker.d.ts +0 -2
  201. package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
  202. package/lib/typescript/src/Types.d.ts +0 -172
  203. package/lib/typescript/src/Types.d.ts.map +0 -1
  204. package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
  205. package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
  206. package/lib/typescript/src/createMMKV.d.ts +0 -3
  207. package/lib/typescript/src/createMMKV.d.ts.map +0 -1
  208. package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
  209. package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
  210. package/lib/typescript/src/createMMKV.web.d.ts +0 -3
  211. package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
  212. package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
  213. package/lib/typescript/src/hooks.d.ts +0 -86
  214. package/lib/typescript/src/hooks.d.ts.map +0 -1
  215. package/lib/typescript/src/index.d.ts +0 -4
  216. package/lib/typescript/src/index.d.ts.map +0 -1
  217. package/react-native-mmkv.podspec +0 -32
  218. package/src/MMKV.ts +0 -142
  219. package/src/MemoryWarningListener.web.ts +0 -5
  220. package/src/ModuleNotFoundError.ts +0 -95
  221. package/src/NativeMmkv.ts +0 -118
  222. package/src/NativeMmkvPlatformContext.ts +0 -38
  223. package/src/Types.ts +0 -178
  224. package/src/createMMKV.mock.ts +0 -38
  225. package/src/createMMKV.ts +0 -42
  226. package/src/hooks.ts +0 -247
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// Listener.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+
21
+
22
+
23
+ #include <functional>
24
+
25
+ namespace margelo::nitro::mmkv {
26
+
27
+ /**
28
+ * A struct which can be represented as a JavaScript object (Listener).
29
+ */
30
+ struct Listener {
31
+ public:
32
+ std::function<void()> remove SWIFT_PRIVATE;
33
+
34
+ public:
35
+ Listener() = default;
36
+ explicit Listener(std::function<void()> remove): remove(remove) {}
37
+ };
38
+
39
+ } // namespace margelo::nitro::mmkv
40
+
41
+ namespace margelo::nitro {
42
+
43
+ // C++ Listener <> JS Listener (object)
44
+ template <>
45
+ struct JSIConverter<margelo::nitro::mmkv::Listener> final {
46
+ static inline margelo::nitro::mmkv::Listener fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
47
+ jsi::Object obj = arg.asObject(runtime);
48
+ return margelo::nitro::mmkv::Listener(
49
+ JSIConverter<std::function<void()>>::fromJSI(runtime, obj.getProperty(runtime, "remove"))
50
+ );
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mmkv::Listener& arg) {
53
+ jsi::Object obj(runtime);
54
+ obj.setProperty(runtime, "remove", JSIConverter<std::function<void()>>::toJSI(runtime, arg.remove));
55
+ return obj;
56
+ }
57
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
58
+ if (!value.isObject()) {
59
+ return false;
60
+ }
61
+ jsi::Object obj = value.getObject(runtime);
62
+ if (!JSIConverter<std::function<void()>>::canConvert(runtime, obj.getProperty(runtime, "remove"))) return false;
63
+ return true;
64
+ }
65
+ };
66
+
67
+ } // namespace margelo::nitro
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// Mode.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::mmkv {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (Mode).
30
+ */
31
+ enum class Mode {
32
+ SINGLE_PROCESS SWIFT_NAME(singleProcess) = 0,
33
+ MULTI_PROCESS SWIFT_NAME(multiProcess) = 1,
34
+ } CLOSED_ENUM;
35
+
36
+ } // namespace margelo::nitro::mmkv
37
+
38
+ namespace margelo::nitro {
39
+
40
+ // C++ Mode <> JS Mode (union)
41
+ template <>
42
+ struct JSIConverter<margelo::nitro::mmkv::Mode> final {
43
+ static inline margelo::nitro::mmkv::Mode fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
44
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
45
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
46
+ case hashString("single-process"): return margelo::nitro::mmkv::Mode::SINGLE_PROCESS;
47
+ case hashString("multi-process"): return margelo::nitro::mmkv::Mode::MULTI_PROCESS;
48
+ default: [[unlikely]]
49
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum Mode - invalid value!");
50
+ }
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::mmkv::Mode arg) {
53
+ switch (arg) {
54
+ case margelo::nitro::mmkv::Mode::SINGLE_PROCESS: return JSIConverter<std::string>::toJSI(runtime, "single-process");
55
+ case margelo::nitro::mmkv::Mode::MULTI_PROCESS: return JSIConverter<std::string>::toJSI(runtime, "multi-process");
56
+ default: [[unlikely]]
57
+ throw std::invalid_argument("Cannot convert Mode to JS - invalid value: "
58
+ + std::to_string(static_cast<int>(arg)) + "!");
59
+ }
60
+ }
61
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
62
+ if (!value.isString()) {
63
+ return false;
64
+ }
65
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
66
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
67
+ case hashString("single-process"):
68
+ case hashString("multi-process"):
69
+ return true;
70
+ default:
71
+ return false;
72
+ }
73
+ }
74
+ };
75
+
76
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,65 +1,57 @@
1
1
  {
2
2
  "name": "react-native-mmkv",
3
- "version": "4.0.0-beta.1",
4
- "description": "The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.",
5
- "main": "lib/commonjs/index",
6
- "module": "lib/module/index",
7
- "types": "lib/typescript/src/index.d.ts",
3
+ "version": "4.0.0-beta.11",
4
+ "description": "⚡️ The fastest key/value storage for React Native.",
5
+ "main": "lib/index",
6
+ "module": "lib/index",
7
+ "types": "lib/index.d.ts",
8
8
  "react-native": "src/index",
9
9
  "source": "src/index",
10
10
  "files": [
11
- "cpp/**/*.h",
12
- "cpp/**/*.cpp",
13
- "android/src",
11
+ "src",
12
+ "react-native.config.js",
13
+ "lib",
14
+ "nitrogen",
14
15
  "android/build.gradle",
15
- "android/CMakeLists.txt",
16
- "android/cpp-adapter.cpp",
17
16
  "android/gradle.properties",
18
- "lib/commonjs",
19
- "lib/module",
20
- "lib/typescript",
17
+ "android/fix-prefab.gradle",
18
+ "android/CMakeLists.txt",
19
+ "android/src",
21
20
  "ios/**/*.h",
22
21
  "ios/**/*.m",
23
22
  "ios/**/*.mm",
24
23
  "ios/**/*.cpp",
25
- "src",
26
- "react-native-mmkv.podspec",
27
- "react-native.config.js",
24
+ "ios/**/*.swift",
25
+ "cpp/**/*.h",
26
+ "cpp/**/*.hpp",
27
+ "cpp/**/*.cpp",
28
+ "app.plugin.js",
29
+ "nitro.json",
30
+ "*.podspec",
28
31
  "README.md"
29
32
  ],
30
33
  "scripts": {
31
- "typescript": "tsc --noEmit",
32
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
- "lint-ci": "yarn lint -f ./node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
34
- "lint-cpp": "scripts/clang-format.sh",
35
- "check-all": "yarn lint --fix && yarn lint-cpp",
36
- "test": "jest",
34
+ "postinstall": "tsc || exit 0;",
37
35
  "typecheck": "tsc --noEmit",
38
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
- "prepare": "bob build",
40
- "prepack": "bob build",
41
- "pods": "cd example && yarn pods",
36
+ "clean": "rm -rf android/build node_modules/**/android/build lib",
37
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
38
+ "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
39
+ "typescript": "tsc",
40
+ "specs": "tsc && nitrogen --logLevel=\"debug\"",
41
+ "build": "tsc --noEmit false",
42
42
  "release": "release-it",
43
- "codegen": "npx react-native codegen"
43
+ "test": "jest"
44
44
  },
45
45
  "keywords": [
46
46
  "react-native",
47
- "ios",
48
- "android",
49
- "mmkv",
50
- "storage",
51
- "key",
52
- "value",
53
- "fast",
54
- "turbo",
55
- "async"
47
+ "nitro"
56
48
  ],
57
49
  "repository": {
58
50
  "type": "git",
59
51
  "url": "git+https://github.com/mrousavy/react-native-mmkv.git"
60
52
  },
61
53
  "author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
62
- "license": "(MIT AND BSD-3-Clause)",
54
+ "license": "MIT",
63
55
  "bugs": {
64
56
  "url": "https://github.com/mrousavy/react-native-mmkv/issues"
65
57
  },
@@ -68,111 +60,71 @@
68
60
  "registry": "https://registry.npmjs.org/"
69
61
  },
70
62
  "devDependencies": {
71
- "@firmnav/eslint-github-actions-formatter": "1.0.1",
72
- "@jamesacarr/eslint-formatter-github-actions": "0.2.0",
73
- "@react-native-community/cli": "19.1.1",
74
- "@react-native-community/cli-types": "18.0.0",
75
- "@react-native/babel-preset": "^0.81.0",
63
+ "@expo/config-plugins": "^10.1.2",
76
64
  "@react-native/eslint-config": "0.81.0",
77
- "@release-it/conventional-changelog": "9.0.1",
78
- "@testing-library/react-native": "13.0.1",
79
- "@types/jest": "29.5.13",
80
- "@types/react": "19.1.01",
81
- "del-cli": "6.0.0",
82
- "eslint": "8.51.0",
83
- "eslint-config-prettier": "9.0.0",
84
- "eslint-plugin-prettier": "5.2.1",
85
- "jest": "29.7.0",
86
- "prettier": "3.3.3",
65
+ "@testing-library/react-native": "^13.3.1",
66
+ "@types/jest": "^29.5.12",
67
+ "@types/react": "^19.0.6",
68
+ "eslint": "^8.57.0",
69
+ "eslint-config-prettier": "^9.1.0",
70
+ "eslint-plugin-prettier": "^5.2.1",
71
+ "nitrogen": "^0.29.4",
72
+ "prettier": "^3.3.3",
87
73
  "react": "19.1.0",
88
74
  "react-native": "0.81.0",
89
- "react-native-builder-bob": "0.37.0",
90
- "react-test-renderer": "19.1.0",
91
- "release-it": "17.10.0",
75
+ "react-native-nitro-modules": "^0.29.4",
92
76
  "typescript": "^5.8.3"
93
77
  },
94
78
  "peerDependencies": {
95
79
  "react": "*",
96
- "react-native": "*"
80
+ "react-native": "*",
81
+ "react-native-nitro-modules": "*"
97
82
  },
98
- "jest": {
99
- "preset": "react-native",
100
- "modulePathIgnorePatterns": [
101
- "<rootDir>/example/node_modules",
102
- "<rootDir>/lib/"
103
- ]
83
+ "eslintConfig": {
84
+ "root": true,
85
+ "extends": [
86
+ "@react-native",
87
+ "prettier"
88
+ ],
89
+ "plugins": [
90
+ "prettier"
91
+ ],
92
+ "rules": {
93
+ "prettier/prettier": [
94
+ "warn",
95
+ {
96
+ "quoteProps": "consistent",
97
+ "singleQuote": true,
98
+ "tabWidth": 2,
99
+ "trailingComma": "es5",
100
+ "useTabs": false
101
+ }
102
+ ]
103
+ }
104
104
  },
105
+ "eslintIgnore": [
106
+ "node_modules/",
107
+ "lib/"
108
+ ],
105
109
  "release-it": {
106
- "git": {
107
- "commitMessage": "chore: release ${version}",
108
- "tagName": "v${version}"
109
- },
110
110
  "npm": {
111
111
  "publish": true
112
112
  },
113
+ "git": false,
113
114
  "github": {
114
- "release": true
115
+ "release": false
115
116
  },
116
- "plugins": {
117
- "@release-it/conventional-changelog": {
118
- "preset": {
119
- "name": "conventionalcommits",
120
- "types": [
121
- {
122
- "type": "feat",
123
- "section": "✨ Features"
124
- },
125
- {
126
- "type": "fix",
127
- "section": "🐛 Bug Fixes"
128
- },
129
- {
130
- "type": "perf",
131
- "section": "💨 Performance Improvements"
132
- },
133
- {
134
- "type": "chore(deps)",
135
- "section": "🛠️ Dependency Upgrades"
136
- },
137
- {
138
- "type": "docs",
139
- "section": "📚 Documentation"
140
- }
141
- ]
142
- }
143
- }
117
+ "hooks": {
118
+ "before:init": "bun typecheck",
119
+ "after:bump": "bun run build"
144
120
  }
145
121
  },
146
- "eslintIgnore": [
147
- "node_modules/",
148
- "lib/",
149
- "MMKV"
150
- ],
151
122
  "prettier": {
152
123
  "quoteProps": "consistent",
153
124
  "singleQuote": true,
154
125
  "tabWidth": 2,
155
126
  "trailingComma": "es5",
156
- "useTabs": false
157
- },
158
- "react-native-builder-bob": {
159
- "source": "src",
160
- "output": "lib",
161
- "targets": [
162
- "commonjs",
163
- "module",
164
- [
165
- "typescript",
166
- {
167
- "project": "tsconfig.json"
168
- }
169
- ]
170
- ]
171
- },
172
- "codegenConfig": {
173
- "name": "RNMmkvSpec",
174
- "type": "modules",
175
- "jsSrcsDir": "src"
176
- },
177
- "packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
127
+ "useTabs": false,
128
+ "semi": false
129
+ }
178
130
  }
@@ -10,20 +10,7 @@ module.exports = {
10
10
  /**
11
11
  * @type {import('@react-native-community/cli-types').AndroidDependencyParams}
12
12
  */
13
- android: {
14
- cxxModuleCMakeListsModuleName: 'react-native-mmkv',
15
- cxxModuleCMakeListsPath: 'CMakeLists.txt',
16
- cxxModuleHeaderName: 'NativeMmkvModule',
17
- },
13
+ android: {},
18
14
  },
19
15
  },
20
- // Codegen configuration for TurboModules
21
- codegenConfig: {
22
- name: 'RNMmkvSpec',
23
- type: 'modules',
24
- jsSrcsDir: 'src',
25
- android: {
26
- javaPackageName: 'com.mrousavy.mmkv',
27
- },
28
- },
29
- };
16
+ }
@@ -1,44 +1,49 @@
1
- import React from 'react';
2
- import { Button, Text } from 'react-native';
1
+ import React from 'react'
2
+ import { Button, Text } from 'react-native'
3
3
  import {
4
4
  act,
5
5
  fireEvent,
6
6
  render,
7
7
  renderHook,
8
8
  screen,
9
- } from '@testing-library/react-native';
10
- import { MMKV, useMMKVNumber, useMMKVString } from '..';
9
+ cleanup,
10
+ } from '@testing-library/react-native'
11
+ import { createMMKV, useMMKVNumber, useMMKVString } from '..'
11
12
 
12
- const mmkv = new MMKV();
13
+ const mmkv = createMMKV()
13
14
 
14
15
  beforeEach(() => {
15
- mmkv.clearAll();
16
- mmkv.trim();
17
- });
16
+ mmkv.clearAll()
17
+ mmkv.trim()
18
+ })
19
+
20
+ afterEach(() => {
21
+ cleanup()
22
+ })
18
23
 
19
24
  test('hooks update when the value is changed directly through the instance', () => {
20
- const { result } = renderHook(() => useMMKVString('string-key', mmkv));
25
+ const { result } = renderHook(() => useMMKVString('string-key', mmkv))
21
26
 
22
- expect(result.current[0]).toBeUndefined();
27
+ expect(result.current[0]).toBeUndefined()
23
28
 
24
29
  // First, make a "normal" change
25
30
  act(() => {
26
- result.current[1]('value 1');
27
- });
31
+ result.current[1]('value 1')
32
+ })
28
33
 
29
- expect(result.current[0]).toStrictEqual('value 1');
34
+ expect(result.current[0]).toStrictEqual('value 1')
30
35
 
31
36
  // Now, make the change directly through the instance.
32
37
  act(() => {
33
- mmkv.set('string-key', 'value 2');
34
- });
35
- expect(result.current[0]).toStrictEqual('value 2');
36
- });
38
+ mmkv.set('string-key', 'value 2')
39
+ })
40
+ expect(result.current[0]).toStrictEqual('value 2')
41
+ })
37
42
 
38
43
  test('functional updates to hooks', () => {
39
44
  const Component: React.FC = () => {
40
- const [state, setState] = React.useState(0);
41
- const [value, setValue] = useMMKVNumber('number-key', mmkv);
45
+ const [state, setState] = React.useState(0)
46
+ const [value, setValue] = useMMKVNumber('number-key', mmkv)
42
47
 
43
48
  return (
44
49
  <>
@@ -47,43 +52,43 @@ test('functional updates to hooks', () => {
47
52
  title="Double Increment Me"
48
53
  onPress={() => {
49
54
  // Increment the state value twice, using the function form of useState.
50
- setState((current) => current + 1);
51
- setState((current) => current + 1);
55
+ setState((current) => current + 1)
56
+ setState((current) => current + 1)
52
57
 
53
58
  // Increment the MMKV value twice, using the same function form.
54
- setValue((current) => (current ?? 0) + 1);
55
- setValue((current) => (current ?? 0) + 1);
59
+ setValue((current) => (current ?? 0) + 1)
60
+ setValue((current) => (current ?? 0) + 1)
56
61
  }}
57
62
  />
58
63
  <Text testID="state-value">State: {state.toString()}</Text>
59
64
  <Text testID="mmkv-value">MMKV: {(value ?? 0).toString()}</Text>
60
65
  </>
61
- );
62
- };
66
+ )
67
+ }
63
68
 
64
- render(<Component />);
69
+ render(<Component />)
65
70
 
66
- const button = screen.getByTestId('button');
71
+ const button = screen.getByTestId('button')
67
72
 
68
73
  // Why these assertions:
69
74
  // https://github.com/mrousavy/react-native-mmkv/issues/599
70
- fireEvent.press(button);
75
+ fireEvent.press(button)
71
76
  expect(screen.getByTestId('state-value').children).toStrictEqual([
72
77
  'State: ',
73
78
  '2',
74
- ]);
79
+ ])
75
80
  expect(screen.getByTestId('mmkv-value').children).toStrictEqual([
76
81
  'MMKV: ',
77
82
  '2',
78
- ]);
83
+ ])
79
84
 
80
- fireEvent.press(button);
85
+ fireEvent.press(button)
81
86
  expect(screen.getByTestId('state-value').children).toStrictEqual([
82
87
  'State: ',
83
88
  '4',
84
- ]);
89
+ ])
85
90
  expect(screen.getByTestId('mmkv-value').children).toStrictEqual([
86
91
  'MMKV: ',
87
92
  '4',
88
- ]);
89
- });
93
+ ])
94
+ })
@@ -0,0 +1,5 @@
1
+ import type { MMKV } from '../specs/MMKV.nitro'
2
+
3
+ export function addMemoryWarningListener(_mmkv: MMKV): void {
4
+ // This is no-op in a mocked environment.
5
+ }
@@ -1,29 +1,29 @@
1
- import { AppState } from 'react-native';
2
- import type { NativeEventSubscription } from 'react-native';
3
- import { MMKVInterface } from './Types';
1
+ import { AppState } from 'react-native'
2
+ import type { NativeEventSubscription } from 'react-native'
3
+ import type { MMKV } from '../specs/MMKV.nitro'
4
4
 
5
- export function addMemoryWarningListener(mmkv: MMKVInterface): void {
5
+ export function addMemoryWarningListener(mmkv: MMKV): void {
6
6
  if (global.WeakRef != null && global.FinalizationRegistry != null) {
7
7
  // 1. Weakify MMKV so we can safely use it inside the memoryWarning event listener
8
- const weakMmkv = new WeakRef(mmkv);
8
+ const weakMmkv = new WeakRef(mmkv)
9
9
  const listener = AppState.addEventListener('memoryWarning', () => {
10
10
  // 0. Everytime we receive a memoryWarning, we try to trim the MMKV instance (if it is still valid)
11
- weakMmkv.deref()?.trim();
12
- });
11
+ weakMmkv.deref()?.trim()
12
+ })
13
13
  // 2. Add a listener to when the MMKV instance is deleted
14
14
  const finalization = new FinalizationRegistry(
15
15
  (l: NativeEventSubscription) => {
16
16
  // 3. When MMKV is deleted, this listener will be called with the memoryWarning listener.
17
- l.remove();
17
+ l.remove()
18
18
  }
19
- );
19
+ )
20
20
  // 2.1. Bind the listener to the actual MMKV instance.
21
- finalization.register(mmkv, listener);
21
+ finalization.register(mmkv, listener)
22
22
  } else {
23
23
  // WeakRef/FinalizationRegistry is not implemented in this engine.
24
24
  // Just add the listener, even if it retains MMKV strong forever.
25
25
  AppState.addEventListener('memoryWarning', () => {
26
- mmkv.trim();
27
- });
26
+ mmkv.trim()
27
+ })
28
28
  }
29
29
  }
@@ -0,0 +1,5 @@
1
+ import type { MMKV } from '../specs/MMKV.nitro'
2
+
3
+ export const addMemoryWarningListener = (_mmkv: MMKV): void => {
4
+ //no-op function, there is not a web equivalent to memory warning
5
+ }
@@ -0,0 +1,51 @@
1
+ import { NitroModules } from 'react-native-nitro-modules'
2
+ import type { MMKV } from '../specs/MMKV.nitro'
3
+ import type { Configuration, MMKVFactory } from '../specs/MMKVFactory.nitro'
4
+ import type { MMKVPlatformContext } from '../specs/MMKVPlatformContext.nitro'
5
+ import { Platform } from 'react-native'
6
+ import { addMemoryWarningListener } from '../addMemoryWarningListener/addMemoryWarningListener'
7
+ import { isTest } from '../isTest'
8
+ import { createMockMMKV } from './createMockMMKV'
9
+
10
+ let factory: MMKVFactory | undefined
11
+ let platformContext: MMKVPlatformContext | undefined
12
+
13
+ export function createMMKV(configuration?: Configuration): MMKV {
14
+ if (isTest()) {
15
+ // In a test environment, we mock the MMKV instance.
16
+ return createMockMMKV()
17
+ }
18
+
19
+ if (platformContext == null) {
20
+ // Lazy-init the platform-context HybridObject
21
+ platformContext = NitroModules.createHybridObject<MMKVPlatformContext>(
22
+ 'MMKVPlatformContext'
23
+ )
24
+ }
25
+ if (factory == null) {
26
+ // Lazy-init the factory HybridObject
27
+ factory = NitroModules.createHybridObject<MMKVFactory>('MMKVFactory')
28
+ const baseDirectory = platformContext.getBaseDirectory()
29
+ factory.initializeMMKV(baseDirectory)
30
+ }
31
+
32
+ // Pre-parse the config
33
+ let config = configuration ?? { id: factory.defaultMMKVInstanceId }
34
+
35
+ if (Platform.OS === 'ios') {
36
+ if (config.path == null) {
37
+ // If the user set an App Group directory in Info.plist, let's use
38
+ // the App Group as a MMKV path:
39
+ const appGroupDirectory = platformContext.getAppGroupDirectory()
40
+ if (appGroupDirectory != null) {
41
+ config.path = appGroupDirectory
42
+ }
43
+ }
44
+ }
45
+
46
+ // Creates the C++ MMKV HybridObject
47
+ const mmkv = factory.createMMKV(config)
48
+ // Add a hook that trims the storage when we get a memory warning
49
+ addMemoryWarningListener(mmkv)
50
+ return mmkv
51
+ }