@shopify/performance
Advanced tools
Comparing version 0.0.0-snapshot-20231222183433 to 0.0.0-snapshot-20240103194658
@@ -13,3 +13,3 @@ 'use strict'; | ||
class Performance { | ||
constructor(resolveRouter) { | ||
constructor(withCustomNavigation) { | ||
this.supportsObserver = utilities.hasGlobal('PerformanceObserver'); | ||
@@ -32,3 +32,3 @@ this.supportsMarks = utilities.hasGlobal('PerformanceMark'); | ||
}; | ||
this.resolveRouter = resolveRouter; | ||
this.withCustomNavigation = withCustomNavigation; | ||
this.start({ | ||
@@ -38,4 +38,4 @@ timeStamp: 0 | ||
if (this.resolveRouter) { | ||
utilities.withReactRouterNavigation(this.resolveRouter, this.start.bind(this)); | ||
if (this.withCustomNavigation) { | ||
this.withCustomNavigation(this); | ||
} else { | ||
@@ -42,0 +42,0 @@ utilities.withNavigation(this.start.bind(this)); |
@@ -89,14 +89,2 @@ 'use strict'; | ||
} | ||
async function withReactRouterNavigation(resolveRouter, handler) { | ||
const router = await resolveRouter; | ||
let currentPathname = window.location.pathname; | ||
return router.subscribe(state => { | ||
if (state.navigation.state === 'loading' && currentPathname !== state.navigation.location.pathname) { | ||
currentPathname = state.navigation.location.pathname; | ||
handler({ | ||
target: currentPathname | ||
}); | ||
} | ||
}); | ||
} | ||
function withTiming(handler) { | ||
@@ -193,3 +181,2 @@ if (typeof document === 'undefined' || typeof performance === 'undefined') { | ||
exports.withNavigation = withNavigation; | ||
exports.withReactRouterNavigation = withReactRouterNavigation; | ||
exports.withTiming = withTiming; |
@@ -9,3 +9,3 @@ import type { Navigation } from './navigation'; | ||
export declare class Performance { | ||
private resolveRouter?; | ||
private withCustomNavigation?; | ||
readonly supportsObserver: boolean; | ||
@@ -27,3 +27,3 @@ readonly supportsMarks: boolean; | ||
private eventHandlers; | ||
constructor(resolveRouter?: Promise<import("@remix-run/router").Router> | undefined); | ||
constructor(withCustomNavigation?: ((perf: Performance) => void) | undefined); | ||
mark(stage: string, id: string): void; | ||
@@ -30,0 +30,0 @@ on<T extends keyof EventMap>(event: T, handler: EventMap[T]): () => boolean; |
@@ -1,2 +0,1 @@ | ||
import type { createBrowserRouter } from 'react-router-dom'; | ||
import { EventType } from './types'; | ||
@@ -17,6 +16,2 @@ export declare function referenceTime(): number; | ||
}) => void): void; | ||
export declare function withReactRouterNavigation(resolveRouter: Promise<ReturnType<typeof createBrowserRouter>>, handler: (details?: { | ||
target?: string; | ||
timeStamp?: number; | ||
}) => void): Promise<() => void>; | ||
export declare function withTiming(handler: (timing: typeof performance.timing) => void): void; | ||
@@ -23,0 +18,0 @@ export declare const supportsPerformanceObserver: boolean; |
{ | ||
"name": "@shopify/performance", | ||
"version": "0.0.0-snapshot-20231222183433", | ||
"version": "0.0.0-snapshot-20240103194658", | ||
"license": "MIT", | ||
@@ -46,11 +46,3 @@ "description": "Primitives for collecting browser performance metrics", | ||
"web-vitals": "^3.0.4" | ||
}, | ||
"peerDependencies": { | ||
"react-router-dom": "^6.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"react-router-dom": { | ||
"optional": true | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
90293
1508