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