|
|
@ -11,7 +11,7 @@ type ShallowUnwrap<T> = { |
|
|
|
[P in keyof T]: UnwrapRef<T[P]> |
|
|
|
[P in keyof T]: UnwrapRef<T[P]> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function createContext<T>(context: any, key: InjectionKey<T> = Symbol(), options: CreateContextOptions = {}) { |
|
|
|
export function createContext<T>(context: any, key: InjectionKey<T> = Symbol('create-context'), options: CreateContextOptions = {}) { |
|
|
|
const { readonly = true, createProvider = true, native = false } = options |
|
|
|
const { readonly = true, createProvider = true, native = false } = options |
|
|
|
|
|
|
|
|
|
|
|
const state = reactive(context) |
|
|
|
const state = reactive(context) |
|
|
@ -25,6 +25,6 @@ export function createContext<T>(context: any, key: InjectionKey<T> = Symbol(), |
|
|
|
|
|
|
|
|
|
|
|
export function useContext<T>(key: InjectionKey<T>, native?: boolean): T |
|
|
|
export function useContext<T>(key: InjectionKey<T>, native?: boolean): T |
|
|
|
|
|
|
|
|
|
|
|
export function useContext<T>(key: InjectionKey<T> = Symbol(), defaultValue?: any): ShallowUnwrap<T> { |
|
|
|
export function useContext<T>(key: InjectionKey<T> = Symbol('use-context'), defaultValue?: any): ShallowUnwrap<T> { |
|
|
|
return inject(key, defaultValue || {}) |
|
|
|
return inject(key, defaultValue || {}) |
|
|
|
} |
|
|
|
} |
|
|
|