| | |
| | | export function createContext<T>( |
| | | context: any, |
| | | key: InjectionKey<T> = Symbol(), |
| | | options: CreateContextOptions = {} |
| | | options: CreateContextOptions = {}, |
| | | ) { |
| | | const { readonly = true, createProvider = false, native = false } = options; |
| | | |
| | |
| | | const provideData = readonly ? defineReadonly(state) : state; |
| | | !createProvider && provide(key, native ? context : provideData); |
| | | |
| | | // const Provider = createProvider |
| | | // ? defineComponent({ |
| | | // name: 'Provider', |
| | | // inheritAttrs: false, |
| | | // setup(_, { slots }) { |
| | | // provide(key, provideData); |
| | | // return () => slots.default?.(); |
| | | // }, |
| | | // }) |
| | | // : null; |
| | | |
| | | return { |
| | | // Provider, |
| | | state, |
| | | }; |
| | | } |
| | |
| | | |
| | | export function useContext<T>( |
| | | key: InjectionKey<T> = Symbol(), |
| | | defaultValue?: any |
| | | defaultValue?: any, |
| | | ): ShallowUnwrap<T> { |
| | | return inject(key, defaultValue || {}); |
| | | } |