Created
July 25, 2019 04:27
-
-
Save stwilz/8bcba580cc5b927d7993cddb5dfb4cb1 to your computer and use it in GitHub Desktop.
A curry utility for passing additional arguments to `mapGetters`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) | |
}), | |
{} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 proplistsType
to the media-table component, then thecurryMapGetters
function runs beforethis
is defined, and I receive an error:Cannot read properties of undefined (reading 'listsType').
I'm a little stumped.