import { unwrapInjected } from "../utils"; import { inject, computed, watchEffect, type Ref, type InjectionKey } from "vue-demi"; import { EChartsType } from "../types"; export const LOADING_OPTIONS_KEY = "ecLoadingOptions" as unknown as InjectionKey< UnknownRecord | Ref >; type UnknownRecord = Record; export function useLoading( chart: Ref, loading: Ref, loadingOptions: Ref ): void { const defaultLoadingOptions = inject(LOADING_OPTIONS_KEY, {}); const realLoadingOptions = computed(() => ({ ...unwrapInjected(defaultLoadingOptions, {}), ...loadingOptions?.value })); watchEffect(() => { const instance = chart.value; if (!instance) { return; } if (loading.value) { instance.showLoading(realLoadingOptions.value); } else { instance.hideLoading(); } }); } export const loadingProps = { loading: Boolean, loadingOptions: Object };