📄 injectLocal¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 6 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/shared/injectLocal/index.ts
📦 Imports¶
| Name | Source |
|---|---|
InjectionKey |
vue |
getCurrentInstance |
vue |
getCurrentScope |
vue |
hasInjectionContext |
vue |
inject |
vue |
localProvidedStateMap |
../provideLocal/map |
Functions¶
injectLocal(args: any[]): any¶
Parameters:
argsany[]
Returns: any
Calls:
getCurrentInstance (from vue)getCurrentScope (from vue)hasInjectionContext (from vue)localProvidedStateMap.haslocalProvidedStateMap.getinject (from vue)
Internal Comments:
Code
<T>(...args) => {
const key = args[0] as InjectionKey<T> | string | number
const instance = getCurrentInstance()?.proxy
const owner = instance ?? getCurrentScope()
if (owner == null && !hasInjectionContext())
throw new Error('injectLocal must be called in setup')
if (owner && localProvidedStateMap.has(owner) && key in localProvidedStateMap.get(owner)!)
return localProvidedStateMap.get(owner)![key]
// @ts-expect-error overloads are not compatible
return inject(...args)
}
Generated by Syntax Scribe