Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Migrate 'Firebase' lib to TypeScript #27661

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
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};