📄 reactify¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 7 |
| 📊 Variables & Constants | 1 |
| 🟢 Vue Composition API | 1 |
| 📐 Interfaces | 1 |
| 📑 Type Aliases | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/shared/reactify/index.ts
📦 Imports¶
| Name | Source |
|---|---|
ComputedRef |
vue |
MaybeRef |
vue |
MaybeRefOrGetter |
vue |
AnyFn |
../utils |
computed |
vue |
toValue |
vue |
unref |
vue |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
createReactiveFn |
<T extends AnyFn, K extends boolean =... |
const | reactify |
✓ |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
computed |
computed | none | none |
Functions¶
reactify(fn: T, options: ReactifyOptions<K>): ReactifyReturn<T, K>¶
Converts plain function into a reactive function. The converted function accepts refs as it's arguments and returns a ComputedRef, with proper typing.
Parameters:
fnany: Source functionoptionsany: Options
Tags: @__NO_SIDE_EFFECTS__
Raw JSDoc
Calls:
computed (from vue)fn.applyargs.mapunrefFn
Code
export function reactify<T extends AnyFn, K extends boolean = true>(fn: T, options?: ReactifyOptions<K>): ReactifyReturn<T, K> {
const unrefFn = options?.computedGetter === false ? unref : toValue
return function (this: any, ...args: any[]) {
return computed(() => fn.apply(this, args.map(i => unrefFn(i))))
} as ReactifyReturn<T, K>
}
Interfaces¶
ReactifyOptions<T extends boolean>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
computedGetter |
T |
✓ | not shown |
Type Aliases¶
Reactified<T, Computed extends boolean>¶
type Reactified<T, Computed extends boolean> = T extends (...args: infer A) => infer R
? (...args: { [K in keyof A]: Computed extends true ? MaybeRefOrGetter<A[K]> : MaybeRef<A[K]> }) => ComputedRef<R>
: never;
ReactifyReturn<T extends AnyFn = AnyFn, K extends boolean = true>¶
Generated by Syntax Scribe