API symmetry when passing PerformanceEntryType to/from native module

Summary:
[Changelog][Internal]

`NativePerformanceObserver` TurboModule API would get the type for performance entries as strings in one direction (`start/stopReporting`) and as integers in another direction (inside `RawPerformanceEntry`, for optimization on the native side).

This makes is symmetrical and consistent, all the conversions are now handled on the JS side.

Reviewed By: christophpurrer

Differential Revision: D43236466

fbshipit-source-id: 08e1b62df90e6d26a11577d6b6b1d91a6bce8339
This commit is contained in:
Ruslan Shestopalyuk
2023-02-13 10:44:06 -08:00
committed by Facebook GitHub Bot
parent e168db4c3b
commit aef7194996
4 changed files with 34 additions and 24 deletions
@@ -10,19 +10,6 @@
namespace facebook::react {
static PerformanceEntryType stringToPerformanceEntryType(
const std::string &entryType) {
if (entryType == "mark") {
return PerformanceEntryType::MARK;
} else if (entryType == "measure") {
return PerformanceEntryType::MEASURE;
} else if (entryType == "event") {
return PerformanceEntryType::EVENT;
} else {
return PerformanceEntryType::UNDEFINED;
}
}
NativePerformanceObserver::NativePerformanceObserver(
std::shared_ptr<CallInvoker> jsInvoker)
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {
@@ -35,16 +22,16 @@ NativePerformanceObserver::~NativePerformanceObserver() {
void NativePerformanceObserver::startReporting(
jsi::Runtime &rt,
std::string entryType) {
int32_t entryType) {
PerformanceEntryReporter::getInstance().startReporting(
stringToPerformanceEntryType(entryType));
static_cast<PerformanceEntryType>(entryType));
}
void NativePerformanceObserver::stopReporting(
jsi::Runtime &rt,
std::string entryType) {
int32_t entryType) {
PerformanceEntryReporter::getInstance().stopReporting(
stringToPerformanceEntryType(entryType));
static_cast<PerformanceEntryType>(entryType));
}
GetPendingEntriesResult NativePerformanceObserver::popPendingEntries(