From: Evan You Date: Mon, 19 Aug 2019 18:45:11 +0000 (-0400) Subject: wip: adjust inject API X-Git-Tag: v3.0.0-alpha.0~918 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=685348f818c7032bacd01c8827d298354cba21f7;p=thirdparty%2Fvuejs%2Fcore.git wip: adjust inject API --- diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 602fc1c0cf..93d5e39a1d 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -1,9 +1,8 @@ -import { ref, isRef, Ref } from './apiState' import { currentInstance } from './component' export interface InjectionKey extends Symbol {} -export function provide(key: InjectionKey | string, value: T | Ref) { +export function provide(key: InjectionKey | string, value: T) { if (!currentInstance) { // TODO warn } else { @@ -22,19 +21,16 @@ export function provide(key: InjectionKey | string, value: T | Ref) { } } -export function inject(key: InjectionKey | string): Ref | undefined -export function inject( - key: InjectionKey | string, - defaultValue: T -): Ref +export function inject(key: InjectionKey | string): T | undefined +export function inject(key: InjectionKey | string, defaultValue: T): T export function inject(key: InjectionKey | string, defaultValue?: any) { if (!currentInstance) { // TODO warn } else { // TODO should also check for app-level provides const provides = currentInstance.parent && currentInstance.provides - const val = - provides && key in provides ? (provides[key as any] as any) : defaultValue - return isRef(val) ? val : ref(val) + return provides && key in provides + ? (provides[key as any] as any) + : defaultValue } }