📄 index.ts¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 4 |
| 📊 Variables & Constants | 1 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/usePerformanceObserver/index.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigurableWindow |
../_configurable |
tryOnScopeDispose |
@vueuse/shared |
defaultWindow |
../_configurable |
useSupported |
../useSupported |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
observer |
PerformanceObserver | undefined |
let/var | *not shown* |
✗ |
Functions¶
usePerformanceObserver(options: UsePerformanceObserverOptions, callback: PerformanceObserverCallback): { isSupported: any; start: () => void; stop: () => void; }¶
Code
export function usePerformanceObserver(options: UsePerformanceObserverOptions, callback: PerformanceObserverCallback) {
const {
window = defaultWindow,
immediate = true,
...performanceOptions
} = options
const isSupported = useSupported(() => window && 'PerformanceObserver' in window)
let observer: PerformanceObserver | undefined
const stop = () => {
observer?.disconnect()
}
const start = () => {
if (isSupported.value) {
stop()
observer = new PerformanceObserver(callback)
observer.observe(performanceOptions)
}
}
tryOnScopeDispose(stop)
if (immediate)
start()
return {
isSupported,
start,
stop,
}
}
-
JSDoc:
-
Parameters:
options: UsePerformanceObserverOptionscallback: PerformanceObserverCallback- Return Type:
{ isSupported: any; start: () => void; stop: () => void; } - Calls:
useSupported (from ../useSupported)observer?.disconnectstopobserver.observetryOnScopeDispose (from @vueuse/shared)start
stop(): void¶
- Return Type:
void - Calls:
observer?.disconnect
start(): void¶
Code
- Return Type:
void - Calls:
stopobserver.observe
Type Aliases¶
UsePerformanceObserverOptions¶
type UsePerformanceObserverOptions = PerformanceObserverInit & ConfigurableWindow & {
/**
* Start the observer immediate.
*
* @default true
*/
immediate?: boolean
};