2019-02-14 06:30:12 +11:00
|
|
|
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),
|
2019-02-14 12:59:26 +11:00
|
|
|
props: {
|
|
|
|
...this.$props.entryProps,
|
|
|
|
...getEntryProps(entry, index)
|
|
|
|
},
|
|
|
|
on: this.$props.entryListeners
|
2019-02-14 06:30:12 +11:00
|
|
|
}
|
2019-02-14 12:59:26 +11:00
|
|
|
return <Component {...props} />
|
2019-02-14 06:30:12 +11:00
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
},
|
2019-02-14 12:59:26 +11:00
|
|
|
props: ['entries', 'entryProps', 'entryListeners']
|
2019-02-14 06:30:12 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withList
|