/** * Mapping helpers for store state and actions. */ /** * Maps store state properties to a reactive object for use in components. * * @param store - The store instance * @param keys - State keys to map * @returns Object with mapped properties */ export const mapState = , K extends keyof S>( store: S, keys: K[] ): Pick => { const mapped = {} as Pick; for (const key of keys) { Object.defineProperty(mapped, key, { get: () => store[key], enumerable: true, }); } return mapped; }; /** * Maps store getters to a reactive object for use in components. * * @param store - The store instance * @param keys - Getter keys to map * @returns Object with mapped getters */ export const mapGetters = , K extends keyof G>( store: G, keys: K[] ): Pick => { const mapped = {} as Pick; for (const key of keys) { Object.defineProperty(mapped, key, { get: () => store[key], enumerable: true, }); } return mapped; }; /** * Maps store actions to an object for easier destructuring. * * @param store - The store instance * @param keys - Action keys to map * @returns Object with mapped actions */ export const mapActions = < // eslint-disable-next-line @typescript-eslint/no-explicit-any -- actions may declare specific parameter types A extends Record any>, K extends keyof A, >( store: A, keys: K[] ): Pick => { const mapped = {} as Pick; for (const key of keys) { (mapped as Record)[key as string] = (...args: unknown[]) => (store[key] as (...args: unknown[]) => unknown)(...args); } return mapped; };