Skip to content

Commit 730da96

Browse files
Adjusted the inject function code to be flat like the provide function (#481)
* Adjusted the inject function code to be flat like the provide function * Update src/apis/inject.ts Co-authored-by: Jacek Karczmarczyk <jkarczm@gmail.com> Co-authored-by: Jacek Karczmarczyk <jkarczm@gmail.com>
1 parent 527ceb1 commit 730da96

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/apis/inject.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ export function inject(
4848
}
4949

5050
const vm = getCurrentInstance()
51-
if (vm) {
52-
const val = resolveInject(key, vm)
53-
if (val !== NOT_FOUND) {
54-
return val
55-
} else {
56-
if (defaultValue === undefined && __DEV__) {
57-
warn(`Injection "${String(key)}" not found`, vm)
58-
}
59-
return defaultValue
60-
}
61-
} else {
51+
if (!vm) {
6252
warn(`inject() can only be used inside setup() or functional components.`)
53+
return
54+
}
55+
56+
const val = resolveInject(key, vm)
57+
if (val !== NOT_FOUND) {
58+
return val;
6359
}
60+
61+
if (defaultValue === undefined && __DEV__) {
62+
warn(`Injection "${String(key)}" not found`, vm)
63+
}
64+
65+
return defaultValue
6466
}

0 commit comments

Comments
 (0)