react-native-onyx 3.0.54 → 3.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -53
- package/dist/Onyx.d.ts +1 -1
- package/dist/Onyx.js +1 -26
- package/dist/OnyxUtils.js +0 -46
- package/dist/storage/index.js +0 -19
- package/dist/types.d.ts +0 -5
- package/dist/useOnyx.js +1 -9
- package/package.json +2 -7
- package/dist/GlobalSettings.d.ts +0 -11
- package/dist/GlobalSettings.js +0 -29
- package/dist/dependencies/ModuleProxy.d.ts +0 -10
- package/dist/dependencies/ModuleProxy.js +0 -37
- package/dist/dependencies/PerformanceProxy/index.d.ts +0 -1
- package/dist/dependencies/PerformanceProxy/index.js +0 -4
- package/dist/dependencies/PerformanceProxy/index.native.d.ts +0 -20
- package/dist/dependencies/PerformanceProxy/index.native.js +0 -12
- package/dist/metrics.d.ts +0 -8
- package/dist/metrics.js +0 -47
package/README.md
CHANGED
|
@@ -351,59 +351,6 @@ const ReportActionsView = ({reportID, isActiveReport}) => {
|
|
|
351
351
|
export default ReportActionsView;
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
-
# Benchmarks
|
|
355
|
-
|
|
356
|
-
Provide the `captureMetrics` boolean flag to `Onyx.init` to capture call statistics
|
|
357
|
-
|
|
358
|
-
```js
|
|
359
|
-
Onyx.init({
|
|
360
|
-
keys: ONYXKEYS,
|
|
361
|
-
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
|
|
362
|
-
captureMetrics: Config.BENCHMARK_ONYX,
|
|
363
|
-
});
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
At any point you can get the collected statistics using `Onyx.getMetrics()`.
|
|
367
|
-
This will return an object containing `totalTime`, `averageTime` and `summaries`.
|
|
368
|
-
`summaries` is a collection of statistics for each method it contains data about:
|
|
369
|
-
- method name
|
|
370
|
-
- total, max, min, average times for this method calls
|
|
371
|
-
- calls - a list of individual calls with each having: start time; end time; call duration; call arguments
|
|
372
|
-
- start/end times are relative to application launch time - 0.00 being exactly at launch
|
|
373
|
-
|
|
374
|
-
If you wish to reset the metrics and start over use `Onyx.resetMetrics()`
|
|
375
|
-
|
|
376
|
-
Finally, there's a `Onyx.printMetrics()` method which prints human statistics information on the dev console. You can use this method during debugging. For example add an `Onyx.printMetrics()` line somewhere in code or call it through the dev console. It supports 3 popular formats *MD* - human friendly markdown, *CSV* and *JSON*. The default is MD if you want to print another format call `Onyx.printMetrics({ format: 'csv' })` or
|
|
377
|
-
`Onyx.printMetrics({ format: 'json' })`.
|
|
378
|
-
|
|
379
|
-
Sample output of `Onyx.printMetrics()`
|
|
380
|
-
|
|
381
|
-
```
|
|
382
|
-
### Onyx Benchmark
|
|
383
|
-
- Total: 1.5min
|
|
384
|
-
- Last call finished at: 12.55sec
|
|
385
|
-
|
|
386
|
-
| method | total time spent | max | min | avg | time last call completed | calls made |
|
|
387
|
-
|-----------------|-----------------:|----------:|---------:|----------:|-------------------------:|-----------:|
|
|
388
|
-
| Onyx:getAllKeys | 1.2min | 2.16sec | 0.159ms | 782.230ms | 12.55sec | 90 |
|
|
389
|
-
| Onyx:merge | 4.73sec | 2.00sec | 74.412ms | 591.642ms | 10.24sec | 8 |
|
|
390
|
-
| Onyx:set | 3.90sec | 846.760ms | 43.663ms | 433.056ms | 7.47sec | 9 |
|
|
391
|
-
| Onyx:get | 8.87sec | 2.00sec | 0.063ms | 61.998ms | 10.24sec | 143 |
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
| Onyx:set |
|
|
395
|
-
|---------------------------------------------------------------|
|
|
396
|
-
| start time | end time | duration | args |
|
|
397
|
-
|-----------:|----------:|----------:|--------------------------|
|
|
398
|
-
| 291.042ms | 553.079ms | 262.037ms | session, [object Object] |
|
|
399
|
-
| 293.719ms | 553.316ms | 259.597ms | account, [object Object] |
|
|
400
|
-
| 294.541ms | 553.651ms | 259.109ms | network, [object Object] |
|
|
401
|
-
| 365.378ms | 554.246ms | 188.867ms | iou, [object Object] |
|
|
402
|
-
| 1.08sec | 2.20sec | 1.12sec | network, [object Object] |
|
|
403
|
-
| 1.08sec | 2.20sec | 1.12sec | iou, [object Object] |
|
|
404
|
-
| 1.17sec | 2.20sec | 1.03sec | currentURL, / |
|
|
405
|
-
```
|
|
406
|
-
|
|
407
354
|
# Debug mode
|
|
408
355
|
|
|
409
356
|
It can be useful to log why Onyx is calling `setState()` on a particular React component so that we can understand which key changed, what changed about the value, and the connected component that ultimately rendered as a result. When used correctly this can help isolate problem areas and unnecessary renders in the code. To enable this feature, pass `debugSetState: true` to the config and grep JS console logs for `[Onyx-Debug]`.
|
package/dist/Onyx.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as Logger from './Logger';
|
|
|
2
2
|
import type { CollectionKeyBase, ConnectOptions, InitOptions, OnyxKey, OnyxMergeCollectionInput, OnyxSetCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate, SetOptions } from './types';
|
|
3
3
|
import type { Connection } from './OnyxConnectionManager';
|
|
4
4
|
/** Initialize the store with actions and listening for storage events */
|
|
5
|
-
declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances,
|
|
5
|
+
declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances, enableDevTools, skippableCollectionMemberIDs, ramOnlyKeys, snapshotMergeKeys, }: InitOptions): void;
|
|
6
6
|
/**
|
|
7
7
|
* Connects to an Onyx key given the options passed and listens to its changes.
|
|
8
8
|
* This method will be deprecated soon. Please use `Onyx.connectWithoutView()` instead.
|
package/dist/Onyx.js
CHANGED
|
@@ -45,16 +45,10 @@ const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
|
|
|
45
45
|
const OnyxKeys_1 = __importDefault(require("./OnyxKeys"));
|
|
46
46
|
const logMessages_1 = __importDefault(require("./logMessages"));
|
|
47
47
|
const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
|
|
48
|
-
const GlobalSettings = __importStar(require("./GlobalSettings"));
|
|
49
|
-
const metrics_1 = __importDefault(require("./metrics"));
|
|
50
48
|
const OnyxMerge_1 = __importDefault(require("./OnyxMerge"));
|
|
51
49
|
/** Initialize the store with actions and listening for storage events */
|
|
52
|
-
function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = !!global.localStorage,
|
|
50
|
+
function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = !!global.localStorage, enableDevTools = true, skippableCollectionMemberIDs = [], ramOnlyKeys = [], snapshotMergeKeys = [], }) {
|
|
53
51
|
var _a;
|
|
54
|
-
if (enablePerformanceMetrics) {
|
|
55
|
-
GlobalSettings.setPerformanceMetricsEnabled(true);
|
|
56
|
-
applyDecorators();
|
|
57
|
-
}
|
|
58
52
|
(0, DevTools_1.initDevTools)(enableDevTools);
|
|
59
53
|
storage_1.default.init();
|
|
60
54
|
OnyxUtils_1.default.setSkippableCollectionMemberIDs(new Set(skippableCollectionMemberIDs));
|
|
@@ -549,23 +543,4 @@ const Onyx = {
|
|
|
549
543
|
init,
|
|
550
544
|
registerLogger: Logger.registerLogger,
|
|
551
545
|
};
|
|
552
|
-
function applyDecorators() {
|
|
553
|
-
// We are reassigning the functions directly so that internal function calls are also decorated
|
|
554
|
-
// @ts-expect-error Reassign
|
|
555
|
-
connect = (0, metrics_1.default)(connect, 'Onyx.connect');
|
|
556
|
-
// @ts-expect-error Reassign
|
|
557
|
-
connectWithoutView = (0, metrics_1.default)(connectWithoutView, 'Onyx.connectWithoutView');
|
|
558
|
-
// @ts-expect-error Reassign
|
|
559
|
-
set = (0, metrics_1.default)(set, 'Onyx.set');
|
|
560
|
-
// @ts-expect-error Reassign
|
|
561
|
-
multiSet = (0, metrics_1.default)(multiSet, 'Onyx.multiSet');
|
|
562
|
-
// @ts-expect-error Reassign
|
|
563
|
-
merge = (0, metrics_1.default)(merge, 'Onyx.merge');
|
|
564
|
-
// @ts-expect-error Reassign
|
|
565
|
-
mergeCollection = (0, metrics_1.default)(mergeCollection, 'Onyx.mergeCollection');
|
|
566
|
-
// @ts-expect-error Reassign
|
|
567
|
-
update = (0, metrics_1.default)(update, 'Onyx.update');
|
|
568
|
-
// @ts-expect-error Reassign
|
|
569
|
-
clear = (0, metrics_1.default)(clear, 'Onyx.clear');
|
|
570
|
-
}
|
|
571
546
|
exports.default = Onyx;
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -47,8 +47,6 @@ const Str = __importStar(require("./Str"));
|
|
|
47
47
|
const storage_1 = __importDefault(require("./storage"));
|
|
48
48
|
const utils_1 = __importDefault(require("./utils"));
|
|
49
49
|
const createDeferredTask_1 = __importDefault(require("./createDeferredTask"));
|
|
50
|
-
const GlobalSettings = __importStar(require("./GlobalSettings"));
|
|
51
|
-
const metrics_1 = __importDefault(require("./metrics"));
|
|
52
50
|
const logMessages_1 = __importDefault(require("./logMessages"));
|
|
53
51
|
// Method constants
|
|
54
52
|
const METHOD = {
|
|
@@ -1469,48 +1467,4 @@ const OnyxUtils = {
|
|
|
1469
1467
|
multiSetWithRetry,
|
|
1470
1468
|
setCollectionWithRetry,
|
|
1471
1469
|
};
|
|
1472
|
-
GlobalSettings.addGlobalSettingsChangeListener(({ enablePerformanceMetrics }) => {
|
|
1473
|
-
if (!enablePerformanceMetrics) {
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
// We are reassigning the functions directly so that internal function calls are also decorated
|
|
1477
|
-
// @ts-expect-error Reassign
|
|
1478
|
-
initStoreValues = (0, metrics_1.default)(initStoreValues, 'OnyxUtils.initStoreValues');
|
|
1479
|
-
// @ts-expect-error Complex type signature
|
|
1480
|
-
get = (0, metrics_1.default)(get, 'OnyxUtils.get');
|
|
1481
|
-
// @ts-expect-error Reassign
|
|
1482
|
-
getAllKeys = (0, metrics_1.default)(getAllKeys, 'OnyxUtils.getAllKeys');
|
|
1483
|
-
// @ts-expect-error Reassign
|
|
1484
|
-
keysChanged = (0, metrics_1.default)(keysChanged, 'OnyxUtils.keysChanged');
|
|
1485
|
-
// @ts-expect-error Reassign
|
|
1486
|
-
keyChanged = (0, metrics_1.default)(keyChanged, 'OnyxUtils.keyChanged');
|
|
1487
|
-
// @ts-expect-error Reassign
|
|
1488
|
-
sendDataToConnection = (0, metrics_1.default)(sendDataToConnection, 'OnyxUtils.sendDataToConnection');
|
|
1489
|
-
// @ts-expect-error Reassign
|
|
1490
|
-
scheduleSubscriberUpdate = (0, metrics_1.default)(scheduleSubscriberUpdate, 'OnyxUtils.scheduleSubscriberUpdate');
|
|
1491
|
-
// @ts-expect-error Reassign
|
|
1492
|
-
scheduleNotifyCollectionSubscribers = (0, metrics_1.default)(scheduleNotifyCollectionSubscribers, 'OnyxUtils.scheduleNotifyCollectionSubscribers');
|
|
1493
|
-
// @ts-expect-error Reassign
|
|
1494
|
-
remove = (0, metrics_1.default)(remove, 'OnyxUtils.remove');
|
|
1495
|
-
// @ts-expect-error Reassign
|
|
1496
|
-
reportStorageQuota = (0, metrics_1.default)(reportStorageQuota, 'OnyxUtils.reportStorageQuota');
|
|
1497
|
-
// @ts-expect-error Complex type signature
|
|
1498
|
-
retryOperation = (0, metrics_1.default)(retryOperation, 'OnyxUtils.retryOperation');
|
|
1499
|
-
// @ts-expect-error Reassign
|
|
1500
|
-
broadcastUpdate = (0, metrics_1.default)(broadcastUpdate, 'OnyxUtils.broadcastUpdate');
|
|
1501
|
-
// @ts-expect-error Reassign
|
|
1502
|
-
initializeWithDefaultKeyStates = (0, metrics_1.default)(initializeWithDefaultKeyStates, 'OnyxUtils.initializeWithDefaultKeyStates');
|
|
1503
|
-
// @ts-expect-error Complex type signature
|
|
1504
|
-
multiGet = (0, metrics_1.default)(multiGet, 'OnyxUtils.multiGet');
|
|
1505
|
-
// @ts-expect-error Reassign
|
|
1506
|
-
tupleGet = (0, metrics_1.default)(tupleGet, 'OnyxUtils.tupleGet');
|
|
1507
|
-
// @ts-expect-error Reassign
|
|
1508
|
-
subscribeToKey = (0, metrics_1.default)(subscribeToKey, 'OnyxUtils.subscribeToKey');
|
|
1509
|
-
// @ts-expect-error Reassign
|
|
1510
|
-
setWithRetry = (0, metrics_1.default)(setWithRetry, 'OnyxUtils.setWithRetry');
|
|
1511
|
-
// @ts-expect-error Reassign
|
|
1512
|
-
multiSetWithRetry = (0, metrics_1.default)(multiSetWithRetry, 'OnyxUtils.multiSetWithRetry');
|
|
1513
|
-
// @ts-expect-error Reassign
|
|
1514
|
-
setCollectionWithRetry = (0, metrics_1.default)(setCollectionWithRetry, 'OnyxUtils.setCollectionWithRetry');
|
|
1515
|
-
});
|
|
1516
1470
|
exports.default = OnyxUtils;
|
package/dist/storage/index.js
CHANGED
|
@@ -40,8 +40,6 @@ const Logger = __importStar(require("../Logger"));
|
|
|
40
40
|
const platforms_1 = __importDefault(require("./platforms"));
|
|
41
41
|
const InstanceSync_1 = __importDefault(require("./InstanceSync"));
|
|
42
42
|
const MemoryOnlyProvider_1 = __importDefault(require("./providers/MemoryOnlyProvider"));
|
|
43
|
-
const GlobalSettings = __importStar(require("../GlobalSettings"));
|
|
44
|
-
const metrics_1 = __importDefault(require("../metrics"));
|
|
45
43
|
let provider = platforms_1.default;
|
|
46
44
|
let shouldKeepInstancesSync = false;
|
|
47
45
|
let finishInitalization;
|
|
@@ -200,21 +198,4 @@ const storage = {
|
|
|
200
198
|
InstanceSync_1.default.init(onStorageKeyChanged, this);
|
|
201
199
|
},
|
|
202
200
|
};
|
|
203
|
-
GlobalSettings.addGlobalSettingsChangeListener(({ enablePerformanceMetrics }) => {
|
|
204
|
-
if (!enablePerformanceMetrics) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
// Apply decorators
|
|
208
|
-
storage.getItem = (0, metrics_1.default)(storage.getItem, 'Storage.getItem');
|
|
209
|
-
storage.multiGet = (0, metrics_1.default)(storage.multiGet, 'Storage.multiGet');
|
|
210
|
-
storage.setItem = (0, metrics_1.default)(storage.setItem, 'Storage.setItem');
|
|
211
|
-
storage.multiSet = (0, metrics_1.default)(storage.multiSet, 'Storage.multiSet');
|
|
212
|
-
storage.mergeItem = (0, metrics_1.default)(storage.mergeItem, 'Storage.mergeItem');
|
|
213
|
-
storage.multiMerge = (0, metrics_1.default)(storage.multiMerge, 'Storage.multiMerge');
|
|
214
|
-
storage.removeItem = (0, metrics_1.default)(storage.removeItem, 'Storage.removeItem');
|
|
215
|
-
storage.removeItems = (0, metrics_1.default)(storage.removeItems, 'Storage.removeItems');
|
|
216
|
-
storage.clear = (0, metrics_1.default)(storage.clear, 'Storage.clear');
|
|
217
|
-
storage.getAllKeys = (0, metrics_1.default)(storage.getAllKeys, 'Storage.getAllKeys');
|
|
218
|
-
storage.getAll = (0, metrics_1.default)(storage.getAll, 'Storage.getAll');
|
|
219
|
-
});
|
|
220
201
|
exports.default = storage;
|
package/dist/types.d.ts
CHANGED
|
@@ -348,11 +348,6 @@ type InitOptions = {
|
|
|
348
348
|
* of Onyx running in different tabs/windows. Defaults to true for platforms that support local storage (web/desktop)
|
|
349
349
|
*/
|
|
350
350
|
shouldSyncMultipleInstances?: boolean;
|
|
351
|
-
/**
|
|
352
|
-
* If enabled it will use the performance API to measure the time taken by Onyx operations.
|
|
353
|
-
* @default false
|
|
354
|
-
*/
|
|
355
|
-
enablePerformanceMetrics?: boolean;
|
|
356
351
|
/**
|
|
357
352
|
* If enabled, it will connect to Redux DevTools Extension for debugging.
|
|
358
353
|
* This allows you to see all Onyx state changes in the Redux DevTools.
|
package/dist/useOnyx.js
CHANGED
|
@@ -42,9 +42,7 @@ const OnyxCache_1 = __importStar(require("./OnyxCache"));
|
|
|
42
42
|
const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
|
|
43
43
|
const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
|
|
44
44
|
const OnyxKeys_1 = __importDefault(require("./OnyxKeys"));
|
|
45
|
-
const GlobalSettings = __importStar(require("./GlobalSettings"));
|
|
46
45
|
const usePrevious_1 = __importDefault(require("./usePrevious"));
|
|
47
|
-
const metrics_1 = __importDefault(require("./metrics"));
|
|
48
46
|
const OnyxSnapshotCache_1 = __importDefault(require("./OnyxSnapshotCache"));
|
|
49
47
|
const useLiveRef_1 = __importDefault(require("./useLiveRef"));
|
|
50
48
|
function useOnyx(key, options, dependencies = []) {
|
|
@@ -266,16 +264,10 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
266
264
|
onStoreChangeFnRef.current = null;
|
|
267
265
|
};
|
|
268
266
|
}, [key, options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.reuseConnection, checkEvictableKey]);
|
|
269
|
-
const getSnapshotDecorated = (0, react_1.useMemo)(() => {
|
|
270
|
-
if (!GlobalSettings.isPerformanceMetricsEnabled()) {
|
|
271
|
-
return getSnapshot;
|
|
272
|
-
}
|
|
273
|
-
return (0, metrics_1.default)(getSnapshot, 'useOnyx.getSnapshot');
|
|
274
|
-
}, [getSnapshot]);
|
|
275
267
|
(0, react_1.useEffect)(() => {
|
|
276
268
|
checkEvictableKey();
|
|
277
269
|
}, [checkEvictableKey]);
|
|
278
|
-
const result = (0, react_1.useSyncExternalStore)(subscribe,
|
|
270
|
+
const result = (0, react_1.useSyncExternalStore)(subscribe, getSnapshot);
|
|
279
271
|
return result;
|
|
280
272
|
}
|
|
281
273
|
exports.default = useOnyx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-onyx",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.55",
|
|
4
4
|
"author": "Expensify, Inc.",
|
|
5
5
|
"homepage": "https://expensify.com",
|
|
6
6
|
"description": "State management for React Native",
|
|
@@ -93,7 +93,6 @@
|
|
|
93
93
|
"react-native-device-info": "^10.3.0",
|
|
94
94
|
"react-native-nitro-modules": "^0.27.2",
|
|
95
95
|
"react-native-nitro-sqlite": "^9.2.0",
|
|
96
|
-
"react-native-performance": "^5.1.0",
|
|
97
96
|
"react-test-renderer": "18.2.0",
|
|
98
97
|
"reassure": "1.4.0",
|
|
99
98
|
"ts-node": "^10.9.2",
|
|
@@ -106,16 +105,12 @@
|
|
|
106
105
|
"react-native": ">=0.75.0",
|
|
107
106
|
"react-native-device-info": "^10.3.0",
|
|
108
107
|
"react-native-nitro-modules": ">=0.27.2",
|
|
109
|
-
"react-native-nitro-sqlite": "^9.2.0"
|
|
110
|
-
"react-native-performance": ">=5.1.0"
|
|
108
|
+
"react-native-nitro-sqlite": "^9.2.0"
|
|
111
109
|
},
|
|
112
110
|
"peerDependenciesMeta": {
|
|
113
111
|
"idb-keyval": {
|
|
114
112
|
"optional": true
|
|
115
113
|
},
|
|
116
|
-
"react-native-performance": {
|
|
117
|
-
"optional": true
|
|
118
|
-
},
|
|
119
114
|
"react-native-nitro-modules": {
|
|
120
115
|
"optional": true
|
|
121
116
|
},
|
package/dist/GlobalSettings.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stores settings from Onyx.init globally so they can be made accessible by other parts of the library.
|
|
3
|
-
*/
|
|
4
|
-
declare const globalSettings: {
|
|
5
|
-
enablePerformanceMetrics: boolean;
|
|
6
|
-
};
|
|
7
|
-
type GlobalSettings = typeof globalSettings;
|
|
8
|
-
declare function addGlobalSettingsChangeListener(listener: (settings: GlobalSettings) => unknown): () => void;
|
|
9
|
-
declare function setPerformanceMetricsEnabled(enabled: boolean): void;
|
|
10
|
-
declare function isPerformanceMetricsEnabled(): boolean;
|
|
11
|
-
export { setPerformanceMetricsEnabled, isPerformanceMetricsEnabled, addGlobalSettingsChangeListener };
|
package/dist/GlobalSettings.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Stores settings from Onyx.init globally so they can be made accessible by other parts of the library.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setPerformanceMetricsEnabled = setPerformanceMetricsEnabled;
|
|
7
|
-
exports.isPerformanceMetricsEnabled = isPerformanceMetricsEnabled;
|
|
8
|
-
exports.addGlobalSettingsChangeListener = addGlobalSettingsChangeListener;
|
|
9
|
-
const globalSettings = {
|
|
10
|
-
enablePerformanceMetrics: false,
|
|
11
|
-
};
|
|
12
|
-
const listeners = new Set();
|
|
13
|
-
function addGlobalSettingsChangeListener(listener) {
|
|
14
|
-
listeners.add(listener);
|
|
15
|
-
return () => {
|
|
16
|
-
listeners.delete(listener);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function notifyListeners() {
|
|
20
|
-
for (const listener of listeners)
|
|
21
|
-
listener(globalSettings);
|
|
22
|
-
}
|
|
23
|
-
function setPerformanceMetricsEnabled(enabled) {
|
|
24
|
-
globalSettings.enablePerformanceMetrics = enabled;
|
|
25
|
-
notifyListeners();
|
|
26
|
-
}
|
|
27
|
-
function isPerformanceMetricsEnabled() {
|
|
28
|
-
return globalSettings.enablePerformanceMetrics;
|
|
29
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type ImportType = ReturnType<typeof require>;
|
|
2
|
-
/**
|
|
3
|
-
* Create a lazily-imported module proxy.
|
|
4
|
-
* This is useful for lazily requiring optional dependencies.
|
|
5
|
-
*/
|
|
6
|
-
declare const createModuleProxy: <TModule>(getModule: () => ImportType) => TModule;
|
|
7
|
-
declare class OptionalDependencyNotInstalledError extends Error {
|
|
8
|
-
constructor(name: string);
|
|
9
|
-
}
|
|
10
|
-
export { createModuleProxy, OptionalDependencyNotInstalledError };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OptionalDependencyNotInstalledError = exports.createModuleProxy = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Create a lazily-imported module proxy.
|
|
6
|
-
* This is useful for lazily requiring optional dependencies.
|
|
7
|
-
*/
|
|
8
|
-
const createModuleProxy = (getModule) => {
|
|
9
|
-
const holder = { module: undefined };
|
|
10
|
-
const proxy = new Proxy(holder, {
|
|
11
|
-
get: (target, property) => {
|
|
12
|
-
if (property === '$$typeof') {
|
|
13
|
-
// If inlineRequires is enabled, Metro will look up all imports
|
|
14
|
-
// with the $$typeof operator. In this case, this will throw the
|
|
15
|
-
// `OptionalDependencyNotInstalledError` error because we try to access the module
|
|
16
|
-
// even though we are not using it (Metro does it), so instead we return undefined
|
|
17
|
-
// to bail out of inlineRequires here.
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
if (target.module == null) {
|
|
21
|
-
// lazy initialize module via require()
|
|
22
|
-
// caller needs to make sure the require() call is wrapped in a try/catch
|
|
23
|
-
// eslint-disable-next-line no-param-reassign
|
|
24
|
-
target.module = getModule();
|
|
25
|
-
}
|
|
26
|
-
return target.module[property];
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
return proxy;
|
|
30
|
-
};
|
|
31
|
-
exports.createModuleProxy = createModuleProxy;
|
|
32
|
-
class OptionalDependencyNotInstalledError extends Error {
|
|
33
|
-
constructor(name) {
|
|
34
|
-
super(`${name} is not installed!`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.OptionalDependencyNotInstalledError = OptionalDependencyNotInstalledError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default performance;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
declare const PerformanceProxy: {
|
|
2
|
-
timeOrigin: number;
|
|
3
|
-
now: () => number;
|
|
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
|
-
metric: (name: string, valueOrOptions: import("react-native-performance/lib/typescript/performance").ValueOrOptions) => import("react-native-performance").PerformanceMetric;
|
|
9
|
-
clearMetrics: (name?: string) => void;
|
|
10
|
-
getEntries: () => import("react-native-performance").PerformanceEntry[];
|
|
11
|
-
getEntriesByName: (name: string, type?: import("react-native-performance").EntryType) => import("react-native-performance").PerformanceEntry[];
|
|
12
|
-
getEntriesByType: {
|
|
13
|
-
(type: "measure"): import("react-native-performance").PerformanceMeasure[];
|
|
14
|
-
(type: "mark"): import("react-native-performance").PerformanceMark[];
|
|
15
|
-
(type: "resource"): import("react-native-performance").PerformanceResourceTiming[];
|
|
16
|
-
(type: "metric"): import("react-native-performance").PerformanceMetric[];
|
|
17
|
-
(type: "react-native-mark"): import("react-native-performance").PerformanceReactNativeMark[];
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export default PerformanceProxy;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ModuleProxy_1 = require("../ModuleProxy");
|
|
4
|
-
const PerformanceProxy = (0, ModuleProxy_1.createModuleProxy)(() => {
|
|
5
|
-
try {
|
|
6
|
-
return require('react-native-performance').default;
|
|
7
|
-
}
|
|
8
|
-
catch (_a) {
|
|
9
|
-
throw new ModuleProxy_1.OptionalDependencyNotInstalledError('react-native-performance');
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
exports.default = PerformanceProxy;
|
package/dist/metrics.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps a function with metrics capturing logic
|
|
3
|
-
*/
|
|
4
|
-
declare function decorateWithMetrics<Args extends unknown[], ReturnType>(func: (...args: Args) => ReturnType, alias?: string): {
|
|
5
|
-
(...args: Args): ReturnType;
|
|
6
|
-
name: string;
|
|
7
|
-
};
|
|
8
|
-
export default decorateWithMetrics;
|
package/dist/metrics.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const PerformanceProxy_1 = __importDefault(require("./dependencies/PerformanceProxy"));
|
|
7
|
-
/**
|
|
8
|
-
* Capture a measurement between the start mark and now
|
|
9
|
-
*/
|
|
10
|
-
function measureMarkToNow(startMark, detail) {
|
|
11
|
-
PerformanceProxy_1.default.measure(`${startMark.name} [${startMark.detail.args.toString()}]`, {
|
|
12
|
-
start: startMark.startTime,
|
|
13
|
-
end: PerformanceProxy_1.default.now(),
|
|
14
|
-
detail: Object.assign(Object.assign({}, startMark.detail), detail),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function isPromiseLike(value) {
|
|
18
|
-
return value != null && typeof value === 'object' && 'then' in value;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Wraps a function with metrics capturing logic
|
|
22
|
-
*/
|
|
23
|
-
function decorateWithMetrics(func, alias = func.name) {
|
|
24
|
-
function decorated(...args) {
|
|
25
|
-
const mark = PerformanceProxy_1.default.mark(alias, { detail: { args, alias } });
|
|
26
|
-
const originalReturnValue = func(...args);
|
|
27
|
-
if (isPromiseLike(originalReturnValue)) {
|
|
28
|
-
/*
|
|
29
|
-
* The handlers added here are not affecting the original promise
|
|
30
|
-
* They create a separate chain that's not exposed (returned) to the original caller
|
|
31
|
-
*/
|
|
32
|
-
originalReturnValue
|
|
33
|
-
.then((result) => {
|
|
34
|
-
measureMarkToNow(mark, { result });
|
|
35
|
-
})
|
|
36
|
-
.catch((error) => {
|
|
37
|
-
measureMarkToNow(mark, { error });
|
|
38
|
-
});
|
|
39
|
-
return originalReturnValue;
|
|
40
|
-
}
|
|
41
|
-
measureMarkToNow(mark, { result: originalReturnValue });
|
|
42
|
-
return originalReturnValue;
|
|
43
|
-
}
|
|
44
|
-
decorated.name = `${alias}_DECORATED`;
|
|
45
|
-
return decorated;
|
|
46
|
-
}
|
|
47
|
-
exports.default = decorateWithMetrics;
|