diff options
Diffstat (limited to 'src/hocs/with_list/with_list.js')
| -rw-r--r-- | src/hocs/with_list/with_list.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/hocs/with_list/with_list.js b/src/hocs/with_list/with_list.js new file mode 100644 index 00000000..21aa288b --- /dev/null +++ b/src/hocs/with_list/with_list.js @@ -0,0 +1,27 @@ +import Vue from 'vue' +import map from 'lodash/map' + +const defaultEntryPropsGetter = entry => ({ entry }) +const defaultKeyGetter = entry => entry.id + +const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter) => { + return Vue.component('withList', { + render (createElement) { + return ( + <div class="with-list"> + {map(this.entries, (entry, index) => { + const props = { + key: getKey(entry, index), + ...this.$props.entryProps, + ...getEntryProps(entry, index) + } + return <Component {...{ attrs: props }} /> + })} + </div> + ) + }, + props: ['entries', 'entryProps'] + }) +} + +export default withList |
