-import { value, isValue, Value } from './apiState'
+import { ref, isRef, Ref } from './apiState'
import { currentInstance } from './component'
-export interface Key<T> extends Symbol {}
+export interface InjectionKey<T> extends Symbol {}
-export function provide<T>(key: Key<T> | string, value: T | Value<T>) {
+export function provide<T>(key: InjectionKey<T> | string, value: T | Ref<T>) {
if (!currentInstance) {
// TODO warn
} else {
}
}
-export function inject<T>(key: Key<T> | string): Value<T> | undefined {
+export function inject<T>(key: InjectionKey<T> | string): Ref<T> | undefined
+export function inject<T>(
+ key: InjectionKey<T> | string,
+ defaultValue: T
+): Ref<T>
+export function inject(key: InjectionKey<any> | string, defaultValue?: any) {
if (!currentInstance) {
// TODO warn
} else {
// TODO should also check for app-level provides
const provides = currentInstance.parent && currentInstance.provides
- if (provides) {
- const val = provides[key as any] as any
- return isValue(val) ? val : value(val)
- }
+ const val =
+ provides && key in provides ? (provides[key as any] as any) : defaultValue
+ return isRef(val) ? val : ref(val)
}
}
import {
effect,
stop,
- isValue,
- Value,
+ isRef,
+ Ref,
ReactiveEffectOptions
} from '@vue/reactivity'
import { queueJob, queuePostFlushCb } from './scheduler'
onTrigger?: ReactiveEffectOptions['onTrigger']
}
-type WatcherSource<T> = Value<T> | (() => T)
+type WatcherSource<T> = Ref<T> | (() => T)
const invoke = (fn: Function) => fn()
flush === 'sync' ? invoke : flush === 'pre' ? queueJob : queuePostFlushCb
const baseGetter = isArray(source)
- ? () => source.map(s => (isValue(s) ? s.value : s()))
- : isValue(source)
+ ? () => source.map(s => (isRef(s) ? s.value : s()))
+ : isRef(source)
? () => source.value
: source
const getter = deep ? () => traverse(baseGetter()) : baseGetter
import { VNode, normalizeVNode, VNodeChild } from './vnode'
-import {
- ReactiveEffect,
- UnwrapValue,
- state,
- immutableState
-} from '@vue/reactivity'
+import { ReactiveEffect, UnwrapRef, reactive, immutable } from '@vue/reactivity'
import { EMPTY_OBJ, isFunction, capitalize, invokeHandlers } from '@vue/shared'
import { RenderProxyHandlers } from './componentProxy'
import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
) => RawBindings | (() => VNodeChild)
type RenderFunction<Props = {}, RawBindings = {}> = <
- Bindings extends UnwrapValue<RawBindings>
+ Bindings extends UnwrapRef<RawBindings>
>(
this: ComponentRenderProxy<Props, Bindings>,
ctx: ComponentRenderProxy<Props, Bindings>
export function createComponent<Props, RawBindings>(
options: ComponentOptionsWithoutProps<Props, RawBindings>
): {
- new (): ComponentRenderProxy<Props, UnwrapValue<RawBindings>>
+ new (): ComponentRenderProxy<Props, UnwrapRef<RawBindings>>
}
// overload 3: object format with array props declaration
// props inferred as { [key in PropNames]?: unknown }
): {
new (): ComponentRenderProxy<
{ [key in PropNames]?: unknown },
- UnwrapValue<RawBindings>
+ UnwrapRef<RawBindings>
>
}
// overload 4: object format with object props declaration
// for Vetur and TSX support
new (): ComponentRenderProxy<
ExtractPropTypes<PropsOptions>,
- UnwrapValue<RawBindings>,
+ UnwrapRef<RawBindings>,
ExtractPropTypes<PropsOptions, false>
>
}
// so props change can be tracked by watchers
// it will be updated in resolveProps() on updates before render
const propsProxy = (instance.propsProxy = setup.length
- ? immutableState(instance.props)
+ ? immutable(instance.props)
: null)
const setupContext = (instance.setupContext =
setup.length > 1 ? createSetupContext(instance) : null)
} else {
// setup returned bindings.
// assuming a render function compiled from template is present.
- instance.data = state(setupResult)
+ instance.data = reactive(setupResult)
if (__DEV__ && !Component.render) {
// TODO warn missing render fn
}