]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: warn when injection not found
authorEvan You <yyx990803@gmail.com>
Tue, 20 Aug 2019 19:51:55 +0000 (15:51 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 20 Aug 2019 19:51:55 +0000 (15:51 -0400)
packages/runtime-core/src/apiInject.ts

index 93d5e39a1d94718192aedc760eb07c02c688098d..b9e105fe6a7c40c1dcf4d30426e4c959ee551246 100644 (file)
@@ -1,4 +1,5 @@
 import { currentInstance } from './component'
+import { warn } from './warning'
 
 export interface InjectionKey<T> extends Symbol {}
 
@@ -29,8 +30,12 @@ export function inject(key: InjectionKey<any> | string, defaultValue?: any) {
   } else {
     // TODO should also check for app-level provides
     const provides = currentInstance.parent && currentInstance.provides
-    return provides && key in provides
-      ? (provides[key as any] as any)
-      : defaultValue
+    if (provides && key in provides) {
+      return provides[key as any] as any
+    } else if (defaultValue !== undefined) {
+      return defaultValue
+    } else if (__DEV__) {
+      warn(`injection ${key} not found.`)
+    }
   }
 }