mirror of
				https://github.com/ecomfe/vue-echarts.git
				synced 2025-10-31 08:57:20 +08:00 
			
		
		
		
	feat: provide better types for injection keys
This commit is contained in:
		| @ -14,7 +14,8 @@ import { | |||||||
|   nextTick, |   nextTick, | ||||||
|   PropType, |   PropType, | ||||||
|   watchEffect, |   watchEffect, | ||||||
|   Vue2 |   Vue2, | ||||||
|  |   InjectionKey | ||||||
| } from "vue-demi"; | } from "vue-demi"; | ||||||
| import { init as initChart } from "echarts/core"; | import { init as initChart } from "echarts/core"; | ||||||
| import { | import { | ||||||
| @ -44,9 +45,9 @@ if (Vue2) { | |||||||
|   Vue2.config.ignoredElements.push(TAG_NAME); |   Vue2.config.ignoredElements.push(TAG_NAME); | ||||||
| } | } | ||||||
|  |  | ||||||
| export const THEME_KEY = "ecTheme"; | export const THEME_KEY = "ecTheme" as unknown as InjectionKey<ThemeInjection>; | ||||||
| export const INIT_OPTIONS_KEY = "ecInitOptions"; | export const INIT_OPTIONS_KEY = "ecInitOptions" as unknown as InjectionKey<InitOptionsInjection>; | ||||||
| export const UPDATE_OPTIONS_KEY = "ecUpdateOptions"; | export const UPDATE_OPTIONS_KEY = "ecUpdateOptions" as unknown as InjectionKey<UpdateOptionsInjection>; | ||||||
| export { LOADING_OPTIONS_KEY } from "./composables"; | export { LOADING_OPTIONS_KEY } from "./composables"; | ||||||
|  |  | ||||||
| export default defineComponent({ | export default defineComponent({ | ||||||
| @ -69,15 +70,15 @@ export default defineComponent({ | |||||||
|     const root = shallowRef<HTMLElement>(); |     const root = shallowRef<HTMLElement>(); | ||||||
|     const chart = shallowRef<EChartsType>(); |     const chart = shallowRef<EChartsType>(); | ||||||
|     const manualOption = shallowRef<Option>(); |     const manualOption = shallowRef<Option>(); | ||||||
|     const defaultTheme = inject(THEME_KEY, null) as ThemeInjection; |     const defaultTheme = inject(THEME_KEY, null); | ||||||
|     const defaultInitOptions = inject( |     const defaultInitOptions = inject( | ||||||
|       INIT_OPTIONS_KEY, |       INIT_OPTIONS_KEY, | ||||||
|       null |       null | ||||||
|     ) as InitOptionsInjection; |     ); | ||||||
|     const defaultUpdateOptions = inject( |     const defaultUpdateOptions = inject( | ||||||
|       UPDATE_OPTIONS_KEY, |       UPDATE_OPTIONS_KEY, | ||||||
|       null |       null | ||||||
|     ) as UpdateOptionsInjection; |     ); | ||||||
|  |  | ||||||
|     const { autoresize, manualUpdate, loading, loadingOptions } = toRefs(props); |     const { autoresize, manualUpdate, loading, loadingOptions } = toRefs(props); | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| import { inject, unref, computed, Ref, watchEffect } from "vue-demi"; | import { inject, unref, computed, Ref, watchEffect, InjectionKey } from "vue-demi"; | ||||||
| import { EChartsType } from "../types"; | import { EChartsType } from "../types"; | ||||||
|  |  | ||||||
| export const LOADING_OPTIONS_KEY = "ecLoadingOptions"; | export const LOADING_OPTIONS_KEY = "ecLoadingOptions" as unknown as InjectionKey<UnknownRecord | Ref<UnknownRecord>>; | ||||||
|  |  | ||||||
| type UnknownRecord = Record<string, unknown>; | type UnknownRecord = Record<string, unknown>; | ||||||
|  |  | ||||||
| @ -10,9 +10,7 @@ export function useLoading( | |||||||
|   loading: Ref<boolean>, |   loading: Ref<boolean>, | ||||||
|   loadingOptions: Ref<UnknownRecord | undefined> |   loadingOptions: Ref<UnknownRecord | undefined> | ||||||
| ): void { | ): void { | ||||||
|   const defaultLoadingOptions = inject(LOADING_OPTIONS_KEY, {}) as |   const defaultLoadingOptions = inject(LOADING_OPTIONS_KEY, {}) | ||||||
|     | UnknownRecord |  | ||||||
|     | Ref<UnknownRecord>; |  | ||||||
|   const realLoadingOptions = computed(() => ({ |   const realLoadingOptions = computed(() => ({ | ||||||
|     ...unref(defaultLoadingOptions), |     ...unref(defaultLoadingOptions), | ||||||
|     ...loadingOptions?.value |     ...loadingOptions?.value | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 meteorlxy
					meteorlxy