From 685348f818c7032bacd01c8827d298354cba21f7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 19 Aug 2019 14:45:11 -0400 Subject: [PATCH] wip: adjust inject API --- packages/runtime-core/src/apiInject.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 } } -- 2.47.3