From 2f224db873d72d485d945c8bf2040626007dfc8f Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Thu, 8 Feb 2024 08:28:16 +0100 Subject: [PATCH] feat: new approach for useStore composable EMP-3458 --- .../x-components/src/composables/use-store.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/x-components/src/composables/use-store.ts b/packages/x-components/src/composables/use-store.ts index 5b3da3b5ed..a3e9e185bf 100644 --- a/packages/x-components/src/composables/use-store.ts +++ b/packages/x-components/src/composables/use-store.ts @@ -7,34 +7,34 @@ import { ExtractState, XModuleName } from '../x-modules/x-modules.types'; * Function which returns the `$store` object from the current component instance * and the selected state as a dictionary of paths. * - * @param module - The {@link XModuleName} of the getter. * @returns The state properties of the module and the `$store`. * * @public */ -export function useStore>( - module?: Module -): UseStore { +export function useStore(): UseStore { const store = (getCurrentInstance()?.proxy as { $store: Store }).$store; - const useState = (module: Module, paths: Path[]): ComputedRef> => { - return paths.reduce>>((state, path) => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - state[path] = computed(() => store.state.x[module][path]); + const useState = >( + module: Module, + paths: Paths[] + ): Dictionary => { + return paths.reduce>((state, path) => { + state[path as string] = computed(() => store.state.x[module][path]); return state; - }, {} as ComputedRef>); + }, {}); }; - const useStateWithModule = useState.bind(module); return { store, - useState: module ? useStateWithModule : useState + useState }; } /** * Return type of the {@link useStore} composable. */ -type UseStore> = { +type UseStore = { store: Store; - useState: (module: Module, paths: Path[]) => ComputedRef>; + useState: >( + module: Module, + paths: Paths[] + ) => Dictionary; };