Skip to content

⬅️ Back to Table of Contents

📄 computedEager

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 5
📊 Variables & Constants 1
📑 Type Aliases 2

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/computedEager/index.ts

📦 Imports

Name Source
ShallowRef vue
WatchOptionsBase vue
deepReadonly vue
shallowRef vue
watchEffect vue

Variables & Constants

Name Type Kind Value Exported
eagerComputed <T>(fn: () => T, options?: WatchOptio... const computedEager

Functions

computedEager(fn: () => T, options: ComputedEagerOptions): ComputedEagerReturn<T>

⚠️ DEPRECATED: This function will be removed in future version.

Note: If you are using Vue 3.4+, you can straight use computed instead. Because in Vue 3.4+, if computed new value does not change, computed, effect, watch, watchEffect, render dependencies will not be triggered. refer: https://github.com/vuejs/core/pull/5912

Parameters:

  • fn any: effect function
  • options any: WatchOptionsBase

Returns: undefined readonly shallowRef

Raw JSDoc
/**
 *
 * @deprecated This function will be removed in future version.
 *
 * Note: If you are using Vue 3.4+, you can straight use computed instead.
 * Because in Vue 3.4+, if computed new value does not change,
 * computed, effect, watch, watchEffect, render dependencies will not be triggered.
 * refer: https://github.com/vuejs/core/pull/5912
 *
 * @param fn effect function
 * @param options WatchOptionsBase
 * @returns readonly shallowRef
 */

Calls:

  • shallowRef (from vue)
  • watchEffect (from vue)
  • fn
  • deepReadonly (from vue)
Code
export function computedEager<T>(fn: () => T, options?: ComputedEagerOptions): ComputedEagerReturn<T> {
  const result = shallowRef()

  watchEffect(() => {
    result.value = fn()
  }, {
    ...options,
    flush: options?.flush ?? 'sync',
  })

  return deepReadonly(result)
}

Type Aliases

ComputedEagerOptions

type ComputedEagerOptions = WatchOptionsBase;

ComputedEagerReturn<T = any>

type ComputedEagerReturn<T = any> = Readonly<ShallowRef<T>>;

Generated by Syntax Scribe