]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: adjust inject API
authorEvan You <yyx990803@gmail.com>
Mon, 19 Aug 2019 18:45:11 +0000 (14:45 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 19 Aug 2019 18:45:11 +0000 (14:45 -0400)
packages/runtime-core/src/apiInject.ts

index 602fc1c0cfe9955dc66cbb0065db97503b7c7c5e..93d5e39a1d94718192aedc760eb07c02c688098d 100644 (file)
@@ -1,9 +1,8 @@
-import { ref, isRef, Ref } from './apiState'
 import { currentInstance } from './component'
 
 export interface InjectionKey<T> extends Symbol {}
 
-export function provide<T>(key: InjectionKey<T> | string, value: T | Ref<T>) {
+export function provide<T>(key: InjectionKey<T> | string, value: T) {
   if (!currentInstance) {
     // TODO warn
   } else {
@@ -22,19 +21,16 @@ export function provide<T>(key: InjectionKey<T> | string, value: T | Ref<T>) {
   }
 }
 
-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<T>(key: InjectionKey<T> | string): T | undefined
+export function inject<T>(key: InjectionKey<T> | string, defaultValue: T): 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
-    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
   }
 }