Add flow typing to QuickPerformanceLogger

Reviewed By: cwdick

Differential Revision: D6613292

fbshipit-source-id: 58e41507a3c7cf9fbc6b972e327ae76d294d6807
This commit is contained in:
Alexey Lang 2018-01-22 05:19:19 -08:00 committed by Facebook Github Bot
parent 5e11b8870a
commit bcfbdf4fbe

View File

@ -7,83 +7,83 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule QuickPerformanceLogger
* @flow
*/
'use strict';
var fixOpts = function(opts) {
var AUTO_SET_TIMESTAMP = -1;
var DUMMY_INSTANCE_KEY = 0;
opts = opts || {};
opts.instanceKey = opts.instanceKey || DUMMY_INSTANCE_KEY;
opts.timestamp = opts.timestamp || AUTO_SET_TIMESTAMP;
return opts;
};
const AUTO_SET_TIMESTAMP = -1;
const DUMMY_INSTANCE_KEY = 0;
var QuickPerformanceLogger = {
markerStart(markerId, opts) {
if (typeof markerId !== 'number') {
return;
}
const QuickPerformanceLogger = {
markerStart(
markerId: number,
instanceKey: number = DUMMY_INSTANCE_KEY,
timestamp: number = AUTO_SET_TIMESTAMP,
): void {
if (global.nativeQPLMarkerStart) {
opts = fixOpts(opts);
global.nativeQPLMarkerStart(markerId, opts.instanceKey, opts.timestamp);
global.nativeQPLMarkerStart(markerId, instanceKey, timestamp);
}
},
markerEnd(markerId, actionId, opts) {
if (typeof markerId !== 'number' || typeof actionId !== 'number') {
return;
}
markerEnd(
markerId: number,
actionId: number,
instanceKey: number = DUMMY_INSTANCE_KEY,
timestamp: number = AUTO_SET_TIMESTAMP,
): void {
if (global.nativeQPLMarkerEnd) {
opts = fixOpts(opts);
global.nativeQPLMarkerEnd(markerId, opts.instanceKey, actionId, opts.timestamp);
global.nativeQPLMarkerEnd(markerId, instanceKey, actionId, timestamp);
}
},
markerNote(markerId, actionId, opts) {
if (typeof markerId !== 'number' || typeof actionId !== 'number') {
return;
}
markerNote(
markerId: number,
actionId: number,
instanceKey: number = DUMMY_INSTANCE_KEY,
timestamp: number = AUTO_SET_TIMESTAMP,
): void {
if (global.nativeQPLMarkerNote) {
opts = fixOpts(opts);
global.nativeQPLMarkerNote(markerId, opts.instanceKey, actionId, opts.timestamp);
global.nativeQPLMarkerNote(markerId, instanceKey, actionId, timestamp);
}
},
markerTag(markerId, tag, opts) {
if (typeof markerId !== 'number' || typeof tag !== 'string') {
return;
}
markerTag(
markerId: number,
tag: string,
instanceKey: number = DUMMY_INSTANCE_KEY,
): void {
if (global.nativeQPLMarkerTag) {
opts = fixOpts(opts);
global.nativeQPLMarkerTag(markerId, opts.instanceKey, tag);
global.nativeQPLMarkerTag(markerId, instanceKey, tag);
}
},
markerAnnotate(markerId, annotationKey, annotationValue, opts) {
if (typeof markerId !== 'number' ||
typeof annotationKey !== 'string' ||
typeof annotationValue !== 'string') {
return;
}
markerAnnotate(
markerId: number,
annotationKey: string,
annotationValue: string,
instanceKey: number = DUMMY_INSTANCE_KEY,
): void {
if (global.nativeQPLMarkerAnnotate) {
opts = fixOpts(opts);
global.nativeQPLMarkerAnnotate(markerId, opts.instanceKey, annotationKey, annotationValue);
global.nativeQPLMarkerAnnotate(
markerId,
instanceKey,
annotationKey,
annotationValue,
);
}
},
markerCancel(markerId, opts) {
if (typeof markerId !== 'number') {
return;
}
markerCancel(
markerId: number,
instanceKey?: number = DUMMY_INSTANCE_KEY,
): void {
if (global.nativeQPLMarkerCancel) {
opts = fixOpts(opts);
global.nativeQPLMarkerCancel(markerId, opts.instanceKey);
global.nativeQPLMarkerCancel(markerId, instanceKey);
}
},
currentTimestamp() {
currentTimestamp(): number {
if (global.nativeQPLTimestamp) {
return global.nativeQPLTimestamp();
}