Skip to content

Commit

Permalink
Merge pull request #27661 from kubabutkiewicz/ts-migration/Firebase-lib
Browse files Browse the repository at this point in the history
[No QA] [TS migration] Migrate 'Firebase' lib to TypeScript
  • Loading branch information
madmax330 authored Sep 22, 2023
2 parents f39184e + 1e7af0f commit 2a5ea63
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
6 changes: 0 additions & 6 deletions src/libs/Firebase/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* eslint-disable no-unused-vars */
import perf from '@react-native-firebase/perf';
import lodashGet from 'lodash/get';
import * as Environment from '../Environment/Environment';
import Log from '../Log';
import {StartTrace, StopTrace, TraceMap} from './types';

const traceMap = {};
const traceMap: TraceMap = {};

/**
* @param {String} customEventName
*/
function startTrace(customEventName) {
const startTrace: StartTrace = (customEventName) => {
const start = global.performance.now();
if (Environment.isDevelopment()) {
return;
Expand All @@ -27,18 +23,16 @@ function startTrace(customEventName) {
start,
};
});
}
};

/**
* @param {String} customEventName
*/
function stopTrace(customEventName) {
const stop = global.performance.now();
const stopTrace: StopTrace = (customEventName) => {
// Uncomment to inspect logs on release builds
// const stop = global.performance.now();
if (Environment.isDevelopment()) {
return;
}

const trace = lodashGet(traceMap, [customEventName, 'trace']);
const trace = traceMap[customEventName].trace;
if (!trace) {
return;
}
Expand All @@ -50,7 +44,7 @@ function stopTrace(customEventName) {
// Log.info(`sidebar_loaded: ${stop - start} ms`, true);

delete traceMap[customEventName];
}
};

export default {
startTrace,
Expand Down
10 changes: 10 additions & 0 deletions src/libs/Firebase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {StartTrace, StopTrace} from './types';

/** Web does not use Firebase for performance tracing */
const startTrace: StartTrace = () => {};
const stopTrace: StopTrace = () => {};

export default {
startTrace,
stopTrace,
};
11 changes: 11 additions & 0 deletions src/libs/Firebase/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {FirebasePerformanceTypes} from '@react-native-firebase/perf';

type Trace = {
trace: FirebasePerformanceTypes.Trace;
start: number;
};
type TraceMap = Record<string, Trace>;
type StartTrace = (customEventName: string) => void;
type StopTrace = (customEventName: string) => void;

export type {StartTrace, StopTrace, TraceMap};

0 comments on commit 2a5ea63

Please sign in to comment.