import {closeLoadingServiceHook, iLoadingServiceOption} from "./loading.service.utils"; import {createApplicationService} from "../Application/service/createApplicationService"; import {createApplicationServiceManager} from "../Application/service/createApplicationServiceManager"; import {LoadingService} from "./LoadingService"; import {createCounter} from "@peryl/utils/createCounter"; interface iLoadingServiceFunction { (option?: iLoadingServiceOption): () => void; } const nextLoadingId = createCounter('loading'); export const useLoading = createApplicationService( 'loading', createApplicationServiceManager({ name: 'loading', Service: LoadingService }), (getManager) => { const service: iLoadingServiceFunction = (_option) => { const option: iLoadingServiceOption = _option || {}; !option.id && (option.id = nextLoadingId()); getManager().then(async manager => {await manager.service(option);}); return () => closeLoadingServiceHook.exec(option!.id!); }; return { $loading: service }; }, ); export default useLoading;