react-native-onyx 2.0.128 → 2.0.130

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.
@@ -3,7 +3,9 @@
3
3
  * Stores settings from Onyx.init globally so they can be made accessible by other parts of the library.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addGlobalSettingsChangeListener = exports.isPerformanceMetricsEnabled = exports.setPerformanceMetricsEnabled = void 0;
6
+ exports.setPerformanceMetricsEnabled = setPerformanceMetricsEnabled;
7
+ exports.isPerformanceMetricsEnabled = isPerformanceMetricsEnabled;
8
+ exports.addGlobalSettingsChangeListener = addGlobalSettingsChangeListener;
7
9
  const globalSettings = {
8
10
  enablePerformanceMetrics: false,
9
11
  };
@@ -14,7 +16,6 @@ function addGlobalSettingsChangeListener(listener) {
14
16
  listeners.delete(listener);
15
17
  };
16
18
  }
17
- exports.addGlobalSettingsChangeListener = addGlobalSettingsChangeListener;
18
19
  function notifyListeners() {
19
20
  listeners.forEach((listener) => listener(globalSettings));
20
21
  }
@@ -22,8 +23,6 @@ function setPerformanceMetricsEnabled(enabled) {
22
23
  globalSettings.enablePerformanceMetrics = enabled;
23
24
  notifyListeners();
24
25
  }
25
- exports.setPerformanceMetricsEnabled = setPerformanceMetricsEnabled;
26
26
  function isPerformanceMetricsEnabled() {
27
27
  return globalSettings.enablePerformanceMetrics;
28
28
  }
29
- exports.isPerformanceMetricsEnabled = isPerformanceMetricsEnabled;
package/dist/Logger.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logHmmm = exports.logAlert = exports.logInfo = exports.registerLogger = void 0;
3
+ exports.registerLogger = registerLogger;
4
+ exports.logInfo = logInfo;
5
+ exports.logAlert = logAlert;
6
+ exports.logHmmm = logHmmm;
4
7
  // eslint-disable-next-line @typescript-eslint/no-empty-function
5
8
  let logger = () => { };
6
9
  /**
@@ -9,25 +12,21 @@ let logger = () => { };
9
12
  function registerLogger(callback) {
10
13
  logger = callback;
11
14
  }
12
- exports.registerLogger = registerLogger;
13
15
  /**
14
16
  * Send an alert message to the logger
15
17
  */
16
18
  function logAlert(message, parameters) {
17
19
  logger({ message: `[Onyx] ${message}`, level: 'alert', parameters });
18
20
  }
19
- exports.logAlert = logAlert;
20
21
  /**
21
22
  * Send an info message to the logger
22
23
  */
23
24
  function logInfo(message, parameters) {
24
25
  logger({ message: `[Onyx] ${message}`, level: 'info', parameters });
25
26
  }
26
- exports.logInfo = logInfo;
27
27
  /**
28
28
  * Send an hmmm message to the logger
29
29
  */
30
30
  function logHmmm(message, parameters) {
31
31
  logger({ message: `[Onyx] ${message}`, level: 'hmmm', parameters });
32
32
  }
33
- exports.logHmmm = logHmmm;
package/dist/Onyx.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
package/dist/OnyxCache.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
package/dist/OnyxUtils.js CHANGED
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.clearOnyxUtilsInternals = void 0;
39
+ exports.clearOnyxUtilsInternals = clearOnyxUtilsInternals;
30
40
  /* eslint-disable no-continue */
31
41
  const fast_equals_1 = require("fast-equals");
32
42
  const clone_1 = __importDefault(require("lodash/clone"));
@@ -1350,7 +1360,6 @@ function clearOnyxUtilsInternals() {
1350
1360
  batchUpdatesQueue = [];
1351
1361
  lastConnectionCallbackData = new Map();
1352
1362
  }
1353
- exports.clearOnyxUtilsInternals = clearOnyxUtilsInternals;
1354
1363
  const OnyxUtils = {
1355
1364
  METHOD,
1356
1365
  getMergeQueue,
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setShouldDebugSetState = exports.logSetStateCall = void 0;
6
+ exports.logSetStateCall = logSetStateCall;
7
+ exports.setShouldDebugSetState = setShouldDebugSetState;
7
8
  const transform_1 = __importDefault(require("lodash/transform"));
8
9
  const fast_equals_1 = require("fast-equals");
9
10
  let debugSetState = false;
10
11
  function setShouldDebugSetState(debug) {
11
12
  debugSetState = debug;
12
13
  }
13
- exports.setShouldDebugSetState = setShouldDebugSetState;
14
14
  /**
15
15
  * Deep diff between two objects. Useful for figuring out what changed about an object from one render to the next so
16
16
  * that state and props updates can be optimized.
@@ -50,4 +50,3 @@ function logSetStateCall(mapping, previousValue, newValue, caller, keyThatChange
50
50
  }
51
51
  console.debug(`[Onyx-Debug] ${'displayName' in mapping && mapping.displayName} setState() called. Subscribed to key '${mapping.key}' (${caller})`, logParams);
52
52
  }
53
- exports.logSetStateCall = logSetStateCall;
package/dist/Str.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startsWith = exports.result = exports.guid = void 0;
3
+ exports.guid = guid;
4
+ exports.result = result;
5
+ exports.startsWith = startsWith;
4
6
  /**
5
7
  * Returns true if the haystack begins with the needle
6
8
  *
@@ -11,11 +13,9 @@ exports.startsWith = exports.result = exports.guid = void 0;
11
13
  function startsWith(haystack, needle) {
12
14
  return typeof haystack === 'string' && typeof needle === 'string' && haystack.startsWith(needle);
13
15
  }
14
- exports.startsWith = startsWith;
15
16
  function result(parameter, ...args) {
16
17
  return typeof parameter === 'function' ? parameter(...args) : parameter;
17
18
  }
18
- exports.result = result;
19
19
  /**
20
20
  * A simple GUID generator taken from https://stackoverflow.com/a/32760401/9114791
21
21
  */
@@ -27,4 +27,3 @@ function guid() {
27
27
  }
28
28
  return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
29
29
  }
30
- exports.guid = guid;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = createDeferredTask;
3
4
  /**
4
5
  * Create a deferred task that can be resolved when we call `resolve()`
5
6
  * The returned promise will complete when we call `resolve`
@@ -12,4 +13,3 @@ function createDeferredTask() {
12
13
  });
13
14
  return deferred;
14
15
  }
15
- exports.default = createDeferredTask;
@@ -1,14 +1,14 @@
1
1
  declare const PerformanceProxy: {
2
2
  timeOrigin: number;
3
3
  now: () => number;
4
- mark: (markName: string, markOptions?: import("react-native-performance/lib/typescript/performance").MarkOptions | undefined) => import("react-native-performance").PerformanceMark;
5
- clearMarks: (name?: string | undefined) => void;
6
- measure: (measureName: string, startOrMeasureOptions?: import("react-native-performance/lib/typescript/performance").StartOrMeasureOptions, endMark?: string | number | undefined) => import("react-native-performance").PerformanceMeasure;
7
- clearMeasures: (name?: string | undefined) => void;
4
+ mark: (markName: string, markOptions?: import("react-native-performance/lib/typescript/performance").MarkOptions) => import("react-native-performance").PerformanceMark;
5
+ clearMarks: (name?: string) => void;
6
+ measure: (measureName: string, startOrMeasureOptions?: import("react-native-performance/lib/typescript/performance").StartOrMeasureOptions, endMark?: string | number) => import("react-native-performance").PerformanceMeasure;
7
+ clearMeasures: (name?: string) => void;
8
8
  metric: (name: string, valueOrOptions: import("react-native-performance/lib/typescript/performance").ValueOrOptions) => import("react-native-performance").PerformanceMetric;
9
- clearMetrics: (name?: string | undefined) => void;
9
+ clearMetrics: (name?: string) => void;
10
10
  getEntries: () => import("react-native-performance").PerformanceEntry[];
11
- getEntriesByName: (name: string, type?: import("react-native-performance").EntryType | undefined) => import("react-native-performance").PerformanceEntry[];
11
+ getEntriesByName: (name: string, type?: import("react-native-performance").EntryType) => import("react-native-performance").PerformanceEntry[];
12
12
  getEntriesByType: {
13
13
  (type: "measure"): import("react-native-performance").PerformanceMeasure[];
14
14
  (type: "mark"): import("react-native-performance").PerformanceMark[];
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  declare const StorageMock: {
3
2
  init: jest.Mock<void, [], any>;
4
3
  getItem: jest.Mock<Promise<unknown>, [key: any], any>;
@@ -16,7 +15,7 @@ declare const StorageMock: {
16
15
  bytesRemaining: number;
17
16
  }>, [], any>;
18
17
  keepInstancesSync: jest.Mock<any, any, any>;
19
- mockSet: (key: string, value: unknown) => Promise<unknown>;
18
+ mockSet: (key: import("../..").OnyxKey, value: import("../..").OnyxValue<import("../..").OnyxKey>) => Promise<unknown>;
20
19
  getMockStore: jest.Mock<{
21
20
  [x: string]: unknown;
22
21
  }, [], any>;
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  const MemoryOnlyProvider_1 = __importStar(require("../providers/MemoryOnlyProvider"));
27
37
  const init = jest.fn(MemoryOnlyProvider_1.default.init);
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * Creates a mutable reference to a value, useful when you need to
4
3
  * maintain a reference to a value that may change over time without triggering re-renders.
package/dist/useOnyx.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -32,15 +42,33 @@ const OnyxCache_1 = __importStar(require("./OnyxCache"));
32
42
  const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
33
43
  const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
34
44
  const GlobalSettings = __importStar(require("./GlobalSettings"));
35
- const useLiveRef_1 = __importDefault(require("./useLiveRef"));
36
45
  const usePrevious_1 = __importDefault(require("./usePrevious"));
37
46
  const metrics_1 = __importDefault(require("./metrics"));
38
47
  const Logger = __importStar(require("./Logger"));
39
48
  function useOnyx(key, options, dependencies = []) {
40
49
  const connectionRef = (0, react_1.useRef)(null);
41
50
  const previousKey = (0, usePrevious_1.default)(key);
42
- // Used to stabilize the selector reference and avoid unnecessary calls to `getSnapshot()`.
43
- const selectorRef = (0, useLiveRef_1.default)(options === null || options === void 0 ? void 0 : options.selector);
51
+ // Create memoized version of selector for performance
52
+ const memoizedSelector = (0, react_1.useMemo)(() => {
53
+ if (!(options === null || options === void 0 ? void 0 : options.selector))
54
+ return null;
55
+ let lastInput;
56
+ let lastOutput;
57
+ let hasComputed = false;
58
+ return (input) => {
59
+ // Always recompute when input changes
60
+ if (!hasComputed || lastInput !== input) {
61
+ const newOutput = options.selector(input);
62
+ // Deep equality mode: only update if output actually changed
63
+ if (!hasComputed || !(0, fast_equals_1.deepEqual)(lastOutput, newOutput)) {
64
+ lastInput = input;
65
+ lastOutput = newOutput;
66
+ hasComputed = true;
67
+ }
68
+ }
69
+ return lastOutput;
70
+ };
71
+ }, [options === null || options === void 0 ? void 0 : options.selector]);
44
72
  // Stores the previous cached value as it's necessary to compare with the new value in `getSnapshot()`.
45
73
  // We initialize it to `null` to simulate that we don't have any value from cache yet.
46
74
  const previousValueRef = (0, react_1.useRef)(null);
@@ -110,7 +138,7 @@ function useOnyx(key, options, dependencies = []) {
110
138
  }
111
139
  }, [key, options === null || options === void 0 ? void 0 : options.canEvict]);
112
140
  const getSnapshot = (0, react_1.useCallback)(() => {
113
- var _a, _b, _c;
141
+ var _a, _b, _c, _d;
114
142
  let isOnyxValueDefined = true;
115
143
  // We return the initial result right away during the first connection if `initWithStoredValues` is set to `false`.
116
144
  if (isFirstConnectionRef.current && (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false) {
@@ -122,7 +150,7 @@ function useOnyx(key, options, dependencies = []) {
122
150
  if (isFirstConnectionRef.current || shouldGetCachedValueRef.current) {
123
151
  // Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility.
124
152
  const value = OnyxUtils_1.default.tryGetCachedValue(key);
125
- const selectedValue = selectorRef.current ? selectorRef.current(value) : value;
153
+ const selectedValue = memoizedSelector ? memoizedSelector(value) : value;
126
154
  newValueRef.current = (selectedValue !== null && selectedValue !== void 0 ? selectedValue : undefined);
127
155
  // This flag is `false` when the original Onyx value (without selector) is not defined yet.
128
156
  // It will be used later to check if we need to log an alert that the value is missing.
@@ -141,15 +169,18 @@ function useOnyx(key, options, dependencies = []) {
141
169
  newValueRef.current = undefined;
142
170
  newFetchStatus = 'loading';
143
171
  }
144
- // We do a deep equality check if `selector` is defined, since each `tryGetCachedValue()` call will
145
- // generate a plain new primitive/object/array that was created using the `selector` function.
146
- // For the other cases we will only deal with object reference checks, so just a shallow equality check is enough.
172
+ // Optimized equality checking - eliminated redundant deep equality:
173
+ // - Memoized selectors already handle deep equality internally, so we can use fast reference equality
174
+ // - Non-selector cases use shallow equality for object reference checks
175
+ // - Normalize null to undefined to ensure consistent comparison (both represent "no value")
147
176
  let areValuesEqual;
148
- if (selectorRef.current) {
149
- areValuesEqual = (0, fast_equals_1.deepEqual)((_a = previousValueRef.current) !== null && _a !== void 0 ? _a : undefined, newValueRef.current);
177
+ if (memoizedSelector) {
178
+ const normalizedPrevious = (_a = previousValueRef.current) !== null && _a !== void 0 ? _a : undefined;
179
+ const normalizedNew = (_b = newValueRef.current) !== null && _b !== void 0 ? _b : undefined;
180
+ areValuesEqual = normalizedPrevious === normalizedNew;
150
181
  }
151
182
  else {
152
- areValuesEqual = (0, fast_equals_1.shallowEqual)((_b = previousValueRef.current) !== null && _b !== void 0 ? _b : undefined, newValueRef.current);
183
+ areValuesEqual = (0, fast_equals_1.shallowEqual)((_c = previousValueRef.current) !== null && _c !== void 0 ? _c : undefined, newValueRef.current);
153
184
  }
154
185
  // We update the cached value and the result in the following conditions:
155
186
  // We will update the cached value and the result in any of the following situations:
@@ -163,7 +194,7 @@ function useOnyx(key, options, dependencies = []) {
163
194
  // If the new value is `null` we default it to `undefined` to ensure the consumer gets a consistent result from the hook.
164
195
  const newStatus = newFetchStatus !== null && newFetchStatus !== void 0 ? newFetchStatus : 'loaded';
165
196
  resultRef.current = [
166
- (_c = previousValueRef.current) !== null && _c !== void 0 ? _c : undefined,
197
+ (_d = previousValueRef.current) !== null && _d !== void 0 ? _d : undefined,
167
198
  {
168
199
  status: newStatus,
169
200
  sourceValue: sourceValueRef.current,
@@ -177,7 +208,7 @@ function useOnyx(key, options, dependencies = []) {
177
208
  }
178
209
  }
179
210
  return resultRef.current;
180
- }, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key, selectorRef]);
211
+ }, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key, memoizedSelector]);
181
212
  const subscribe = (0, react_1.useCallback)((onStoreChange) => {
182
213
  isConnectingRef.current = true;
183
214
  onStoreChangeFnRef.current = onStoreChange;
@@ -15,17 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = default_1;
29
40
  /**
30
41
  * This is a higher order component that provides the ability to map a state property directly to
31
42
  * something in Onyx (a key/value store). That way, as soon as data in Onyx changes, the state will be set and the view
@@ -309,4 +320,3 @@ function default_1(mapOnyxToState, shouldDelayUpdates = false) {
309
320
  });
310
321
  };
311
322
  }
312
- exports.default = default_1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.128",
3
+ "version": "2.0.130",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -126,7 +126,7 @@
126
126
  }
127
127
  },
128
128
  "engines": {
129
- "node": ">=20.19.1",
129
+ "node": ">=20.19.3",
130
130
  "npm": ">=10.8.2"
131
131
  },
132
132
  "sideEffects": false