mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-28 15:44:46 +08:00
[perf] Return Promise types
This commit is contained in:
@@ -16,7 +16,7 @@ export default class HttpMetric {
|
||||
this.httpMethod = httpMethod;
|
||||
}
|
||||
|
||||
getAttribute(attribute: string): Promise<string> {
|
||||
getAttribute(attribute: string): Promise<string | null> {
|
||||
return getNativeModule(this._perf).getHttpMetricAttribute(
|
||||
this.url,
|
||||
this.httpMethod,
|
||||
@@ -31,7 +31,8 @@ export default class HttpMetric {
|
||||
);
|
||||
}
|
||||
|
||||
putAttribute(attribute: string, value: string): Promise<null> {
|
||||
// TODO return true or false
|
||||
putAttribute(attribute: string, value: string): Promise<true | false> {
|
||||
return getNativeModule(this._perf).putHttpMetricAttribute(
|
||||
this.url,
|
||||
this.httpMethod,
|
||||
|
||||
@@ -14,7 +14,7 @@ export default class Trace {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
getAttribute(attribute: string): Promise<string> {
|
||||
getAttribute(attribute: string): Promise<string | null> {
|
||||
return getNativeModule(this._perf).getTraceAttribute(
|
||||
this.identifier,
|
||||
attribute
|
||||
@@ -40,7 +40,8 @@ export default class Trace {
|
||||
);
|
||||
}
|
||||
|
||||
putAttribute(attribute: string, value: string): Promise<null> {
|
||||
// TODO return true or false
|
||||
putAttribute(attribute: string, value: string): Promise<true | false> {
|
||||
return getNativeModule(this._perf).putTraceAttribute(
|
||||
this.identifier,
|
||||
attribute,
|
||||
|
||||
@@ -12,6 +12,29 @@ import type App from '../core/app';
|
||||
export const MODULE_NAME = 'RNFirebasePerformance';
|
||||
export const NAMESPACE = 'perf';
|
||||
|
||||
const HTTP_METHODS = {
|
||||
CONNECT: true,
|
||||
DELETE: true,
|
||||
GET: true,
|
||||
HEAD: true,
|
||||
OPTIONS: true,
|
||||
PATCH: true,
|
||||
POST: true,
|
||||
PUT: true,
|
||||
TRACE: true,
|
||||
};
|
||||
|
||||
type HttpMethod =
|
||||
| 'CONNECT'
|
||||
| 'DELETE'
|
||||
| 'GET'
|
||||
| 'HEAD'
|
||||
| 'OPTIONS'
|
||||
| 'PATCH'
|
||||
| 'POST'
|
||||
| 'PUT'
|
||||
| 'TRACE';
|
||||
|
||||
export default class PerformanceMonitoring extends ModuleBase {
|
||||
constructor(app: App) {
|
||||
super(app, {
|
||||
@@ -49,13 +72,27 @@ export default class PerformanceMonitoring extends ModuleBase {
|
||||
return new Trace(this, trace);
|
||||
}
|
||||
|
||||
newHttpMetric(url: string, httpMethod: string) {
|
||||
/**
|
||||
* Return a new HttpMetric instance
|
||||
* @param url
|
||||
* @param httpMethod
|
||||
* @returns {HttpMetric}
|
||||
*/
|
||||
newHttpMetric(url: string, httpMethod: HttpMethod): HttpMetric {
|
||||
if (typeof url !== 'string' || typeof httpMethod !== 'string') {
|
||||
throw new Error(
|
||||
'firebase.perf().newHttpMetric() requires url and httpMethod string values'
|
||||
);
|
||||
}
|
||||
|
||||
if (!HTTP_METHODS[httpMethod]) {
|
||||
throw new Error(
|
||||
`firebase.perf().newHttpMetric() httpMethod should be one of ${Object.keys(
|
||||
HTTP_METHODS
|
||||
).join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return new HttpMetric(this, url, httpMethod);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user