From cd5730bc3f43b21c1367f078492829e54446f3f6 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Fri, 8 Sep 2023 15:05:34 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'Metrics' lib to TypeScript --- src/libs/Metrics/index.js | 8 -------- src/libs/Metrics/index.native.js | 17 ----------------- src/libs/Metrics/index.native.ts | 14 ++++++++++++++ src/libs/Metrics/index.ts | 9 +++++++++ src/libs/Metrics/types.ts | 6 ++++++ 5 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 src/libs/Metrics/index.js delete mode 100644 src/libs/Metrics/index.native.js create mode 100644 src/libs/Metrics/index.native.ts create mode 100644 src/libs/Metrics/index.ts create mode 100644 src/libs/Metrics/types.ts diff --git a/src/libs/Metrics/index.js b/src/libs/Metrics/index.js deleted file mode 100644 index 2c90f1c51b65..000000000000 --- a/src/libs/Metrics/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import CONFIG from '../../CONFIG'; - -// We don't capture performance metrics on web as there are enough tools available -const canCapturePerformanceMetrics = () => false; - -const canCaptureOnyxMetrics = () => Boolean(CONFIG.ONYX_METRICS); - -export {canCapturePerformanceMetrics, canCaptureOnyxMetrics}; diff --git a/src/libs/Metrics/index.native.js b/src/libs/Metrics/index.native.js deleted file mode 100644 index f57526e674ba..000000000000 --- a/src/libs/Metrics/index.native.js +++ /dev/null @@ -1,17 +0,0 @@ -import CONFIG from '../../CONFIG'; - -/** - * Is capturing performance stats enabled. - * - * @returns {Boolean} - */ -const canCapturePerformanceMetrics = () => CONFIG.CAPTURE_METRICS; - -/** - * Is capturing Onyx stats enabled. - * - * @returns {Boolean} - */ -const canCaptureOnyxMetrics = () => CONFIG.ONYX_METRICS; - -export {canCapturePerformanceMetrics, canCaptureOnyxMetrics}; diff --git a/src/libs/Metrics/index.native.ts b/src/libs/Metrics/index.native.ts new file mode 100644 index 000000000000..89de6218dd29 --- /dev/null +++ b/src/libs/Metrics/index.native.ts @@ -0,0 +1,14 @@ +import CONFIG from '../../CONFIG'; +import Metrics from './types'; + +/** + * Is capturing performance stats enabled. + */ +const canCapturePerformanceMetrics: Metrics['canCapturePerformanceMetrics'] = () => CONFIG.CAPTURE_METRICS; + +/** + * Is capturing Onyx stats enabled. + */ +const canCaptureOnyxMetrics: Metrics['canCaptureOnyxMetrics'] = () => CONFIG.ONYX_METRICS; + +export {canCapturePerformanceMetrics, canCaptureOnyxMetrics}; diff --git a/src/libs/Metrics/index.ts b/src/libs/Metrics/index.ts new file mode 100644 index 000000000000..b3b1ed3cb5e0 --- /dev/null +++ b/src/libs/Metrics/index.ts @@ -0,0 +1,9 @@ +import CONFIG from '../../CONFIG'; +import Metrics from './types'; + +// We don't capture performance metrics on web as there are enough tools available +const canCapturePerformanceMetrics: Metrics['canCapturePerformanceMetrics'] = () => false; + +const canCaptureOnyxMetrics: Metrics['canCaptureOnyxMetrics'] = () => CONFIG.ONYX_METRICS; + +export {canCapturePerformanceMetrics, canCaptureOnyxMetrics}; diff --git a/src/libs/Metrics/types.ts b/src/libs/Metrics/types.ts new file mode 100644 index 000000000000..8ac360b3655d --- /dev/null +++ b/src/libs/Metrics/types.ts @@ -0,0 +1,6 @@ +type Metrics = { + canCapturePerformanceMetrics: () => boolean; + canCaptureOnyxMetrics: () => boolean; +}; + +export default Metrics; From b023871c9727014325d9dd1829675c5666a3d687 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 12 Sep 2023 11:35:27 +0200 Subject: [PATCH 2/2] Adjust how type is defined --- src/libs/Metrics/index.native.ts | 6 +++--- src/libs/Metrics/index.ts | 6 +++--- src/libs/Metrics/types.ts | 8 +++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/libs/Metrics/index.native.ts b/src/libs/Metrics/index.native.ts index 89de6218dd29..526e5c57a269 100644 --- a/src/libs/Metrics/index.native.ts +++ b/src/libs/Metrics/index.native.ts @@ -1,14 +1,14 @@ import CONFIG from '../../CONFIG'; -import Metrics from './types'; +import {CanCaptureOnyxMetrics, CanCapturePerformanceMetrics} from './types'; /** * Is capturing performance stats enabled. */ -const canCapturePerformanceMetrics: Metrics['canCapturePerformanceMetrics'] = () => CONFIG.CAPTURE_METRICS; +const canCapturePerformanceMetrics: CanCapturePerformanceMetrics = () => CONFIG.CAPTURE_METRICS; /** * Is capturing Onyx stats enabled. */ -const canCaptureOnyxMetrics: Metrics['canCaptureOnyxMetrics'] = () => CONFIG.ONYX_METRICS; +const canCaptureOnyxMetrics: CanCaptureOnyxMetrics = () => CONFIG.ONYX_METRICS; export {canCapturePerformanceMetrics, canCaptureOnyxMetrics}; diff --git a/src/libs/Metrics/index.ts b/src/libs/Metrics/index.ts index b3b1ed3cb5e0..7c33f31cb19e 100644 --- a/src/libs/Metrics/index.ts +++ b/src/libs/Metrics/index.ts @@ -1,9 +1,9 @@ import CONFIG from '../../CONFIG'; -import Metrics from './types'; +import {CanCaptureOnyxMetrics, CanCapturePerformanceMetrics} from './types'; // We don't capture performance metrics on web as there are enough tools available -const canCapturePerformanceMetrics: Metrics['canCapturePerformanceMetrics'] = () => false; +const canCapturePerformanceMetrics: CanCapturePerformanceMetrics = () => false; -const canCaptureOnyxMetrics: Metrics['canCaptureOnyxMetrics'] = () => CONFIG.ONYX_METRICS; +const canCaptureOnyxMetrics: CanCaptureOnyxMetrics = () => CONFIG.ONYX_METRICS; export {canCapturePerformanceMetrics, canCaptureOnyxMetrics}; diff --git a/src/libs/Metrics/types.ts b/src/libs/Metrics/types.ts index 8ac360b3655d..61b1400ae9f8 100644 --- a/src/libs/Metrics/types.ts +++ b/src/libs/Metrics/types.ts @@ -1,6 +1,4 @@ -type Metrics = { - canCapturePerformanceMetrics: () => boolean; - canCaptureOnyxMetrics: () => boolean; -}; +type CanCapturePerformanceMetrics = () => boolean; +type CanCaptureOnyxMetrics = () => boolean; -export default Metrics; +export type {CanCapturePerformanceMetrics, CanCaptureOnyxMetrics};