Skip to content

⬅️ Back to Table of Contents

📄 ssr-handlers.ts

📊 Analysis Summary

Metric Count
🔧 Functions 3
📦 Imports 2
📊 Variables & Constants 2
📐 Interfaces 3

📚 Table of Contents

🛠️ File Location:

📂 packages/core/ssr-handlers.ts

📦 Imports

Name Source
Awaitable @vueuse/shared
MaybeElementRef ./unrefElement

Variables & Constants

Name Type Kind Value Exported
_global {} const `typeof globalThis !== 'undefined'
? globalThis
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined'
? self
: {}`
globalKey "__vueuse_ssr_handlers__" const '__vueuse_ssr_handlers__'

Functions

getHandlers(): Partial<SSRHandlersMap>

Code
function getHandlers() {
  if (!(globalKey in _global))
    // @ts-expect-error inject global
    _global[globalKey] = _global[globalKey] || {}
  // @ts-expect-error inject global
  return _global[globalKey] as Partial<SSRHandlersMap>
}
  • Return Type: Partial<SSRHandlersMap>
  • Internal Comments:
    // @ts-expect-error inject global (x5)
    

getSSRHandler(key: T, fallback: SSRHandlersMap[T]): SSRHandlersMap[T]

Code
export function getSSRHandler<T extends keyof SSRHandlersMap>(key: T, fallback: SSRHandlersMap[T]): SSRHandlersMap[T]
  • Parameters:
  • key: T
  • fallback: SSRHandlersMap[T]
  • Return Type: SSRHandlersMap[T]

setSSRHandler(key: T, fn: SSRHandlersMap[T]): void

Code
export function setSSRHandler<T extends keyof SSRHandlersMap>(key: T, fn: SSRHandlersMap[T]) {
  handlers[key] = fn
}
  • Parameters:
  • key: T
  • fn: SSRHandlersMap[T]
  • Return Type: void

Interfaces

StorageLikeAsync

Interface Code
export interface StorageLikeAsync {
  getItem: (key: string) => Awaitable<string | null>
  setItem: (key: string, value: string) => Awaitable<void>
  removeItem: (key: string) => Awaitable<void>
}

Properties

Name Type Optional Description
getItem (key: string) => Awaitable<string | null>
setItem (key: string, value: string) => Awaitable<void>
removeItem (key: string) => Awaitable<void>

StorageLike

Interface Code
export interface StorageLike {
  getItem: (key: string) => string | null
  setItem: (key: string, value: string) => void
  removeItem: (key: string) => void
}

Properties

Name Type Optional Description
getItem (key: string) => string | null
setItem (key: string, value: string) => void
removeItem (key: string) => void

SSRHandlersMap

Interface Code
export interface SSRHandlersMap {
  getDefaultStorage: () => StorageLike | undefined
  getDefaultStorageAsync: () => StorageLikeAsync | undefined
  updateHTMLAttrs: (selector: string | MaybeElementRef, attribute: string, value: string) => void
}

Properties

Name Type Optional Description
getDefaultStorage () => StorageLike | undefined
getDefaultStorageAsync () => StorageLikeAsync | undefined
updateHTMLAttrs (selector: string | MaybeElementRef, attribute: string, value: string) => void