Skip to content

Instantly share code, notes, and snippets.

@stwilz
Created July 25, 2019 04:27
Show Gist options
  • Save stwilz/8bcba580cc5b927d7993cddb5dfb4cb1 to your computer and use it in GitHub Desktop.
Save stwilz/8bcba580cc5b927d7993cddb5dfb4cb1 to your computer and use it in GitHub Desktop.
A curry utility for passing additional arguments to `mapGetters`.
import { mapGetters } from "vuex";
const curryMapGetters = args => (namespace, getters) =>
Object.entries(mapGetters(namespace, getters)).reduce(
(acc, [getter, fn]) => ({
...acc,
[getter]: state =>
fn.call(state)(...(Array.isArray(args) ? args : [args]))
}),
{}
);
@michaelegregious
Copy link

michaelegregious commented Nov 27, 2024

Did you make this work properly? I borrowed your idea with slight modifications, however, the problem is I need to access the store in the child component as well, and if I pass the LISTS_TYPE as a prop listsType to the media-table component, then the curryMapGetters function runs before this is defined, and I receive an error: Cannot read properties of undefined (reading 'listsType').

I'm a little stumped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment