Skip to content

⬅️ Back to Table of Contents

πŸ“„ usePerformanceObserver

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 3
πŸ“¦ Imports 4
πŸ“‘ 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

Functions

usePerformanceObserver(options: UsePerformanceObserverOptions, callback: PerformanceObserverCallback): { isSupported: ComputedRef<boolean>; start: () => void; sto…

Observe performance metrics.

Parameters:

  • options any: No description

See: https://vueuse.org/usePerformanceObserver

Raw JSDoc
/**
 * Observe performance metrics.
 *
 * @see https://vueuse.org/usePerformanceObserver
 * @param options
 */

Calls:

  • useSupported (from ../useSupported)
  • observer?.disconnect
  • stop
  • observer.observe
  • tryOnScopeDispose (from @vueuse/shared)
  • start
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,
  }
}

Internal helpers

Declared inside another function in this file.

stop(): void

Returns: void

Calls:

  • observer?.disconnect
Code
() => {
    observer?.disconnect()
  }

start(): void

Returns: void

Calls:

  • stop
  • observer.observe
Code
() => {
    if (isSupported.value) {
      stop()
      observer = new PerformanceObserver(callback)
      observer.observe(performanceOptions)
    }
  }

Type Aliases

UsePerformanceObserverOptions

type UsePerformanceObserverOptions = PerformanceObserverInit & ConfigurableWindow & {
  /**
   * Start the observer immediate.
   *
   * @default true
   */
  immediate?: boolean
};

Generated by Syntax Scribe