import { getCurrentInstance } from '../runtime/instance' ; import { warn } from '../warn' ; /**
 * Value to track if parameter is unset
 */ const UNSET = Object . create ( null ) ; /**
 * Helps type inference when providing/injecting a key
 */ export interface InjectionKey < T > extends Symbol { } param key param value export function provide < T > ( key , value ) { const instance = getCurrentInstance ( ) ; if ( instance ) { instance . provide ( key , value ) ; } else { warn ( `provide() requires to have a setup function in its call stack.` , `provide(${ key })` ) ; } } param key param defaultValue returns export function inject < T > ( key , defaultValue ? ) ; export function inject < T > ( key , defaultValue = UNSET ) { const instance = getCurrentInstance ( ) ; if ( instance ) { const { provides } = instance ; const prop = key as string ; if ( prop in provides ) { return provides [ prop ] as T ; } else if ( defaultValue !== UNSET ) { return defaultValue ; } warn ( `Provider "${ key . toString ( ) }" not found, cannot inject.` , `inject(${ key . toString ( ) })` ) ; } else { warn ( `inject() requires to have a setup function in its call stack.` , `inject(${ key . toString ( ) })` ) ; } }