react-native-mmkv 2.5.1 → 2.6.1

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 (59) hide show
  1. package/MMKV/Core/MMKV.cpp +13 -0
  2. package/MMKV/Core/MMKVPredef.h +1 -1
  3. package/MMKV/Core/MMKV_IO.cpp +2 -0
  4. package/MMKV/Core/MMKV_OSX.cpp +7 -1
  5. package/README.md +1 -1
  6. package/android/CMakeLists.txt +14 -44
  7. package/android/build.gradle +62 -316
  8. package/android/gradle.properties +5 -3
  9. package/android/src/main/cpp/MmkvHostObject.cpp +1 -0
  10. package/ios/MmkvHostObject.mm +1 -0
  11. package/lib/commonjs/MMKV.js +5 -34
  12. package/lib/commonjs/MMKV.js.map +1 -1
  13. package/lib/commonjs/PlatformChecker.js +0 -2
  14. package/lib/commonjs/PlatformChecker.js.map +1 -1
  15. package/lib/commonjs/createMMKV.js +8 -19
  16. package/lib/commonjs/createMMKV.js.map +1 -1
  17. package/lib/commonjs/createMMKV.mock.js +0 -2
  18. package/lib/commonjs/createMMKV.mock.js.map +1 -1
  19. package/lib/commonjs/createMMKV.web.js +3 -20
  20. package/lib/commonjs/createMMKV.web.js.map +1 -1
  21. package/lib/commonjs/createTextEncoder.js +0 -1
  22. package/lib/commonjs/createTextEncoder.js.map +1 -1
  23. package/lib/commonjs/hooks.js +12 -27
  24. package/lib/commonjs/hooks.js.map +1 -1
  25. package/lib/commonjs/index.js +0 -4
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/module/MMKV.js +5 -29
  28. package/lib/module/MMKV.js.map +1 -1
  29. package/lib/module/PlatformChecker.js +0 -1
  30. package/lib/module/PlatformChecker.js.map +1 -1
  31. package/lib/module/createMMKV.js +8 -15
  32. package/lib/module/createMMKV.js.map +1 -1
  33. package/lib/module/createMMKV.mock.js.map +1 -1
  34. package/lib/module/createMMKV.web.js +4 -16
  35. package/lib/module/createMMKV.web.js.map +1 -1
  36. package/lib/module/createTextEncoder.js.map +1 -1
  37. package/lib/module/hooks.js +12 -23
  38. package/lib/module/hooks.js.map +1 -1
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/typescript/MMKV.d.ts +2 -1
  41. package/lib/typescript/MMKV.d.ts.map +1 -0
  42. package/lib/typescript/PlatformChecker.d.ts +1 -0
  43. package/lib/typescript/PlatformChecker.d.ts.map +1 -0
  44. package/lib/typescript/createMMKV.d.ts +1 -0
  45. package/lib/typescript/createMMKV.d.ts.map +1 -0
  46. package/lib/typescript/createMMKV.mock.d.ts +1 -0
  47. package/lib/typescript/createMMKV.mock.d.ts.map +1 -0
  48. package/lib/typescript/createMMKV.web.d.ts +1 -0
  49. package/lib/typescript/createMMKV.web.d.ts.map +1 -0
  50. package/lib/typescript/createTextEncoder.d.ts +1 -0
  51. package/lib/typescript/createTextEncoder.d.ts.map +1 -0
  52. package/lib/typescript/hooks.d.ts +5 -4
  53. package/lib/typescript/hooks.d.ts.map +1 -0
  54. package/lib/typescript/index.d.ts +1 -0
  55. package/lib/typescript/index.d.ts.map +1 -0
  56. package/package.json +16 -15
  57. package/MMKV/CHANGELOG.md +0 -553
  58. package/MMKV/LICENSE.TXT +0 -193
  59. package/MMKV/README.md +0 -288
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks.ts"],"names":["isConfigurationEqual","left","right","encryptionKey","id","path","defaultInstance","getDefaultInstance","MMKV","useMMKV","configuration","instance","lastConfiguration","current","createMMKVHook","getter","key","mmkv","value","setValue","valueRef","set","v","newValue","delete","Error","listener","addOnValueChangedListener","changedKey","remove","useMMKVString","getString","useMMKVNumber","getNumber","useMMKVBoolean","getBoolean","useMMKVBuffer","getBuffer","useMMKVObject","string","setString","undefined","JSON","parse","stringify","useMMKVListener","valueChangedListener","ref"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AAEA,SAASA,oBAAT,CACEC,IADF,EAEEC,KAFF,EAGW;AACT,MAAID,IAAI,IAAI,IAAR,IAAgBC,KAAK,IAAI,IAA7B,E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,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS0B,eAAT,CACLC,oBADK,EAELnC,QAFK,EAGC;AACN,QAAMoC,GAAG,GAAG,mBAAOD,oBAAP,CAAZ;AACAC,EAAAA,GAAG,CAAClC,OAAJ,GAAciC,oBAAd;AAEA,QAAM7B,IAAI,GAAGN,QAAH,aAAGA,QAAH,cAAGA,QAAH,GAAeJ,kBAAkB,EAA3C;AAEA,wBAAU,MAAM;AACd,UAAMmB,QAAQ,GAAGT,IAAI,CAACU,yBAAL,CAAgCC,UAAD,IAAgB;AAC9DmB,MAAAA,GAAG,CAAClC,OAAJ,CAAYe,UAAZ;AACD,KAFgB,CAAjB;AAGA,WAAO,MAAMF,QAAQ,CAACG,MAAT,EAAb;AACD,GALD,EAKG,CAACZ,IAAD,CALH;AAMD","sourcesContent":["import { useRef, useState, useMemo, useCallback, useEffect } from 'react';\nimport { MMKV, MMKVConfiguration } from './MMKV';\n\nfunction isConfigurationEqual(\n left?: MMKVConfiguration,\n right?: MMKVConfiguration\n): boolean {\n if (left == null || right == null) return left == null && right == null;\n\n return (\n left.encryptionKey === right.encryptionKey &&\n left.id === right.id &&\n left.path === right.path\n );\n}\n\nlet defaultInstance: MMKV | null = null;\nfunction getDefaultInstance(): MMKV {\n if (defaultInstance == null) {\n defaultInstance = new MMKV();\n }\n return defaultInstance;\n}\n\n/**\n * Use the default, shared MMKV instance.\n */\nexport function useMMKV(): MMKV;\n/**\n * Use a custom MMKV instance with the given configuration.\n * @param configuration The configuration to initialize the MMKV instance with. Does not have to be memoized.\n */\nexport function useMMKV(configuration: MMKVConfiguration): MMKV;\nexport function useMMKV(configuration?: MMKVConfiguration): MMKV {\n const instance = useRef<MMKV>();\n const lastConfiguration = useRef<MMKVConfiguration>();\n\n if (configuration == null) return getDefaultInstance();\n\n if (\n instance.current == null ||\n !isConfigurationEqual(lastConfiguration.current, configuration)\n ) {\n lastConfiguration.current = configuration;\n instance.current = new MMKV(configuration);\n }\n\n return instance.current;\n}\n\nfunction createMMKVHook<\n T extends (boolean | number | string | Uint8Array) | undefined,\n TSet extends T | undefined,\n TSetAction extends TSet | ((current: T) => TSet)\n>(getter: (instance: MMKV, key: string) => T) {\n return (\n key: string,\n instance?: MMKV\n ): [value: T, setValue: (value: TSetAction) => void] => {\n const mmkv = instance ?? getDefaultInstance();\n const [value, setValue] = useState(() => getter(mmkv, key));\n const valueRef = useRef<T>(value);\n valueRef.current = value;\n\n // update value by user set\n const set = useCallback(\n (v: TSetAction) => {\n const newValue = typeof v === 'function' ? v(valueRef.current) : v;\n switch (typeof newValue) {\n case 'number':\n case 'string':\n case 'boolean':\n mmkv.set(key, newValue);\n break;\n case 'undefined':\n mmkv.delete(key);\n break;\n default:\n throw new Error(`MMKV: Type ${typeof newValue} is not supported!`);\n }\n },\n [key, mmkv]\n );\n\n // update value if key or instance changes\n useEffect(() => {\n setValue(getter(mmkv, key));\n }, [key, mmkv]);\n\n // update value if it changes somewhere else (second hook, same key)\n useEffect(() => {\n const listener = mmkv.addOnValueChangedListener((changedKey) => {\n if (changedKey === key) {\n setValue(getter(mmkv, key));\n }\n });\n return () => listener.remove();\n }, [key, mmkv]);\n\n return [value, set];\n };\n}\n\n/**\n * Use the string value of the given `key` from the given MMKV storage instance.\n *\n * If no instance is provided, a shared default instance will be used.\n *\n * @example\n * ```ts\n * const [username, setUsername] = useMMKVString(\"user.name\")\n * ```\n */\nexport const useMMKVString = createMMKVHook((instance, key) =>\n instance.getString(key)\n);\n\n/**\n * Use the number value of the given `key` from the given MMKV storage instance.\n *\n * If no instance is provided, a shared default instance will be used.\n *\n * @example\n * ```ts\n * const [age, setAge] = useMMKVNumber(\"user.age\")\n * ```\n */\nexport const useMMKVNumber = createMMKVHook((instance, key) =>\n instance.getNumber(key)\n);\n/**\n * Use the boolean value of the given `key` from the given MMKV storage instance.\n *\n * If no instance is provided, a shared default instance will be used.\n *\n * @example\n * ```ts\n * const [isPremiumAccount, setIsPremiumAccount] = useMMKVBoolean(\"user.isPremium\")\n * ```\n */\nexport const useMMKVBoolean = createMMKVHook((instance, key) =>\n instance.getBoolean(key)\n);\n/**\n * Use the buffer value (unsigned 8-bit (0-255)) of the given `key` from the given MMKV storage instance.\n *\n * If no instance is provided, a shared default instance will be used.\n *\n * @example\n * ```ts\n * const [privateKey, setPrivateKey] = useMMKVBuffer(\"user.privateKey\")\n * ```\n */\nexport const useMMKVBuffer = createMMKVHook((instance, key) =>\n instance.getBuffer(key)\n);\n/**\n * Use an object value of the given `key` from the given MMKV storage instance.\n *\n * If no instance is provided, a shared default instance will be used.\n *\n * The object will be serialized using `JSON`.\n *\n * @example\n * ```ts\n * const [user, setUser] = useMMKVObject<User>(\"user\")\n * ```\n */\nexport function useMMKVObject<T>(\n key: string,\n instance?: MMKV\n): [value: T | undefined, setValue: (value: T | undefined) => void] {\n const [string, setString] = useMMKVString(key, instance);\n\n const value = useMemo(() => {\n if (string == null) return undefined;\n return JSON.parse(string) as T;\n }, [string]);\n const setValue = useCallback(\n (v: T | undefined) => {\n if (v == null) {\n // Clear the Value\n setString(undefined);\n } else {\n // Store the Object as a serialized Value\n setString(JSON.stringify(v));\n }\n },\n [setString]\n );\n\n return [value, setValue];\n}\n\n/**\n * Listen for changes in the given MMKV storage instance.\n * If no instance is passed, the default instance will be used.\n * @param valueChangedListener The function to call whenever a value inside the storage instance changes\n * @param instance The instance to listen to changes to (or the default instance)\n *\n * @example\n * ```ts\n * useMMKVListener((key) => {\n * console.log(`Value for \"${key}\" changed!`)\n * })\n * ```\n */\nexport function useMMKVListener(\n valueChangedListener: (key: string) => void,\n instance?: MMKV\n): void {\n const ref = useRef(valueChangedListener);\n ref.current = valueChangedListener;\n\n const mmkv = instance ?? getDefaultInstance();\n\n useEffect(() => {\n const listener = mmkv.addOnValueChangedListener((changedKey) => {\n ref.current(changedKey);\n });\n return () => listener.remove();\n }, [mmkv]);\n}\n"]}
1
+ {"version":3,"names":["isConfigurationEqual","left","right","encryptionKey","id","path","defaultInstance","getDefaultInstance","MMKV","useMMKV","configuration","instance","useRef","lastConfiguration","current","createMMKVHook","getter","key","mmkv","value","setValue","useState","valueRef","set","useCallback","v","newValue","delete","Error","useEffect","listener","addOnValueChangedListener","changedKey","remove","useMMKVString","getString","useMMKVNumber","getNumber","useMMKVBoolean","getBoolean","useMMKVBuffer","getBuffer","useMMKVObject","string","setString","useMemo","undefined","JSON","parse","stringify","useMMKVListener","valueChangedListener","ref"],"sourceRoot":"../../src","sources":["hooks.ts"],"mappings":";;;;;;;;;;;AAAA;AACA;AAEA,SAASA,oBAAoB,CAC3BC,IAAwB,EACxBC,KAAyB,EAChB;EACT,IAAID,IAAI,IAAI,IAAI,IAAIC,KAAK,IAAI,IAAI,EAAE,OAAOD,IAAI,IAAI,IAAI,IAAIC,KAAK,IAAI,IAAI;EAEvE,OACED,IAAI,CAACE,aAAa,KAAKD,KAAK,CAACC,aAAa,IAC1CF,IAAI,CAACG,EAAE,KAAKF,KAAK,CAACE,EAAE,IACpBH,IAAI,CAACI,IAAI,KAAKH,KAAK,CAACG,IAAI;AAE5B;AAEA,IAAIC,eAA4B,GAAG,IAAI;AACvC,SAASC,kBAAkB,GAAS;EAClC,IAAID,eAAe,IAAI,IAAI,EAAE;IAC3BA,eAAe,GAAG,IAAIE,UAAI,EAAE;EAC9B;EACA,OAAOF,eAAe;AACxB;;AAEA;AACA;AACA;;AAOO,SAASG,OAAO,CAACC,aAAiC,EAAQ;EAC/D,MAAMC,QAAQ,GAAG,IAAAC,aAAM,GAAQ;EAC/B,MAAMC,iBAAiB,GAAG,IAAAD,aAAM,GAAqB;EAErD,IAAIF,aAAa,IAAI,IAAI,EAAE,OAAOH,kBAAkB,EAAE;EAEtD,IACEI,QAAQ,CAACG,OAAO,IAAI,IAAI,IACxB,CAACd,oBAAoB,CAACa,iBAAiB,CAACC,OAAO,EAAEJ,aAAa,CAAC,EAC/D;IACAG,iBAAiB,CAACC,OAAO,GAAG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AK,GAAG,IAAA0B,cAAO,EAAC,MAAM;IAC1B,IAAIF,MAAM,IAAI,IAAI,EAAE,OAAOG,SAAS;IACpC,OAAOC,IAAI,CAACC,KAAK,CAACL,MAAM,CAAC;EAC3B,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EACZ,MAAMvB,QAAQ,GAAG,IAAAI,kBAAW,EACzBC,CAAgB,IAAK;IACpB,IAAIA,CAAC,IAAI,IAAI,EAAE;MACb;MACAmB,SAAS,CAACE,SAAS,CAAC;IACtB,CAAC,MAAM;MACL;MACAF,SAAS,CAACG,IAAI,CAACE,SAAS,CAACxB,CAAC,CAAC,CAAC;IAC9B;EACF,CAAC,EACD,CAACmB,SAAS,CAAC,CACZ;EAED,OAAO,CAACzB,KAAK,EAAEC,QAAQ,CAAC;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS8B,eAAe,CAC7BC,oBAA2C,EAC3CxC,QAAe,EACT;EACN,MAAMyC,GAAG,GAAG,IAAAxC,aAAM,EAACuC,oBAAoB,CAAC;EACxCC,GAAG,CAACtC,OAAO,GAAGqC,oBAAoB;EAElC,MAAMjC,IAAI,GAAGP,QAAQ,IAAIJ,kBAAkB,EAAE;EAE7C,IAAAsB,gBAAS,EAAC,MAAM;IACd,MAAMC,QAAQ,GAAGZ,IAAI,CAACa,yBAAyB,CAAEC,UAAU,IAAK;MAC9DoB,GAAG,CAACtC,OAAO,CAACkB,UAAU,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,MAAMF,QAAQ,CAACG,MAAM,EAAE;EAChC,CAAC,EAAE,CAACf,IAAI,CAAC,CAAC;AACZ"}
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _MMKV = require("./MMKV");
8
-
9
7
  Object.keys(_MMKV).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _MMKV[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_MMKV).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _hooks = require("./hooks");
21
-
22
18
  Object.keys(_hooks).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _hooks[key]) return;
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './MMKV';\nexport * from './hooks';\n"]}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,134 +1,110 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
2
  import { createMMKV } from './createMMKV';
4
3
  import { createMockMMKV } from './createMMKV.mock';
5
4
  import { isJest } from './PlatformChecker';
6
5
  const onValueChangedListeners = new Map();
6
+
7
7
  /**
8
8
  * A single MMKV instance.
9
9
  */
10
-
11
10
  export class MMKV {
12
11
  /**
13
12
  * Creates a new MMKV instance with the given Configuration.
14
13
  * If no custom `id` is supplied, `'mmkv.default'` will be used.
15
14
  */
16
- constructor(configuration = {
17
- id: 'mmkv.default'
18
- }) {
15
+ constructor() {
16
+ let configuration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
17
+ id: 'mmkv.default'
18
+ };
19
19
  _defineProperty(this, "nativeInstance", void 0);
20
-
21
20
  _defineProperty(this, "functionCache", void 0);
22
-
23
21
  _defineProperty(this, "id", void 0);
24
-
25
22
  this.id = configuration.id;
26
23
  this.nativeInstance = isJest() ? createMockMMKV() : createMMKV(configuration);
27
24
  this.functionCache = {};
28
25
  }
29
-
30
26
  get onValueChangedListeners() {
31
27
  if (!onValueChangedListeners.has(this.id)) {
32
28
  onValueChangedListeners.set(this.id, []);
33
29
  }
34
-
35
30
  return onValueChangedListeners.get(this.id);
36
31
  }
37
-
38
32
  getFunctionFromCache(functionName) {
39
33
  if (this.functionCache[functionName] == null) {
40
34
  this.functionCache[functionName] = this.nativeInstance[functionName];
41
35
  }
42
-
43
36
  return this.functionCache[functionName];
44
37
  }
45
-
46
38
  onValuesChanged(keys) {
47
39
  if (this.onValueChangedListeners.length === 0) return;
48
-
49
40
  for (const key of keys) {
50
41
  for (const listener of this.onValueChangedListeners) {
51
42
  listener(key);
52
43
  }
53
44
  }
54
45
  }
55
-
56
46
  set(key, value) {
57
47
  const func = this.getFunctionFromCache('set');
58
48
  func(key, value);
59
49
  this.onValuesChanged([key]);
60
50
  }
61
-
62
51
  getBoolean(key) {
63
52
  const func = this.getFunctionFromCache('getBoolean');
64
53
  return func(key);
65
54
  }
66
-
67
55
  getString(key) {
68
56
  const func = this.getFunctionFromCache('getString');
69
57
  return func(key);
70
58
  }
71
-
72
59
  getNumber(key) {
73
60
  const func = this.getFunctionFromCache('getNumber');
74
61
  return func(key);
75
62
  }
76
-
77
63
  getBuffer(key) {
78
64
  const func = this.getFunctionFromCache('getBuffer');
79
65
  return func(key);
80
66
  }
81
-
82
67
  contains(key) {
83
68
  const func = this.getFunctionFromCache('contains');
84
69
  return func(key);
85
70
  }
86
-
87
71
  delete(key) {
88
72
  const func = this.getFunctionFromCache('delete');
89
73
  func(key);
90
74
  this.onValuesChanged([key]);
91
75
  }
92
-
93
76
  getAllKeys() {
94
77
  const func = this.getFunctionFromCache('getAllKeys');
95
78
  return func();
96
79
  }
97
-
98
80
  clearAll() {
99
81
  const keys = this.getAllKeys();
100
82
  const func = this.getFunctionFromCache('clearAll');
101
83
  func();
102
84
  this.onValuesChanged(keys);
103
85
  }
104
-
105
86
  recrypt(key) {
106
87
  const func = this.getFunctionFromCache('recrypt');
107
88
  return func(key);
108
89
  }
109
-
110
90
  toString() {
111
91
  return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;
112
92
  }
113
-
114
93
  toJSON() {
115
94
  return {
116
95
  [this.id]: this.getAllKeys()
117
96
  };
118
97
  }
119
-
120
98
  addOnValueChangedListener(onValueChanged) {
121
99
  this.onValueChangedListeners.push(onValueChanged);
122
100
  return {
123
101
  remove: () => {
124
102
  const index = this.onValueChangedListeners.indexOf(onValueChanged);
125
-
126
103
  if (index !== -1) {
127
104
  this.onValueChangedListeners.splice(index, 1);
128
105
  }
129
106
  }
130
107
  };
131
108
  }
132
-
133
109
  }
134
110
  //# sourceMappingURL=MMKV.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["MMKV.ts"],"names":["createMMKV","createMockMMKV","isJest","onValueChangedListeners","Map","MMKV","constructor","configuration","id","nativeInstance","functionCache","has","set","get","getFunctionFromCache","functionName","onValuesChanged","keys","length","key","listener","value","func","getBoolean","getString","getNumber","getBuffer","contains","delete","getAllKeys","clearAll","recrypt","toString","join","toJSON","addOnValueChangedListener","onValueChanged","push","remove","index","indexOf","splice"],"mappings":";;AAAA,SAASA,UAAT,QAA2B,cAA3B;AACA,SAASC,cAAT,QAA+B,mBAA/B;AACA,SAASC,MAAT,QAAuB,mBAAvB;AA+HA,MAAMC,uBAAuB,GAAG,IAAIC,GAAJ,EAAhC;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,IAAN,CAAoC;AAKzC;AACF;AACA;AACA;AACEC,EAAAA,WAAW,CAACC,aAAgC,GAAG;AAAEC,IAAAA,EAAE,EAAE;AAAN,GAApC,EAA4D;AAAA;;AAAA;;AAAA;;AACrE,SAAKA,EAAL,GAAUD,aAAa,CAACC,EAAxB;AACA,SAAKC,cAAL,GAAsBP,MAAM,KACxBD,cAA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xB,EAAG,OAAM,KAAKqB,UAAL,GAAkBI,IAAlB,CAAuB,IAAvB,CAA6B,GAA3D;AACD;;AACDC,EAAAA,MAAM,GAAW;AACf,WAAO;AACL,OAAC,KAAK1B,EAAN,GAAW,KAAKqB,UAAL;AADN,KAAP;AAGD;;AAEDM,EAAAA,yBAAyB,CAACC,cAAD,EAAkD;AACzE,SAAKjC,uBAAL,CAA6BkC,IAA7B,CAAkCD,cAAlC;AAEA,WAAO;AACLE,MAAAA,MAAM,EAAE,MAAM;AACZ,cAAMC,KAAK,GAAG,KAAKpC,uBAAL,CAA6BqC,OAA7B,CAAqCJ,cAArC,CAAd;;AACA,YAAIG,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,eAAKpC,uBAAL,CAA6BsC,MAA7B,CAAoCF,KAApC,EAA2C,CAA3C;AACD;AACF;AANI,KAAP;AAQD;;AAhHwC","sourcesContent":["import { createMMKV } from './createMMKV';\nimport { createMockMMKV } from './createMMKV.mock';\nimport { isJest } from './PlatformChecker';\n\ninterface Listener {\n remove: () => void;\n}\n\n/**\n * Used for configuration of a single MMKV instance.\n */\nexport interface MMKVConfiguration {\n /**\n * The MMKV instance's ID. If you want to use multiple instances, make sure to use different IDs!\n *\n * @example\n * ```ts\n * const userStorage = new MMKV({ id: `user-${userId}-storage` })\n * const globalStorage = new MMKV({ id: 'global-app-storage' })\n * ```\n *\n * @default 'mmkv.default'\n */\n id: string;\n /**\n * The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization:\n *\n * @example\n * ```ts\n * const temporaryStorage = new MMKV({ path: '/tmp/' })\n * ```\n */\n path?: string;\n /**\n * The MMKV instance's encryption/decryption key. By default, MMKV stores all key-values in plain text on file, relying on iOS's sandbox to make sure the file is encrypted. Should you worry about information leaking, you can choose to encrypt MMKV.\n *\n * Encryption keys can have a maximum length of 16 bytes.\n *\n * @example\n * ```ts\n * const secureStorage = new MMKV({ encryptionKey: 'my-encryption-key!' })\n * ```\n */\n encryptionKey?: string;\n}\n\n/**\n * Represents a single MMKV instance.\n */\ninterface MMKVInterface {\n /**\n * Set a value for the given `key`.\n */\n set: (key: string, value: boolean | string | number | Uint8Array) => void;\n /**\n * Get the boolean value for the given `key`, or `undefined` if it does not exist.\n *\n * @default undefined\n */\n getBoolean: (key: string) => boolean | undefined;\n /**\n * Get the string value for the given `key`, or `undefined` if it does not exist.\n *\n * @default undefined\n */\n getString: (key: string) => string | undefined;\n /**\n * Get the number value for the given `key`, or `undefined` if it does not exist.\n *\n * @default undefined\n */\n getNumber: (key: string) => number | undefined;\n /**\n * Get a raw buffer of unsigned 8-bit (0-255) data.\n *\n * @default undefined\n */\n getBuffer: (key: string) => Uint8Array | undefined;\n /**\n * Checks whether the given `key` is being stored in this MMKV instance.\n */\n contains: (key: string) => boolean;\n /**\n * Delete the given `key`.\n */\n delete: (key: string) => void;\n /**\n * Get all keys.\n *\n * @default []\n */\n getAllKeys: () => string[];\n /**\n * Delete all keys.\n */\n clearAll: () => void;\n /**\n * Sets (or updates) the encryption-key to encrypt all data in this MMKV instance with.\n *\n * To remove encryption, pass `undefined` as a key.\n *\n * Encryption keys can have a maximum length of 16 bytes.\n */\n recrypt: (key: string | undefined) => void;\n /**\n * Adds a value changed listener. The Listener will be called whenever any value\n * in this storage instance changes (set or delete).\n *\n * To unsubscribe from value changes, call `remove()` on the Listener.\n */\n addOnValueChangedListener: (\n onValueChanged: (key: string) => void\n ) => Listener;\n}\n\nexport type NativeMMKV = Pick<\n MMKVInterface,\n | 'clearAll'\n | 'contains'\n | 'delete'\n | 'getAllKeys'\n | 'getBoolean'\n | 'getNumber'\n | 'getString'\n | 'getBuffer'\n | 'set'\n | 'recrypt'\n>;\n\nconst onValueChangedListeners = new Map<string, ((key: string) => void)[]>();\n\n/**\n * A single MMKV instance.\n */\nexport class MMKV implements MMKVInterface {\n private nativeInstance: NativeMMKV;\n private functionCache: Partial<NativeMMKV>;\n private id: string;\n\n /**\n * Creates a new MMKV instance with the given Configuration.\n * If no custom `id` is supplied, `'mmkv.default'` will be used.\n */\n constructor(configuration: MMKVConfiguration = { id: 'mmkv.default' }) {\n this.id = configuration.id;\n this.nativeInstance = isJest()\n ? createMockMMKV()\n : createMMKV(configuration);\n this.functionCache = {};\n }\n\n private get onValueChangedListeners() {\n if (!onValueChangedListeners.has(this.id)) {\n onValueChangedListeners.set(this.id, []);\n }\n return onValueChangedListeners.get(this.id)!;\n }\n\n private getFunctionFromCache<T extends keyof NativeMMKV>(\n functionName: T\n ): NativeMMKV[T] {\n if (this.functionCache[functionName] == null) {\n this.functionCache[functionName] = this.nativeInstance[functionName];\n }\n return this.functionCache[functionName] as NativeMMKV[T];\n }\n\n private onValuesChanged(keys: string[]) {\n if (this.onValueChangedListeners.length === 0) return;\n\n for (const key of keys) {\n for (const listener of this.onValueChangedListeners) {\n listener(key);\n }\n }\n }\n\n set(key: string, value: boolean | string | number | Uint8Array): void {\n const func = this.getFunctionFromCache('set');\n func(key, value);\n\n this.onValuesChanged([key]);\n }\n getBoolean(key: string): boolean | undefined {\n const func = this.getFunctionFromCache('getBoolean');\n return func(key);\n }\n getString(key: string): string | undefined {\n const func = this.getFunctionFromCache('getString');\n return func(key);\n }\n getNumber(key: string): number | undefined {\n const func = this.getFunctionFromCache('getNumber');\n return func(key);\n }\n getBuffer(key: string): Uint8Array | undefined {\n const func = this.getFunctionFromCache('getBuffer');\n return func(key);\n }\n contains(key: string): boolean {\n const func = this.getFunctionFromCache('contains');\n return func(key);\n }\n delete(key: string): void {\n const func = this.getFunctionFromCache('delete');\n func(key);\n\n this.onValuesChanged([key]);\n }\n getAllKeys(): string[] {\n const func = this.getFunctionFromCache('getAllKeys');\n return func();\n }\n clearAll(): void {\n const keys = this.getAllKeys();\n\n const func = this.getFunctionFromCache('clearAll');\n func();\n\n this.onValuesChanged(keys);\n }\n recrypt(key: string | undefined): void {\n const func = this.getFunctionFromCache('recrypt');\n return func(key);\n }\n\n toString(): string {\n return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;\n }\n toJSON(): object {\n return {\n [this.id]: this.getAllKeys(),\n };\n }\n\n addOnValueChangedListener(onValueChanged: (key: string) => void): Listener {\n this.onValueChangedListeners.push(onValueChanged);\n\n return {\n remove: () => {\n const index = this.onValueChangedListeners.indexOf(onValueChanged);\n if (index !== -1) {\n this.onValueChangedListeners.splice(index, 1);\n }\n },\n };\n }\n}\n"]}
1
+ {"version":3,"names":["createMMKV","createMockMMKV","isJest","onValueChangedListeners","Map","MMKV","constructor","configuration","id","nativeInstance","functionCache","has","set","get","getFunctionFromCache","functionName","onValuesChanged","keys","length","key","listener","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,UAAU,QAAQ,cAAc;AACzC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,MAAM,QAAQ,mBAAmB;AA+H1C,MAAMC,uBAAuB,GAAG,IAAIC,GAAG,EAAqC;;AAE5E;AACA;AACA;AACA,OAAO,MAAMC,IAAI,CAA0B;EAKzC;AACF;AACA;AACA;EACEC,WAAW,GAA4D;IAAA,IAA3DC,aAAgC,uEAAG;MAAEC,EAAE,EAAE;IAAe,CAAC;IAAA;IAAA;IAAA;IACnE,IAAI,CAACA,EAAE,GAAGD,aAAa,CAACC,EAAE;IAC1B,IAAI,CAACC,cAAc,GAAGP,MAAM,EAAE,GAC1BD,cAAc,EAAE,GAChBD,UAAU,CAACO,aAAa,CAAC;IAC7B,IAAI,CAACG,aAAa,GAAG,CAAC,CAAC;EACzB;EAEA,IAAYP,uBAAuB,GAAG;IACpC,IAAI,CAACA,uBAAuB,CAACQ,GAAG,CAAC,IAAI,CAACH,EAAE,CAAC,EAAE;MACzCL,uBAAuB,CAACS,GAAG,CAAC,IAAI,CAACJ,EAAE,EAAE,EAAE,CAAC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Ac,CAAC;IAEjD,OAAO;MACLE,MAAM,EAAE,MAAM;QACZ,MAAMC,KAAK,GAAG,IAAI,CAACpC,uBAAuB,CAACqC,OAAO,CAACJ,cAAc,CAAC;QAClE,IAAIG,KAAK,KAAK,CAAC,CAAC,EAAE;UAChB,IAAI,CAACpC,uBAAuB,CAACsC,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;QAC/C;MACF;IACF,CAAC;EACH;AACF"}
@@ -3,7 +3,6 @@ export function isJest() {
3
3
  // In a WebBrowser/Electron the `process` variable does not exist
4
4
  return false;
5
5
  }
6
-
7
6
  return process.env.JEST_WORKER_ID != null;
8
7
  }
9
8
  //# sourceMappingURL=PlatformChecker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["PlatformChecker.ts"],"names":["isJest","global","process","env","JEST_WORKER_ID"],"mappings":"AAAA,OAAO,SAASA,MAAT,GAA2B;AAChC,MAAIC,MAAM,CAACC,OAAP,IAAkB,IAAtB,EAA4B;AAC1B;AACA,WAAO,KAAP;AACD;;AACD,SAAOA,OAAO,CAACC,GAAR,CAAYC,cAAZ,IAA8B,IAArC;AACD","sourcesContent":["export function isJest(): boolean {\n if (global.process == null) {\n // In a WebBrowser/Electron the `process` variable does not exist\n return false;\n }\n return process.env.JEST_WORKER_ID != null;\n}\n"]}
1
+ {"version":3,"names":["isJest","global","process","env","JEST_WORKER_ID"],"sourceRoot":"../../src","sources":["PlatformChecker.ts"],"mappings":"AAAA,OAAO,SAASA,MAAM,GAAY;EAChC,IAAIC,MAAM,CAACC,OAAO,IAAI,IAAI,EAAE;IAC1B;IACA,OAAO,KAAK;EACd;EACA,OAAOA,OAAO,CAACC,GAAG,CAACC,cAAc,IAAI,IAAI;AAC3C"}
@@ -6,24 +6,18 @@ export const createMMKV = config => {
6
6
  if (global.mmkvCreateNewInstance == null) {
7
7
  // Get the native MMKV ReactModule
8
8
  const MMKVModule = NativeModules.MMKV;
9
-
10
9
  if (MMKVModule == null) {
11
10
  var _NativeModules$Native, _NativeModules$Native2;
12
-
13
11
  let message = 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
14
12
  message += '\n* Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)';
15
-
16
13
  if (Platform.OS === 'ios' || Platform.OS === 'macos') {
17
14
  message += '\n* Make sure you ran `pod install` in the ios/ directory.';
18
15
  }
19
-
20
16
  if (Platform.OS === 'android') {
21
17
  message += '\n* Make sure gradle is synced.';
22
- } // check if Expo
23
-
24
-
18
+ }
19
+ // check if Expo
25
20
  const ExpoConstants = (_NativeModules$Native = NativeModules.NativeUnimoduleProxy) === null || _NativeModules$Native === void 0 ? void 0 : (_NativeModules$Native2 = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native2 === void 0 ? void 0 : _NativeModules$Native2.ExponentConstants;
26
-
27
21
  if (ExpoConstants != null) {
28
22
  if (ExpoConstants.appOwnership === 'expo') {
29
23
  // We're running Expo Go
@@ -33,23 +27,22 @@ export const createMMKV = config => {
33
27
  message += '\n* Make sure you ran `expo prebuild`.';
34
28
  }
35
29
  }
36
-
37
30
  message += '\n* Make sure you rebuilt the app.';
38
31
  throw new Error(message);
39
- } // Check if we are running on-device (JSI)
40
-
32
+ }
41
33
 
34
+ // Check if we are running on-device (JSI)
42
35
  if (global.nativeCallSyncHook == null || MMKVModule.install == null) {
43
36
  throw new Error('Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.');
44
- } // Call the synchronous blocking install() function
45
-
37
+ }
46
38
 
39
+ // Call the synchronous blocking install() function
47
40
  const result = MMKVModule.install(ROOT_DIRECTORY);
48
- if (result !== true) throw new Error(`Failed to create a new MMKV instance: The native MMKV Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`); // Check again if the constructor now exists. If not, throw an error.
41
+ if (result !== true) throw new Error(`Failed to create a new MMKV instance: The native MMKV Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`);
49
42
 
43
+ // Check again if the constructor now exists. If not, throw an error.
50
44
  if (global.mmkvCreateNewInstance == null) throw new Error('Failed to create a new MMKV instance, the native initializer function does not exist. Are you trying to use MMKV from different JS Runtimes?');
51
45
  }
52
-
53
46
  return global.mmkvCreateNewInstance(config);
54
47
  };
55
48
  //# sourceMappingURL=createMMKV.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["createMMKV.ts"],"names":["NativeModules","Platform","ROOT_DIRECTORY","createMMKV","config","global","mmkvCreateNewInstance","MMKVModule","MMKV","message","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,QAAxB,QAAwC,cAAxC;AASA;AACA,MAAMC,cAA6B,GAAG,IAAtC;AAEA,OAAO,MAAMC,UAAU,GAAIC,MAAD,IAA2C;AACnE;AACA,MAAIC,MAAM,CAACC,qBAAP,IAAgC,IAApC,EAA0C;AACxC;AACA,UAAMC,UAAU,GAAGP,aAAa,CAACQ,IAAjC;;AACA,QAAID,UAAU,IAAI,IAAlB,EAAwB;AAAA;;AACtB,UAAIE,OAAO,GACT,kFADF;AAEAA,MAAAA,OAAO,IACL,mGADF;;AAEA,UAAIR,QAAQ,CAACS,EAAT,KAAgB,KAAhB,IAAyBT,QAAQ,CAACS,EAAT,KAAgB,OAA7C,EAAsD;AACpDD,QAAAA,OAAO,IAAI,4DAAX;AACD;;AACD,UAAIR,QAAQ,CAACS,EAAT,KAAgB,SAApB,EAA+B;AAC7BD,QAAAA,OAAO,IAAI,iCAAX;AACD,OAVqB,CAWtB;;;AACA,YAAME,aAAa,4BACjBX,aAAa,CAACY,oBADG,oFACjB,sBAAoCC,gBADnB,2DACjB,uBAAsDC,iBADxD;;AAEA,UAAIH,aAAa,IAAI,IAArB,EAA2B;AACzB,YAAIA,aAAa,CAACI,YAAd,KAA+B,MAAnC,EAA2C;AACzC;AACA,gBAAM,IAAIC,KAAJ,CACJ,+GADI,CAAN;AAGD,SALD,MAKO;AACL;AACAP,UAAAA,OAAO,IAAI,wCAAX;AACD;AACF;;AAEDA,MAAAA,OAAO,IAAI,oCAAX;AACA,YAAM,IAAIO,KAAJ,CAAUP,OAAV,CAAN;AACD,KA/BuC,CAiCxC;;;AACA,QAAIJ,MAAM,CAACY,kBAAP,IAA6B,IAA7B,IAAqCV,UAAU,CAACW,OAAX,IAAsB,IAA/D,EAAqE;AACnE,YAAM,IAAIF,KAAJ,CACJ,sQADI,CAAN;AAGD,KAtCuC,CAwCxC;;;AACA,UAAMG,MAAM,GAAGZ,UAAU,CAACW,OAAX,CAAmBhB,cAAnB,CAAf;AACA,QAAIiB,MAAM,KAAK,IAAf,EACE,MAAM,IAAIH,KAAJ,CACH,sJAAqJG,MAAO,EADzJ,CAAN,CA3CsC,CA+CxC;;AACA,QAAId,MAAM,CAACC,qBAAP,IAAgC,IAApC,EACE,MAAM,IAAIU,KAAJ,CACJ,8IADI,CAAN;AAGH;;AAED,SAAOX,MAAM,CAACC,qBAAP,CAA6BF,MAA7B,CAAP;AACD,CAzDM","sourcesContent":["import { NativeModules, Platform } from 'react-native';\nimport type { MMKVConfiguration, NativeMMKV } from 'react-native-mmkv';\n\n// global func declaration for JSI functions\ndeclare global {\n function mmkvCreateNewInstance(configuration: MMKVConfiguration): NativeMMKV;\n function nativeCallSyncHook(): unknown;\n}\n\n// Root directory of all MMKV stores\nconst ROOT_DIRECTORY: string | null = null;\n\nexport const createMMKV = (config: MMKVConfiguration): NativeMMKV => {\n // Check if the constructor exists. If not, try installing the JSI bindings.\n if (global.mmkvCreateNewInstance == null) {\n // Get the native MMKV ReactModule\n const MMKVModule = NativeModules.MMKV;\n if (MMKVModule == null) {\n let message =\n 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';\n message +=\n '\\n* Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)';\n if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n message += '\\n* Make sure you ran `pod install` in the ios/ directory.';\n }\n if (Platform.OS === 'android') {\n message += '\\n* Make sure gradle is synced.';\n }\n // check if Expo\n const ExpoConstants =\n NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;\n if (ExpoConstants != null) {\n if (ExpoConstants.appOwnership === 'expo') {\n // We're running Expo Go\n throw new Error(\n 'react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'\n );\n } else {\n // We're running Expo bare / standalone\n message += '\\n* Make sure you ran `expo prebuild`.';\n }\n }\n\n message += '\\n* Make sure you rebuilt the app.';\n throw new Error(message);\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || MMKVModule.install == null) {\n throw new Error(\n 'Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = MMKVModule.install(ROOT_DIRECTORY);\n if (result !== true)\n throw new Error(\n `Failed to create a new MMKV instance: The native MMKV Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.mmkvCreateNewInstance == null)\n throw new Error(\n 'Failed to create a new MMKV instance, the native initializer function does not exist. Are you trying to use MMKV from different JS Runtimes?'\n );\n }\n\n return global.mmkvCreateNewInstance(config);\n};\n"]}
1
+ {"version":3,"names":["NativeModules","Platform","ROOT_DIRECTORY","createMMKV","config","global","mmkvCreateNewInstance","MMKVModule","MMKV","message","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result"],"sourceRoot":"../../src","sources":["createMMKV.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAStD;AACA,MAAMC,cAA6B,GAAG,IAAI;AAE1C,OAAO,MAAMC,UAAU,GAAIC,MAAyB,I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AACC,qBAAqB,CAACF,MAAM,CAAC;AAC7C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["createMMKV.mock.ts"],"names":["createMockMMKV","storage","Map","clearAll","clear","delete","key","set","value","getString","result","get","undefined","getNumber","getBoolean","getBuffer","Uint8Array","getAllKeys","Array","from","keys","contains","has","recrypt","console","warn"],"mappings":"AAEA;AACA,OAAO,MAAMA,cAAc,GAAG,MAAkB;AAC9C,QAAMC,OAAO,GAAG,IAAIC,GAAJ,EAAhB;AAEA,SAAO;AACLC,IAAAA,QAAQ,EAAE,MAAMF,OAAO,CAACG,KAAR,EADX;AAELC,IAAAA,MAAM,EAAGC,GAAD,IAASL,OAAO,CAACI,MAAR,CAAeC,GAAf,CAFZ;AAGLC,IAAAA,GAAG,EAAE,CAACD,GAAD,EAAME,KAAN,KAAgBP,OAAO,CAACM,GAAR,CAAYD,GAAZ,EAAiBE,KAAjB,CAHhB;AAILC,IAAAA,SAAS,EAAGH,GAAD,IAAS;AAClB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAO,OAAOI,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCE,SAA7C;AACD,KAPI;AAQLC,IAAAA,SAAS,EAAGP,GAAD,IAAS;AAClB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAO,OAAOI,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCE,SAA7C;AACD,KAXI;AAYLE,IAAAA,UAAU,EAAGR,GAAD,IAAS;AACnB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAO,OAAOI,MAAP,KAAkB,SAAlB,GAA8BA,MAA9B,GAAuCE,SAA9C;AACD,KAfI;AAgBLG,IAAAA,SAAS,EAAGT,GAAD,IAAS;AAClB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAOI,MAAM,YAAYM,UAAlB,GAA+BN,MAA/B,GAAwCE,SAA/C;AACD,KAnBI;AAoBLK,IAAAA,UAAU,EAAE,MAAMC,KAAK,CAACC,IAAN,CAAWlB,OAAO,CAACmB,IAAR,EAAX,CApBb;AAqBLC,IAAAA,QAAQ,EAAGf,GAAD,IAASL,OAAO,CAACqB,GAAR,CAAYhB,GAAZ,CArBd;AAsBLiB,IAAAA,OAAO,EAAE,MAAM;AACbC,MAAAA,OAAO,CAACC,IAAR,CAAa,uDAAb;AACD;AAxBI,GAAP;AA0BD,CA7BM","sourcesContent":["import type { NativeMMKV } from 'react-native-mmkv';\n\n/* Mock MMKV instance for use in tests */\nexport const createMockMMKV = (): NativeMMKV => {\n const storage = new Map<string, string | boolean | number | Uint8Array>();\n\n return {\n clearAll: () => storage.clear(),\n delete: (key) => storage.delete(key),\n set: (key, value) => storage.set(key, value),\n getString: (key) => {\n const result = storage.get(key);\n return typeof result === 'string' ? result : undefined;\n },\n getNumber: (key) => {\n const result = storage.get(key);\n return typeof result === 'number' ? result : undefined;\n },\n getBoolean: (key) => {\n const result = storage.get(key);\n return typeof result === 'boolean' ? result : undefined;\n },\n getBuffer: (key) => {\n const result = storage.get(key);\n return result instanceof Uint8Array ? result : undefined;\n },\n getAllKeys: () => Array.from(storage.keys()),\n contains: (key) => storage.has(key),\n recrypt: () => {\n console.warn('Encryption is not supported in mocked MMKV instances!');\n },\n };\n};\n"]}
1
+ {"version":3,"names":["createMockMMKV","storage","Map","clearAll","clear","delete","key","set","value","getString","result","get","undefined","getNumber","getBoolean","getBuffer","Uint8Array","getAllKeys","Array","from","keys","contains","has","recrypt","console","warn"],"sourceRoot":"../../src","sources":["createMMKV.mock.ts"],"mappings":"AAEA;AACA,OAAO,MAAMA,cAAc,GAAG,MAAkB;EAC9C,MAAMC,OAAO,GAAG,IAAIC,GAAG,EAAkD;EAEzE,OAAO;IACLC,QAAQ,EAAE,MAAMF,OAAO,CAACG,KAAK,EAAE;IAC/BC,MAAM,EAAGC,GAAG,IAAKL,OAAO,CAACI,MAAM,CAACC,GAAG,CAAC;IACpCC,GAAG,EAAE,CAACD,GAAG,EAAEE,KAAK,KAAKP,OAAO,CAACM,GAAG,CAACD,GAAG,EAAEE,KAAK,CAAC;IAC5CC,SAAS,EAAGH,GAAG,IAAK;MAClB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAO,OAAOI,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGE,SAAS;IACxD,CAAC;IACDC,SAAS,EAAGP,GAAG,IAAK;MAClB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAO,OAAOI,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGE,SAAS;IACxD,CAAC;IACDE,UAAU,EAAGR,GAAG,IAAK;MACnB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAO,OAAOI,MAAM,KAAK,SAAS,GAAGA,MAAM,GAAGE,SAAS;IACzD,CAAC;IACDG,SAAS,EAAGT,GAAG,IAAK;MAClB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAOI,MAAM,YAAYM,UAAU,GAAGN,MAAM,GAAGE,SAAS;IAC1D,CAAC;IACDK,UAAU,EAAE,MAAMC,KAAK,CAACC,IAAI,CAAClB,OAAO,CAACmB,IAAI,EAAE,CAAC;IAC5CC,QAAQ,EAAGf,GAAG,IAAKL,OAAO,CAACqB,GAAG,CAAChB,GAAG,CAAC;IACnCiB,OAAO,EAAE,MAAM;MACbC,OAAO,CAACC,IAAI,CAAC,uDAAuD,CAAC;IACvE;EACF,CAAC;AACH,CAAC"}
@@ -1,47 +1,35 @@
1
1
  var _window$document;
2
-
3
2
  /* global localStorage */
3
+
4
4
  import { createTextEncoder } from './createTextEncoder';
5
5
  const canUseDOM = typeof window !== 'undefined' && ((_window$document = window.document) === null || _window$document === void 0 ? void 0 : _window$document.createElement) != null;
6
6
  export const createMMKV = config => {
7
7
  if (config.id !== 'mmkv.default') {
8
8
  throw new Error("MMKV: 'id' is not supported on Web!");
9
9
  }
10
-
11
10
  if (config.encryptionKey != null) {
12
11
  throw new Error("MMKV: 'encryptionKey' is not supported on Web!");
13
12
  }
14
-
15
13
  if (config.path != null) {
16
14
  throw new Error("MMKV: 'path' is not supported on Web!");
17
15
  }
18
-
19
16
  const storage = () => {
20
- var _ref, _global$localStorage, _global, _window;
21
-
17
+ var _global, _window;
22
18
  if (!canUseDOM) {
23
19
  throw new Error('Tried to access storage on the server. Did you forget to call this in useEffect?');
24
20
  }
25
-
26
- const domStorage = (_ref = (_global$localStorage = (_global = global) === null || _global === void 0 ? void 0 : _global.localStorage) !== null && _global$localStorage !== void 0 ? _global$localStorage : (_window = window) === null || _window === void 0 ? void 0 : _window.localStorage) !== null && _ref !== void 0 ? _ref : localStorage;
27
-
21
+ const domStorage = ((_global = global) === null || _global === void 0 ? void 0 : _global.localStorage) ?? ((_window = window) === null || _window === void 0 ? void 0 : _window.localStorage) ?? localStorage;
28
22
  if (domStorage == null) {
29
23
  throw new Error(`Could not find 'localStorage' instance!`);
30
24
  }
31
-
32
25
  return domStorage;
33
26
  };
34
-
35
27
  const textEncoder = createTextEncoder();
36
28
  return {
37
29
  clearAll: () => storage().clear(),
38
30
  delete: key => storage().removeItem(key),
39
31
  set: (key, value) => storage().setItem(key, value.toString()),
40
- getString: key => {
41
- var _storage$getItem;
42
-
43
- return (_storage$getItem = storage().getItem(key)) !== null && _storage$getItem !== void 0 ? _storage$getItem : undefined;
44
- },
32
+ getString: key => storage().getItem(key) ?? undefined,
45
33
  getNumber: key => {
46
34
  const value = storage().getItem(key);
47
35
  if (value == null) return undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["createMMKV.web.ts"],"names":["createTextEncoder","canUseDOM","window","document","createElement","createMMKV","config","id","Error","encryptionKey","path","storage","domStorage","global","localStorage","textEncoder","clearAll","clear","delete","key","removeItem","set","value","setItem","toString","getString","getItem","undefined","getNumber","Number","getBoolean","getBuffer","encode","getAllKeys","Object","keys","contains","recrypt"],"mappings":";;AAAA;AAEA,SAASA,iBAAT,QAAkC,qBAAlC;AAEA,MAAMC,SAAS,GACb,OAAOC,MAAP,KAAkB,WAAlB,IAAiC,qBAAAA,MAAM,CAACC,QAAP,sEAAiBC,aAAjB,KAAkC,IADrE;AAGA,OAAO,MAAMC,UAAU,GAAIC,MAAD,IAA2C;AACnE,MAAIA,MAAM,CAACC,EAAP,KAAc,cAAlB,EAAkC;AAChC,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AACD,MAAIF,MAAM,CAACG,aAAP,IAAwB,IAA5B,EAAkC;AAChC,UAAM,IAAID,KAAJ,CAAU,gDAAV,CAAN;AACD;;AACD,MAAIF,MAAM,CAACI,IAAP,IAAe,IAAnB,EAAyB;AACvB,UAAM,IAAIF,KAAJ,CAAU,uCAAV,CAAN;AACD;;AAED,QAAMG,OAAO,GAAG,MAAM;AAAA;;AACpB,QAAI,CAACV,SAAL,EAAgB;AACd,YAAM,IAAIO,KAAJ,CACJ,kFADI,CAAN;AAGD;;AACD,UAAMI,UAAU,8CACdC,MADc,4CACd,QAAQC,YADM,kFACUZ,MADV,4CACU,QAAQY,YADlB,uCACkCA,YADlD;;AAEA,QAAIF,UAAU,IAAI,IAAlB,EAAwB;AACtB,YAAM,IAAIJ,KAAJ,CAAW,yCAAX,CAAN;AACD;;AACD,WAAOI,UAAP;AACD,GAZD;;AAcA,QAAMG,WAAW,GAAGf,iBAAiB,EAArC;AAEA,SAAO;AACLgB,IAAAA,QAAQ,EAAE,MAAML,OAAO,GAAGM,KAAV,EADX;AAELC,IAAAA,MAAM,EAAGC,GAAD,IAASR,OAAO,GAAGS,UAAV,CAAqBD,GAArB,CAFZ;AAGLE,IAAAA,GAAG,EAAE,CAACF,GAAD,EAAMG,KAAN,KAAgBX,OAAO,GAAGY,OAAV,CAAkBJ,GAAlB,EAAuBG,KAAK,CAACE,QAAN,EAAvB,CAHhB;AAILC,IAAAA,SAAS,EAAGN,GAAD;AAAA;;AAAA,iCAASR,OAAO,GAAGe,OAAV,CAAkBP,GAAlB,CAAT,+DAAmCQ,SAAnC;AAAA,KAJN;AAKLC,IAAAA,SAAS,EAAGT,GAAD,IAAS;AAClB,YAAMG,KAAK,GAAGX,OAAO,GAAGe,OAAV,CAAkBP,GAAlB,CAAd;AACA,UAAIG,KAAK,IAAI,IAAb,EAAmB,OAAOK,SAAP;AACnB,aAAOE,MAAM,CAACP,KAAD,CAAb;AACD,KATI;AAULQ,IAAAA,UAAU,EAAGX,GAAD,IAAS;AACnB,YAAMG,KAAK,GAAGX,OAAO,GAAGe,OAAV,CAAkBP,GAAlB,CAAd;AACA,UAAIG,KAAK,IAAI,IAAb,EAAmB,OAAOK,SAAP;AACnB,aAAOL,KAAK,KAAK,MAAjB;AACD,KAdI;AAeLS,IAAAA,SAAS,EAAGZ,GAAD,IAAS;AAClB,YAAMG,KAAK,GAAGX,OAAO,GAAGe,OAAV,CAAkBP,GAAlB,CAAd;AACA,UAAIG,KAAK,IAAI,IAAb,EAAmB,OAAOK,SAAP;AACnB,aAAOZ,WAAW,CAACiB,MAAZ,CAAmBV,KAAnB,CAAP;AACD,KAnBI;AAoBLW,IAAAA,UAAU,EAAE,MAAMC,MAAM,CAACC,IAAP,CAAYxB,OAAO,EAAnB,CApBb;AAqBLyB,IAAAA,QAAQ,EAAGjB,GAAD,IAASR,OAAO,GAAGe,OAAV,CAAkBP,GAAlB,KAA0B,IArBxC;AAsBLkB,IAAAA,OAAO,EAAE,MAAM;AACb,YAAM,IAAI7B,KAAJ,CAAU,wCAAV,CAAN;AACD;AAxBI,GAAP;AA0BD,CArDM","sourcesContent":["/* global localStorage */\nimport type { MMKVConfiguration, NativeMMKV } from 'react-native-mmkv';\nimport { createTextEncoder } from './createTextEncoder';\n\nconst canUseDOM =\n typeof window !== 'undefined' && window.document?.createElement != null;\n\nexport const createMMKV = (config: MMKVConfiguration): NativeMMKV => {\n if (config.id !== 'mmkv.default') {\n throw new Error(\"MMKV: 'id' is not supported on Web!\");\n }\n if (config.encryptionKey != null) {\n throw new Error(\"MMKV: 'encryptionKey' is not supported on Web!\");\n }\n if (config.path != null) {\n throw new Error(\"MMKV: 'path' is not supported on Web!\");\n }\n\n const storage = () => {\n if (!canUseDOM) {\n throw new Error(\n 'Tried to access storage on the server. Did you forget to call this in useEffect?'\n );\n }\n const domStorage =\n global?.localStorage ?? window?.localStorage ?? localStorage;\n if (domStorage == null) {\n throw new Error(`Could not find 'localStorage' instance!`);\n }\n return domStorage;\n };\n\n const textEncoder = createTextEncoder();\n\n return {\n clearAll: () => storage().clear(),\n delete: (key) => storage().removeItem(key),\n set: (key, value) => storage().setItem(key, value.toString()),\n getString: (key) => storage().getItem(key) ?? undefined,\n getNumber: (key) => {\n const value = storage().getItem(key);\n if (value == null) return undefined;\n return Number(value);\n },\n getBoolean: (key) => {\n const value = storage().getItem(key);\n if (value == null) return undefined;\n return value === 'true';\n },\n getBuffer: (key) => {\n const value = storage().getItem(key);\n if (value == null) return undefined;\n return textEncoder.encode(value);\n },\n getAllKeys: () => Object.keys(storage()),\n contains: (key) => storage().getItem(key) != null,\n recrypt: () => {\n throw new Error('`recrypt(..)` is not supported on Web!');\n },\n };\n};\n"]}
1
+ {"version":3,"names":["createTextEncoder","canUseDOM","window","document","createElement","createMMKV","config","id","Error","encryptionKey","path","storage","domStorage","global","localStorage","textEncoder","clearAll","clear","delete","key","removeItem","set","value","setItem","toString","getString","getItem","undefined","getNumber","Number","getBoolean","getBuffer","encode","getAllKeys","Object","keys","contains","recrypt"],"sourceRoot":"../../src","sources":["createMMKV.web.ts"],"mappings":";AAAA;;AAEA,SAASA,iBAAiB,QAAQ,qBAAqB;AAEvD,MAAMC,SAAS,GACb,OAAOC,MAAM,KAAK,WAAW,IAAI,qBAAAA,MAAM,CAACC,QAAQ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AC;MACpC,IAAIG,KAAK,IAAI,IAAI,EAAE,OAAOK,SAAS;MACnC,OAAOE,MAAM,CAACP,KAAK,CAAC;IACtB,CAAC;IACDQ,UAAU,EAAGX,GAAG,IAAK;MACnB,MAAMG,KAAK,GAAGX,OAAO,EAAE,CAACe,OAAO,CAACP,GAAG,CAAC;MACpC,IAAIG,KAAK,IAAI,IAAI,EAAE,OAAOK,SAAS;MACnC,OAAOL,KAAK,KAAK,MAAM;IACzB,CAAC;IACDS,SAAS,EAAGZ,GAAG,IAAK;MAClB,MAAMG,KAAK,GAAGX,OAAO,EAAE,CAACe,OAAO,CAACP,GAAG,CAAC;MACpC,IAAIG,KAAK,IAAI,IAAI,EAAE,OAAOK,SAAS;MACnC,OAAOZ,WAAW,CAACiB,MAAM,CAACV,KAAK,CAAC;IAClC,CAAC;IACDW,UAAU,EAAE,MAAMC,MAAM,CAACC,IAAI,CAACxB,OAAO,EAAE,CAAC;IACxCyB,QAAQ,EAAGjB,GAAG,IAAKR,OAAO,EAAE,CAACe,OAAO,CAACP,GAAG,CAAC,IAAI,IAAI;IACjDkB,OAAO,EAAE,MAAM;MACb,MAAM,IAAI7B,KAAK,CAAC,wCAAwC,CAAC;IAC3D;EACF,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["createTextEncoder.ts"],"names":["createTextEncoder","global","TextEncoder","encode","Error","encodeInto","encoding"],"mappings":"AAAA;AACA,OAAO,SAASA,iBAAT,GAA0C;AAC/C,MAAIC,MAAM,CAACC,WAAP,IAAsB,IAA1B,EAAgC;AAC9B,WAAO,IAAID,MAAM,CAACC,WAAX,EAAP;AACD,GAFD,MAEO;AACL,WAAO;AACLC,MAAAA,MAAM,EAAE,MAAM;AACZ,cAAM,IAAIC,KAAJ,CAAU,mDAAV,CAAN;AACD,OAHI;AAILC,MAAAA,UAAU,EAAE,MAAM;AAChB,cAAM,IAAID,KAAJ,CAAU,mDAAV,CAAN;AACD,OANI;AAOLE,MAAAA,QAAQ,EAAE;AAPL,KAAP;AASD;AACF","sourcesContent":["/* global TextEncoder */\nexport function createTextEncoder(): TextEncoder {\n if (global.TextEncoder != null) {\n return new global.TextEncoder();\n } else {\n return {\n encode: () => {\n throw new Error('TextEncoder is not supported in this environment!');\n },\n encodeInto: () => {\n throw new Error('TextEncoder is not supported in this environment!');\n },\n encoding: 'utf-8',\n };\n }\n}\n"]}
1
+ {"version":3,"names":["createTextEncoder","global","TextEncoder","encode","Error","encodeInto","encoding"],"sourceRoot":"../../src","sources":["createTextEncoder.ts"],"mappings":"AAAA;AACA,OAAO,SAASA,iBAAiB,GAAgB;EAC/C,IAAIC,MAAM,CAACC,WAAW,IAAI,IAAI,EAAE;IAC9B,OAAO,IAAID,MAAM,CAACC,WAAW,EAAE;EACjC,CAAC,MAAM;IACL,OAAO;MACLC,MAAM,EAAE,MAAM;QACZ,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;MACtE,CAAC;MACDC,UAAU,EAAE,MAAM;QAChB,MAAM,IAAID,KAAK,CAAC,mDAAmD,CAAC;MACtE,CAAC;MACDE,QAAQ,EAAE;IACZ,CAAC;EACH;AACF"}
@@ -1,68 +1,61 @@
1
1
  import { useRef, useState, useMemo, useCallback, useEffect } from 'react';
2
2
  import { MMKV } from './MMKV';
3
-
4
3
  function isConfigurationEqual(left, right) {
5
4
  if (left == null || right == null) return left == null && right == null;
6
5
  return left.encryptionKey === right.encryptionKey && left.id === right.id && left.path === right.path;
7
6
  }
8
-
9
7
  let defaultInstance = null;
10
-
11
8
  function getDefaultInstance() {
12
9
  if (defaultInstance == null) {
13
10
  defaultInstance = new MMKV();
14
11
  }
15
-
16
12
  return defaultInstance;
17
13
  }
14
+
18
15
  /**
19
16
  * Use the default, shared MMKV instance.
20
17
  */
21
18
 
22
-
23
19
  export function useMMKV(configuration) {
24
20
  const instance = useRef();
25
21
  const lastConfiguration = useRef();
26
22
  if (configuration == null) return getDefaultInstance();
27
-
28
23
  if (instance.current == null || !isConfigurationEqual(lastConfiguration.current, configuration)) {
29
24
  lastConfiguration.current = configuration;
30
25
  instance.current = new MMKV(configuration);
31
26
  }
32
-
33
27
  return instance.current;
34
28
  }
35
-
36
29
  function createMMKVHook(getter) {
37
30
  return (key, instance) => {
38
- const mmkv = instance !== null && instance !== void 0 ? instance : getDefaultInstance();
31
+ const mmkv = instance ?? getDefaultInstance();
39
32
  const [value, setValue] = useState(() => getter(mmkv, key));
40
33
  const valueRef = useRef(value);
41
- valueRef.current = value; // update value by user set
34
+ valueRef.current = value;
42
35
 
36
+ // update value by user set
43
37
  const set = useCallback(v => {
44
38
  const newValue = typeof v === 'function' ? v(valueRef.current) : v;
45
-
46
39
  switch (typeof newValue) {
47
40
  case 'number':
48
41
  case 'string':
49
42
  case 'boolean':
50
43
  mmkv.set(key, newValue);
51
44
  break;
52
-
53
45
  case 'undefined':
54
46
  mmkv.delete(key);
55
47
  break;
56
-
57
48
  default:
58
49
  throw new Error(`MMKV: Type ${typeof newValue} is not supported!`);
59
50
  }
60
- }, [key, mmkv]); // update value if key or instance changes
51
+ }, [key, mmkv]);
61
52
 
53
+ // update value if key or instance changes
62
54
  useEffect(() => {
63
55
  setValue(getter(mmkv, key));
64
- }, [key, mmkv]); // update value if it changes somewhere else (second hook, same key)
56
+ }, [key, mmkv]);
65
57
 
58
+ // update value if it changes somewhere else (second hook, same key)
66
59
  useEffect(() => {
67
60
  const listener = mmkv.addOnValueChangedListener(changedKey => {
68
61
  if (changedKey === key) {
@@ -74,6 +67,7 @@ function createMMKVHook(getter) {
74
67
  return [value, set];
75
68
  };
76
69
  }
70
+
77
71
  /**
78
72
  * Use the string value of the given `key` from the given MMKV storage instance.
79
73
  *
@@ -84,9 +78,8 @@ function createMMKVHook(getter) {
84
78
  * const [username, setUsername] = useMMKVString("user.name")
85
79
  * ```
86
80
  */
87
-
88
-
89
81
  export const useMMKVString = createMMKVHook((instance, key) => instance.getString(key));
82
+
90
83
  /**
91
84
  * Use the number value of the given `key` from the given MMKV storage instance.
92
85
  *
@@ -97,7 +90,6 @@ export const useMMKVString = createMMKVHook((instance, key) => instance.getStrin
97
90
  * const [age, setAge] = useMMKVNumber("user.age")
98
91
  * ```
99
92
  */
100
-
101
93
  export const useMMKVNumber = createMMKVHook((instance, key) => instance.getNumber(key));
102
94
  /**
103
95
  * Use the boolean value of the given `key` from the given MMKV storage instance.
@@ -109,7 +101,6 @@ export const useMMKVNumber = createMMKVHook((instance, key) => instance.getNumbe
109
101
  * const [isPremiumAccount, setIsPremiumAccount] = useMMKVBoolean("user.isPremium")
110
102
  * ```
111
103
  */
112
-
113
104
  export const useMMKVBoolean = createMMKVHook((instance, key) => instance.getBoolean(key));
114
105
  /**
115
106
  * Use the buffer value (unsigned 8-bit (0-255)) of the given `key` from the given MMKV storage instance.
@@ -121,7 +112,6 @@ export const useMMKVBoolean = createMMKVHook((instance, key) => instance.getBool
121
112
  * const [privateKey, setPrivateKey] = useMMKVBuffer("user.privateKey")
122
113
  * ```
123
114
  */
124
-
125
115
  export const useMMKVBuffer = createMMKVHook((instance, key) => instance.getBuffer(key));
126
116
  /**
127
117
  * Use an object value of the given `key` from the given MMKV storage instance.
@@ -135,7 +125,6 @@ export const useMMKVBuffer = createMMKVHook((instance, key) => instance.getBuffe
135
125
  * const [user, setUser] = useMMKVObject<User>("user")
136
126
  * ```
137
127
  */
138
-
139
128
  export function useMMKVObject(key, instance) {
140
129
  const [string, setString] = useMMKVString(key, instance);
141
130
  const value = useMemo(() => {
@@ -153,6 +142,7 @@ export function useMMKVObject(key, instance) {
153
142
  }, [setString]);
154
143
  return [value, setValue];
155
144
  }
145
+
156
146
  /**
157
147
  * Listen for changes in the given MMKV storage instance.
158
148
  * If no instance is passed, the default instance will be used.
@@ -166,11 +156,10 @@ export function useMMKVObject(key, instance) {
166
156
  * })
167
157
  * ```
168
158
  */
169
-
170
159
  export function useMMKVListener(valueChangedListener, instance) {
171
160
  const ref = useRef(valueChangedListener);
172
161
  ref.current = valueChangedListener;
173
- const mmkv = instance !== null && instance !== void 0 ? instance : getDefaultInstance();
162
+ const mmkv = instance ?? getDefaultInstance();
174
163
  useEffect(() => {
175
164
  const listener = mmkv.addOnValueChangedListener(changedKey => {
176
165
  ref.current(changedKey);