Skip to content

Commit

Permalink
feat: improve tree-shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 13, 2023
1 parent cb644e0 commit 3275e94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 13 additions & 5 deletions packages/core/ssr-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ const _global
? window
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined' ? self : {}
: typeof self !== 'undefined'
? self
: {}

const globalKey = '__vueuse_ssr_handlers__'
// @ts-expect-error inject global
_global[globalKey] = _global[globalKey] || {}
// @ts-expect-error inject global
const handlers: Partial<SSRHandlersMap> = _global[globalKey]
const handlers = /* @__PURE__ */ getHandlers()

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>
}

export function getSSRHandler<T extends keyof SSRHandlersMap>(key: T, fallback: SSRHandlersMap[T]): SSRHandlersMap[T]
export function getSSRHandler<T extends keyof SSRHandlersMap>(key: T, fallback: SSRHandlersMap[T] | undefined): SSRHandlersMap[T] | undefined
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export const rand = (min: number, max: number) => {
}
export const hasOwn = <T extends object, K extends keyof T>(val: T, key: K): key is K => Object.prototype.hasOwnProperty.call(val, key)

export const isIOS = /* #__PURE__ */ isClient && window?.navigator?.userAgent && /iP(ad|hone|od)/.test(window.navigator.userAgent)
export const isIOS = /* #__PURE__ */ getIsIOS()

function getIsIOS() {
return isClient && window?.navigator?.userAgent && /iP(ad|hone|od)/.test(window.navigator.userAgent)
}

0 comments on commit 3275e94

Please sign in to comment.