-
-
Save bekliev/5fbd348054d2f57bc0b0af0720b9cfff to your computer and use it in GitHub Desktop.
A curry utility for passing additional arguments to `mapGetters`.
This file contains 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) => { | |
const getters = mapGetters(namespace, getters); | |
const entries = Object.entries(getters); | |
const initialAccumulator = {}; | |
return entries.reduce((acc, [getterName, getterHandler]) => { | |
acc[getterName] = (state) => { | |
return getterHandler.call(state)(...args); | |
}; | |
return acc; | |
}, initialAccumulator); | |
}; | |
const curryMapActions = (...args) => (namespace, actions) => { | |
// Currently in development | |
}; |
This file contains 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
<template> | |
<section class="media-list"> | |
<media-table | |
:rows="list.list" | |
:sord="list.order.sord" | |
:sidx="list.order.sidx" | |
:page="list.pagination.page" | |
:perPage="list.pagination.perPage" | |
:total="list.total" | |
@sort-change="listSortChange" | |
@page-change="listPaginationChange" | |
@size-change="listPaginationChange" | |
/> | |
</section> | |
</template> | |
<script> | |
const LISTS_TYPE = { | |
MEDIA: 'media', | |
CONTENT: 'content', | |
}; | |
export default { | |
name: 'example', | |
computed: { | |
...curryMapGetters(LISTS_TYPE.MEDIA)('Lists', [ | |
'list', | |
]), | |
}, | |
created() { | |
// NOTE: currently in development | |
this.listInitialize(); // auto-magically passes LISTS_TYPE.MEDIA as first argument | |
}, | |
methods: { | |
// NOTE: currently in development | |
...curryMapActions(LISTS_TYPE.MEDIA)('Lists', [ | |
'listInitialize', | |
'listSearch', | |
'listSortChange', | |
'listPaginationChange', | |
]), | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment