Skip to content

Commit 0471d6f

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/skippable-collection-member-ids
2 parents 192568b + 620fccf commit 0471d6f

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

lib/metrics.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import PerformanceProxy from './dependencies/PerformanceProxy';
22

3-
const decoratedAliases = new Set();
4-
53
/**
64
* Capture a measurement between the start mark and now
75
*/
@@ -21,11 +19,6 @@ function isPromiseLike(value: unknown): value is Promise<unknown> {
2119
* Wraps a function with metrics capturing logic
2220
*/
2321
function decorateWithMetrics<Args extends unknown[], ReturnType>(func: (...args: Args) => ReturnType, alias = func.name) {
24-
if (decoratedAliases.has(alias)) {
25-
throw new Error(`"${alias}" is already decorated`);
26-
}
27-
28-
decoratedAliases.add(alias);
2922
function decorated(...args: Args) {
3023
const mark = PerformanceProxy.mark(alias, {detail: {args, alias}});
3124

lib/useOnyx.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {deepEqual, shallowEqual} from 'fast-equals';
2-
import {useCallback, useEffect, useRef, useSyncExternalStore} from 'react';
2+
import {useCallback, useEffect, useMemo, useRef, useSyncExternalStore} from 'react';
33
import type {DependencyList} from 'react';
44
import OnyxCache, {TASK} from './OnyxCache';
55
import type {Connection} from './OnyxConnectionManager';
66
import connectionManager from './OnyxConnectionManager';
77
import OnyxUtils from './OnyxUtils';
8+
import * as GlobalSettings from './GlobalSettings';
89
import type {CollectionKeyBase, KeyValueMapping, OnyxCollection, OnyxKey, OnyxValue} from './types';
910
import useLiveRef from './useLiveRef';
1011
import usePrevious from './usePrevious';
12+
import decorateWithMetrics from './metrics';
1113

1214
type BaseUseOnyxOptions = {
1315
/**
@@ -144,7 +146,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
144146
// in `getSnapshot()` to be satisfied several times.
145147
const isFirstConnectionRef = useRef(true);
146148

147-
// Indicates if the hook is connecting to a Onyx key.
149+
// Indicates if the hook is connecting to an Onyx key.
148150
const isConnectingRef = useRef(false);
149151

150152
// Stores the `onStoreChange()` function, which can be used to trigger a `getSnapshot()` update when desired.
@@ -321,11 +323,19 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
321323
[key, options?.initWithStoredValues, options?.reuseConnection, checkEvictableKey],
322324
);
323325

326+
const getSnapshotDecorated = useMemo(() => {
327+
if (!GlobalSettings.isPerformanceMetricsEnabled()) {
328+
return getSnapshot;
329+
}
330+
331+
return decorateWithMetrics(getSnapshot, 'useOnyx.getSnapshot');
332+
}, [getSnapshot]);
333+
324334
useEffect(() => {
325335
checkEvictableKey();
326336
}, [checkEvictableKey]);
327337

328-
const result = useSyncExternalStore<UseOnyxResult<TReturnValue>>(subscribe, getSnapshot);
338+
const result = useSyncExternalStore<UseOnyxResult<TReturnValue>>(subscribe, getSnapshotDecorated);
329339

330340
return result;
331341
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-onyx",
3-
"version": "2.0.84",
3+
"version": "2.0.86",
44
"author": "Expensify, Inc.",
55
"homepage": "https://expensify.com",
66
"description": "State management for React Native",
@@ -25,7 +25,8 @@
2525
"README.md",
2626
"LICENSE.md"
2727
],
28-
"main": "lib/index.ts",
28+
"main": "dist/index.js",
29+
"types": "dist/index.d.ts",
2930
"scripts": {
3031
"lint": "eslint .",
3132
"typecheck": "tsc --noEmit",

0 commit comments

Comments
 (0)