📄 index.ts
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 1 |
📦 Imports | 4 |
📊 Variables & Constants | 2 |
📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/shared/provideLocal/index.ts
📦 Imports¶
Name | Source |
---|---|
InjectionKey |
vue |
getCurrentInstance |
vue |
provide |
vue |
localProvidedStateMap |
./map |
Variables & Constants¶
Name | Type | Kind | Value | Exported |
---|---|---|---|---|
instance |
any |
const | getCurrentInstance()?.proxy |
✗ |
localProvidedState |
Record<string | symbol, any> |
const | localProvidedStateMap.get(instance)! |
✗ |
Functions¶
provideLocal(key: K, value: K extends InjectionKey<infer V> ? V : T): ProvideLocalReturn
¶
Code
export function provideLocal<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): ProvideLocalReturn {
const instance = getCurrentInstance()?.proxy
if (instance == null)
throw new Error('provideLocal must be called in setup')
if (!localProvidedStateMap.has(instance))
localProvidedStateMap.set(instance, Object.create(null))
const localProvidedState = localProvidedStateMap.get(instance)!
// @ts-expect-error allow InjectionKey as key
localProvidedState[key] = value
return provide<T, K>(key, value)
}
-
JSDoc:
-
Parameters:
key: K
value: K extends InjectionKey<infer V> ? V : T
- Return Type:
ProvideLocalReturn
- Calls:
getCurrentInstance (from vue)
localProvidedStateMap.has
localProvidedStateMap.set
Object.create
localProvidedStateMap.get
provide (from vue)
- Internal Comments: