]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: make injected values immutable
authorEvan You <yyx990803@gmail.com>
Mon, 19 Aug 2019 19:06:03 +0000 (15:06 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 19 Aug 2019 19:06:03 +0000 (15:06 -0400)
packages/runtime-core/src/apiInject.ts

index 93d5e39a1d94718192aedc760eb07c02c688098d..c7f8f327e470c0e9896a34bade57c7f11d7834cc 100644 (file)
@@ -1,4 +1,6 @@
 import { currentInstance } from './component'
+import { immutable } from './apiState'
+import { isObject } from '@vue/shared'
 
 export interface InjectionKey<T> extends Symbol {}
 
@@ -29,8 +31,8 @@ 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
+    const val =
+      provides && key in provides ? (provides[key as any] as any) : defaultValue
+    return __DEV__ && isObject(val) ? immutable(val) : val
   }
 }